diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 2dff4d2..74de839 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -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; diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index cec8768..a196292 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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, diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index bba1397..696e2c3 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -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| diff --git a/app/models/comment.rb b/app/models/comment.rb index ab627f7..b689f00 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/hat.rb b/app/models/hat.rb new file mode 100644 index 0000000..f1d6ebe --- /dev/null +++ b/app/models/hat.rb @@ -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 = "" << + "" + + if self.link.present? + h << "" + end + + h << self.hat + + if self.link.present? + h << "" + end + + h << "" + + h.html_safe + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 876528c..ad99812 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 56a5c38..350e525 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -27,19 +27,23 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? <% if defined?(was_merged) && was_merged %> <% end %> + + + class="inactive_user" + <% elsif comment.user.is_new? %> + class="new_user" + <% end %> + ><%= comment.user.username %> + + <% if comment.hat %> + <%= comment.hat.to_html_label %> + <% end %> + <% if comment.previewing %> - <%= comment.user.username %> previewed just now <% else %> - - class="inactive_user" - <% elsif comment.user.is_new? %> - class="new_user" - <% end %> - ><%= comment.user.username %> - <% if comment.has_been_edited? %> edited <% elsif comment.is_from_email? %> diff --git a/app/views/comments/_commentbox.html.erb b/app/views/comments/_commentbox.html.erb index 77f6c3e..093e4cb 100644 --- a/app/views/comments/_commentbox.html.erb +++ b/app/views/comments/_commentbox.html.erb @@ -43,6 +43,15 @@ :type => "button" %> <% end %> + <% if @user && @user.hats.any? %> +