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? %> +
+ Put on hat: + <%= select_tag "hat_id", + options_from_collection_for_select(@user.hats, "id", "hat", + comment.hat_id), :include_blank => true %> +
+ <% end %> +
<% if @user %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 1af4934..17b43a8 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -60,6 +60,16 @@
<% end %> + <% if @showing_user.hats.any? %> + + + <% @showing_user.hats.each do |hat| %> + <%= hat.to_html_label %> + <% end %> + +
+ <% end %> + <% if @showing_user.deleted_at? %> diff --git a/db/migrate/20141114184921_add_hats.rb b/db/migrate/20141114184921_add_hats.rb new file mode 100644 index 0000000..07d81fe --- /dev/null +++ b/db/migrate/20141114184921_add_hats.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index d6fa1ec..c3e4020 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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