From e535a1387f109f15242ef137f1450048f188504d Mon Sep 17 00:00:00 2001 From: joshua stein Date: Tue, 3 Jul 2012 12:12:20 -0500 Subject: [PATCH] make linking to specific comments work --- app/assets/stylesheets/application.css | 11 +++-- app/controllers/stories_controller.rb | 64 +++++++++++++++++++++----- app/models/comment.rb | 4 +- app/views/comments/_comment.html.erb | 1 + config/routes.rb | 1 + 5 files changed, 65 insertions(+), 16 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 7790c6a..821bd76 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -359,7 +359,8 @@ li.downvoted div.voters a.downvoter { ol.stories li, ol.comments li { clear: both; - padding-top: 1em; + padding-top: 0.5em; + padding-bottom: 0.5em; } ol.stories li:first-child { padding-top: 0.5em; @@ -382,6 +383,10 @@ ol.comments li.negative_7 { opacity: 0.2; } +ol.comments li.highlighted { + background-color: #ffffbf; +} + li .link { font-weight: bold; vertical-align: middle; @@ -540,8 +545,8 @@ div#story_box div.markdown_help_toggler { width: 610px; } -div.comment_form_container { - max-width: 550px; +div.comment_form_container, div.comment_reply { + max-width: 500px; } /* data tables */ diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 04d5c50..deaf284 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -76,27 +76,67 @@ class StoriesController < ApplicationController end end - def show - @story = Story.find_by_short_id!(params[:id]) + def show + @story = Story.find_by_short_id!(params[:id]) @page_title = @story.title - @comments = Comment.ordered_for_story_or_thread_for_user( - @story.id, nil, @user ? @user.id : nil) + @comments = Comment.ordered_for_story_or_thread_for_user(@story.id, nil, + @user ? @user.id : nil) @comment = Comment.new - if @user - if v = Vote.find_by_user_id_and_story_id(@user.id, @story.id) - @story.vote = v.vote + if @user + if v = Vote.find_by_user_id_and_story_id(@user.id, @story.id) + @story.vote = v.vote end - @votes = Vote.comment_votes_by_user_for_story_hash(@user.id, @story.id) - @comments.each do |c| - if @votes[c.id] - c.current_vote = @votes[c.id] + @votes = Vote.comment_votes_by_user_for_story_hash(@user.id, @story.id) + @comments.each do |c| + if @votes[c.id] + c.current_vote = @votes[c.id] end end - end + end + end + + def show_comment + @story = Story.find_by_short_id!(params[:id]) + + @page_title = @story.title + + @showing_comment = Comment.find_by_short_id(params[:comment_short_id]) + + if !@showing_comment + flash[:error] = "Could not find comment. It may have been deleted." + return redirect_to @story.comments_url + end + + @comments = Comment.ordered_for_story_or_thread_for_user(@story.id, + @showing_comment.thread_id, @user ? @user.id : nil) + + @comments.each do |c,x| + if c.id == @showing_comment.id + c.highlighted = true + break + end + end + + @comment = Comment.new + + if @user + if v = Vote.find_by_user_id_and_story_id(@user.id, @story.id) + @story.vote = v.vote + end + + @votes = Vote.comment_votes_by_user_for_story_hash(@user.id, @story.id) + @comments.each do |c| + if @votes[c.id] + c.current_vote = @votes[c.id] + end + end + end + + render :action => "show" end def undelete diff --git a/app/models/comment.rb b/app/models/comment.rb index ec430b6..fd266c6 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -9,7 +9,7 @@ class Comment < ActiveRecord::Base attr_accessible :comment attr_accessor :parent_comment_short_id, :current_vote, :previewing, - :indent_level + :indent_level, :highlighted before_create :assign_short_id_and_upvote after_create :assign_votes, :mark_submitter, :email_reply @@ -150,6 +150,8 @@ class Comment < ActiveRecord::Base } recursor.call(nil, 0) + # TODO: handle deleted comments, show for user_id + ordered end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 9a0776a..44e3d0e 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,6 +1,7 @@
  • + <%= comment.highlighted ? "highlighted" : "" %> <%= comment.score <= 0 ? "negative" : "" %> <%= comment.score <= -3 ? "negative_3" : "" %> <%= comment.score <= -5 ? "negative_5" : "" %> diff --git a/config/routes.rb b/config/routes.rb index 4101765..453e1f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,6 +37,7 @@ Lobsters::Application.routes.draw do post "/comments/:story_id" => "comments#create" post "/comments/preview/:story_id" => "comments#preview" + get "/s/:id/:title/comments/:comment_short_id" => "stories#show_comment" get "/s/:id/(:title)" => "stories#show" get "/u/:id" => "users#show"