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.
This commit is contained in:
evazion
2019-09-29 15:57:15 -05:00
parent 9ba46105dd
commit fc3441606e
9 changed files with 28 additions and 45 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -1,6 +1,6 @@
<% if CurrentUser.is_moderator? || (params[:search] && params[:search][:is_deleted] =~ /t/) || !comment.is_deleted? %>
<a name="comment-<%= comment.id %>"></a>
<article class="comment message"
<article id="comment_<%= comment.id %>" class="comment message"
data-id="<%= comment.id %>"
data-post-id="<%= comment.post_id %>"
data-creator-id="<%= comment.creator_id %>"
@@ -18,7 +18,7 @@
(deleted)
<% end %>
</h4>
<%= 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" %>
</div>
<div class="content">
<div class="body prose">

View File

@@ -1,18 +0,0 @@
<div id="c-comments">
<div id="a-show">
<div class="comments-for-post">
<div class="list-of-comments list-of-messages">
<%= content_tag(:div, { id: "post_#{@comment.post_id}", class: ["post", *PostPresenter.preview_class(@comment.post)].join(" ") }.merge(PostPresenter.data_attributes(@comment.post))) do %>
<div class="preview">
<% if @comment.post.visible? %>
<%= link_to(image_tag(@comment.post.preview_file_url), post_path(@comment.post)) %>
<% end %>
</div>
<%= render :partial => "comments/partials/show/comment", :collection => [@comment] %>
<% end %>
</div>
</div>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -7,7 +7,7 @@
(deleted)
<% end %>
</h4>
<%= 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" %>
</div>
<div class="content">
<div class="prose">
@@ -15,9 +15,8 @@
</div>
<%= render "application/update_notice", record: forum_post %>
<menu>
<li>ID: <%= forum_post.id %></li>
<% if CurrentUser.is_member? && @forum_topic %>
<li><%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %></li>
<li><%= link_to "Reply", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %></li>
<% end %>
<% if CurrentUser.is_moderator? && !forum_post.is_original_post?(original_forum_post_id) %>
<% if forum_post.is_deleted %>
@@ -33,11 +32,6 @@
<li><%= link_to "Edit", edit_forum_post_path(forum_post.id), :id => "edit_forum_post_link_#{forum_post.id}", :class => "edit_forum_post_link" %></li>
<% end %>
<% end %>
<% if params[:controller] == "forum_posts" %>
<li><%= link_to "Parent", forum_topic_path(forum_post.topic, :page => forum_post.forum_topic_page, :anchor => "forum_post_#{forum_post.id}") %></li>
<% else %>
<li><%= link_to "Permalink", forum_post_path(forum_post) %></li>
<% end %>
<% if forum_post.votable? %>
<ul class="votes" id="forum-post-votes-for-<%= forum_post.id %>">
<%= render "forum_post_votes/list", votes: forum_post.votes, forum_post: forum_post %>

View File

@@ -1,8 +0,0 @@
<div id="c-forum-posts">
<div id="a-show" class="single-forum-post list-of-forum-posts list-of-messages">
<h1>Topic: <%= @forum_post.topic.title %></h1>
<%= render "forum_post", :forum_post => @forum_post, :original_forum_post_id => @forum_post.topic.original_post.id %>
</div>
</div>
<%= render "forum_topics/secondary_links" %>

View File

@@ -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

View File

@@ -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