From fc3441606e685c0bdd061970552acc8c765f5049 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 29 Sep 2019 15:57:15 -0500 Subject: [PATCH] forum posts, comments: make timestamps into permalinks. Make the timestamp beneath the username on forum posts into a permalink that links to the post in full context of the thread. For comments, make the timestamp link to the comment in full context of the post. * Make the timestamp in forum posts link to /forum_posts/123. * Make the timestamp in comments link to /posts/456#comment_123. * Make /forum_posts/123 redirect to /forum_topics/456#forum_post_123. * Make /comments/123 redirect to /posts/456#comment_123. * Remove the "ID: ###" and "Permalink" fields from forum posts. --- app/controllers/comments_controller.rb | 7 ++++++- app/controllers/forum_posts_controller.rb | 10 ++++++---- app/javascript/src/styles/common/messages.scss | 9 ++++++--- .../comments/partials/show/_comment.html.erb | 4 ++-- app/views/comments/show.html.erb | 18 ------------------ app/views/forum_posts/_forum_post.html.erb | 10 ++-------- app/views/forum_posts/show.html.erb | 8 -------- test/functional/comments_controller_test.rb | 2 +- test/functional/forum_posts_controller_test.rb | 5 +++++ 9 files changed, 28 insertions(+), 45 deletions(-) delete mode 100644 app/views/comments/show.html.erb delete mode 100644 app/views/forum_posts/show.html.erb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 89ccf17b3..a8e828c69 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -50,7 +50,12 @@ class CommentsController < ApplicationController def show @comment = Comment.find(params[:id]) - respond_with(@comment) + + respond_with(@comment) do |format| + format.html do + redirect_to post_path(@comment.post, anchor: "comment_#{@comment.id}") + end + end end def destroy diff --git a/app/controllers/forum_posts_controller.rb b/app/controllers/forum_posts_controller.rb index 43b29d853..e58f12e17 100644 --- a/app/controllers/forum_posts_controller.rb +++ b/app/controllers/forum_posts_controller.rb @@ -33,10 +33,12 @@ class ForumPostsController < ApplicationController end def show - if request.format == "text/html" && @forum_post.id == @forum_post.topic.original_post.id - redirect_to(forum_topic_path(@forum_post.topic, :page => params[:page])) - else - respond_with(@forum_post) + respond_with(@forum_post) do |format| + format.html do + page = @forum_post.forum_topic_page + page = nil if page == 1 + redirect_to forum_topic_path(@forum_post.topic, page: page, anchor: "forum_post_#{@forum_post.id}") + end end end diff --git a/app/javascript/src/styles/common/messages.scss b/app/javascript/src/styles/common/messages.scss index 9519801ed..efa386a45 100644 --- a/app/javascript/src/styles/common/messages.scss +++ b/app/javascript/src/styles/common/messages.scss @@ -15,8 +15,10 @@ div.list-of-messages { flex-basis: 12em; margin-right: 1em; - time { + a.message-timestamp { font-style: italic; + color: var(--text-color); + &:hover { text-decoration: underline; } } } @@ -25,7 +27,8 @@ div.list-of-messages { menu { li { - margin-right: 1em; + padding: 0; + margin-right: 1.5em; } } } @@ -42,7 +45,7 @@ div.list-of-messages { margin-right: 0.5em; } - time { + a.message-timestamp { display: inline; color: var(--muted-text-color); font-size: 0.8em; diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 4a296ff16..3db1cc28a 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -1,6 +1,6 @@ <% if CurrentUser.is_moderator? || (params[:search] && params[:search][:is_deleted] =~ /t/) || !comment.is_deleted? %> -
- <%= time_ago_in_words_tagged(comment.created_at) %> + <%= link_to time_ago_in_words_tagged(comment.created_at), post_path(comment.post, anchor: "comment_#{comment.id}"), class: "message-timestamp" %>
diff --git a/app/views/comments/show.html.erb b/app/views/comments/show.html.erb deleted file mode 100644 index 36907fe2e..000000000 --- a/app/views/comments/show.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -
-
-
-
- <%= content_tag(:div, { id: "post_#{@comment.post_id}", class: ["post", *PostPresenter.preview_class(@comment.post)].join(" ") }.merge(PostPresenter.data_attributes(@comment.post))) do %> -
- <% if @comment.post.visible? %> - <%= link_to(image_tag(@comment.post.preview_file_url), post_path(@comment.post)) %> - <% end %> -
- <%= render :partial => "comments/partials/show/comment", :collection => [@comment] %> - <% end %> -
-
-
-
- -<%= render "secondary_links" %> diff --git a/app/views/forum_posts/_forum_post.html.erb b/app/views/forum_posts/_forum_post.html.erb index 280f1c962..da49b2c17 100644 --- a/app/views/forum_posts/_forum_post.html.erb +++ b/app/views/forum_posts/_forum_post.html.erb @@ -7,7 +7,7 @@ (deleted) <% end %> - <%= time_ago_in_words_tagged(forum_post.created_at) %> + <%= link_to time_ago_in_words_tagged(forum_post.created_at), forum_post, class: "message-timestamp" %>
@@ -15,9 +15,8 @@
<%= render "application/update_notice", record: forum_post %> -
  • ID: <%= forum_post.id %>
  • <% if CurrentUser.is_member? && @forum_topic %> -
  • <%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %>
  • +
  • <%= link_to "Reply", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %>
  • <% end %> <% if CurrentUser.is_moderator? && !forum_post.is_original_post?(original_forum_post_id) %> <% if forum_post.is_deleted %> @@ -33,11 +32,6 @@
  • <%= link_to "Edit", edit_forum_post_path(forum_post.id), :id => "edit_forum_post_link_#{forum_post.id}", :class => "edit_forum_post_link" %>
  • <% end %> <% end %> - <% if params[:controller] == "forum_posts" %> -
  • <%= link_to "Parent", forum_topic_path(forum_post.topic, :page => forum_post.forum_topic_page, :anchor => "forum_post_#{forum_post.id}") %>
  • - <% else %> -
  • <%= link_to "Permalink", forum_post_path(forum_post) %>
  • - <% end %> <% if forum_post.votable? %>
      <%= render "forum_post_votes/list", votes: forum_post.votes, forum_post: forum_post %> diff --git a/app/views/forum_posts/show.html.erb b/app/views/forum_posts/show.html.erb deleted file mode 100644 index b7f6102c8..000000000 --- a/app/views/forum_posts/show.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -
      -
      -

      Topic: <%= @forum_post.topic.title %>

      - <%= render "forum_post", :forum_post => @forum_post, :original_forum_post_id => @forum_post.topic.original_post.id %> -
      -
      - -<%= render "forum_topics/secondary_links" %> diff --git a/test/functional/comments_controller_test.rb b/test/functional/comments_controller_test.rb index 7bde760d6..ea2a197fe 100644 --- a/test/functional/comments_controller_test.rb +++ b/test/functional/comments_controller_test.rb @@ -110,7 +110,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest should "render" do @comment = create(:comment, post: @post) get comment_path(@comment.id) - assert_response :success + assert_redirected_to post_path(@comment.post, anchor: "comment_#{@comment.id}") end end diff --git a/test/functional/forum_posts_controller_test.rb b/test/functional/forum_posts_controller_test.rb index 29caac5dd..7c1364470 100644 --- a/test/functional/forum_posts_controller_test.rb +++ b/test/functional/forum_posts_controller_test.rb @@ -110,6 +110,11 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest assert_response 403 end + + should "redirect to the forum topic" do + get forum_post_path(@forum_post) + assert_redirected_to forum_topic_path(@forum_post.topic, anchor: "forum_post_#{@forum_post.id}") + end end context "edit action" do