joshua stein 2014-11-14 14:09:28 -06:00
parent 4b0caa2752
commit 31d4e97858
11 changed files with 118 additions and 12 deletions

View file

@ -70,6 +70,27 @@ a.tag_meta {
border-color: #c8c8c8;
}
span.hat {
border-bottom: 6px solid #bbb;
border-radius: 4px;
padding: 1px 8px;
}
span.hat span.crown {
background-color: #ddd;
border: 1px solid #eee;
border-bottom: 0;
border-radius: 5px 5px 0px 0px;
font-size: 7.5pt;
padding: 3px 5px 2px 5px;
text-decoration: none;
vertical-align: text-top;
}
span.hat span.crown, span.hat a {
color: #777;
text-decoration: none;
}
span.fakea {
cursor: pointer;
text-decoration: underline;

View file

@ -17,6 +17,10 @@ class CommentsController < ApplicationController
comment.comment = params[:comment].to_s
comment.user = @user
if params[:hat_id] && @user.hats.where(:id => params[:hat_id])
comment.hat_id = params[:hat_id]
end
if params[:parent_comment_short_id].present?
if pc = Comment.where(:story_id => story.id, :short_id =>
params[:parent_comment_short_id]).first
@ -115,6 +119,10 @@ class CommentsController < ApplicationController
end
comment.comment = params[:comment]
comment.hat_id = nil
if params[:hat_id] && @user.hats.where(:id => params[:hat_id])
comment.hat_id = params[:hat_id]
end
if params[:preview].blank? && comment.save
votes = Vote.comment_votes_by_user_for_comment_ids_hash(@user.id,

View file

@ -127,8 +127,8 @@ class StoriesController < ApplicationController
@short_url = @story.short_id_url
@comments = @story.merged_comments.includes(:user,
:story).arrange_for_user(@user)
@comments = @story.merged_comments.includes(:user, :story,
:hat).arrange_for_user(@user)
if params[:comment_short_id]
@comments.each do |c,x|

View file

@ -8,6 +8,7 @@ class Comment < ActiveRecord::Base
:class_name => "Comment"
has_one :moderation,
:class_name => "Moderation"
belongs_to :hat
attr_accessor :current_vote, :previewing, :indent_level, :highlighted

29
app/models/hat.rb Normal file
View file

@ -0,0 +1,29 @@
class Hat < ActiveRecord::Base
belongs_to :user
belongs_to :granted_by_user,
:class_name => "User"
validates :user, :presence => true
validates :granted_by_user, :presence => true
def to_html_label
h = "<span class=\"hat\" title=\"Granted by " <<
"#{self.granted_by_user.username} on " <<
"#{self.created_at.strftime("%Y-%m-%d")}\">" <<
"<span class=\"crown\">"
if self.link.present?
h << "<a href=\"#{self.link}\" target=\"_blank\">"
end
h << self.hat
if self.link.present?
h << "</a>"
end
h << "</span></span>"
h.html_safe
end
end

View file

@ -27,6 +27,7 @@ class User < ActiveRecord::Base
-> { where('votes.comment_id' => nil, 'votes.vote' => 1) },
:through => :votes,
:source => :story
has_many :hats
has_secure_password

View file

@ -27,19 +27,23 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
<% if defined?(was_merged) && was_merged %>
<span class="merge"></span>
<% end %>
<a href="/u/<%= comment.user.username %>"
<% if !comment.user.is_active? %>
class="inactive_user"
<% elsif comment.user.is_new? %>
class="new_user"
<% end %>
><%= comment.user.username %></a>
<% if comment.hat %>
<%= comment.hat.to_html_label %>
<% end %>
<% if comment.previewing %>
<a><%= comment.user.username %></a>
previewed
just now
<% else %>
<a href="/u/<%= comment.user.username %>"
<% if !comment.user.is_active? %>
class="inactive_user"
<% elsif comment.user.is_new? %>
class="new_user"
<% end %>
><%= comment.user.username %></a>
<% if comment.has_been_edited? %>
edited
<% elsif comment.is_from_email? %>

View file

@ -43,6 +43,15 @@
:type => "button" %>
<% end %>
<% if @user && @user.hats.any? %>
<div style="display: inline-block; margin-left: 1em;">
Put on hat:
<%= select_tag "hat_id",
options_from_collection_for_select(@user.hats, "id", "hat",
comment.hat_id), :include_blank => true %>
</div>
<% end %>
<div style="clear: both;"></div>
<% if @user %>

View file

@ -60,6 +60,16 @@
<br>
<% end %>
<% if @showing_user.hats.any? %>
<label class="required">Hats:</label>
<span class="d">
<% @showing_user.hats.each do |hat| %>
<%= hat.to_html_label %>
<% end %>
</span>
<br>
<% end %>
<% if @showing_user.deleted_at? %>
<label class="required">Left:</label>
<span class="d">

View file

@ -0,0 +1,13 @@
class AddHats < ActiveRecord::Migration
def change
create_table :hats do |t|
t.timestamps
t.integer :user_id
t.integer :granted_by_user_id
t.string :hat
t.string :link
end
add_column :comments, :hat_id, :integer
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140901013149) do
ActiveRecord::Schema.define(version: 20141114184921) do
create_table "comments", force: true do |t|
t.datetime "created_at", null: false
@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20140901013149) do
t.boolean "is_deleted", default: false
t.boolean "is_moderated", default: false
t.boolean "is_from_email", default: false
t.integer "hat_id"
end
add_index "comments", ["confidence"], name: "confidence_idx", using: :btree
@ -36,6 +37,15 @@ ActiveRecord::Schema.define(version: 20140901013149) do
add_index "comments", ["story_id", "short_id"], name: "story_id_short_id", using: :btree
add_index "comments", ["thread_id"], name: "thread_id", using: :btree
create_table "hats", force: true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
t.integer "granted_by_user_id"
t.string "hat"
t.string "link"
end
create_table "invitation_requests", force: true do |t|
t.string "code"
t.boolean "is_verified", default: false