From 2eecf4d6951969128391ef9faee1fa182a7e75f1 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 22 Jan 2021 04:26:55 -0600 Subject: [PATCH] comments: let mods click score to see votes. --- .../comment_component.html.erb | 8 ++++++- app/views/comment_votes/_search.html.erb | 11 +++++++++ .../comment_votes/index.html+compact.erb | 24 +++++++++++++++++++ app/views/comment_votes/index.html.erb | 10 +------- .../comment_votes_controller_test.rb | 7 ++++++ 5 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 app/views/comment_votes/_search.html.erb create mode 100644 app/views/comment_votes/index.html+compact.erb diff --git a/app/components/comment_component/comment_component.html.erb b/app/components/comment_component/comment_component.html.erb index 3b70a21cc..71e1bf9aa 100644 --- a/app/components/comment_component/comment_component.html.erb +++ b/app/components/comment_component/comment_component.html.erb @@ -53,7 +53,13 @@ <%= link_to upvote_icon, comment_comment_votes_path(comment_id: comment.id, score: "1"), class: "comment-upvote-link inactive-link", method: :post, remote: true %> <% end %> - <%= comment.score %> + <% if policy(CommentVote).can_see_votes? %> + <%= link_to comment_votes_path(search: { comment_id: comment.id }, variant: "compact"), class: "inactive-link" do %> + <%= comment.score %> + <% end %> + <% else %> + <%= comment.score %> + <% end %> <% if current_user.is_anonymous? %> <%= link_to downvote_icon, login_path(url: request.fullpath), class: "comment-downvote-link inactive-link" %> diff --git a/app/views/comment_votes/_search.html.erb b/app/views/comment_votes/_search.html.erb new file mode 100644 index 000000000..2fcdde6a0 --- /dev/null +++ b/app/views/comment_votes/_search.html.erb @@ -0,0 +1,11 @@ +<%= search_form_for(comment_votes_path) do |f| %> + <%= f.input :user_name, label: "Voter", input_html: { value: params[:search][:user_name], "data-autocomplete": "user" } %> + <%= f.simple_fields_for :comment do |fc| %> + <%= fc.input :creator_name, label: "Commenter", input_html: { value: params.dig(:search, :comment, :creator_name), "data-autocomplete": "user" } %> + <%= fc.input :post_tags_match, label: "Tags", input_html: { value: params.dig(:search, :comment, :post_tags_match), "data-autocomplete": "tag-query" } %> + <%= fc.input :post_id, label: "Post", input_html: { value: params.dig(:search, :comment, :post_id) } %> + <% end %> + <%= f.input :comment_id, label: "Comment", input_html: { value: params[:search][:comment_id] } %> + <%= f.input :score, collection: [["+1", "1"], ["-1", "-1"]], include_blank: true, selected: params[:search][:score] %> + <%= f.submit "Search" %> +<% end %> diff --git a/app/views/comment_votes/index.html+compact.erb b/app/views/comment_votes/index.html+compact.erb new file mode 100644 index 000000000..053c3b37e --- /dev/null +++ b/app/views/comment_votes/index.html+compact.erb @@ -0,0 +1,24 @@ +<%= render "comments/secondary_links" %> + +
+
+ <%= render "search" %> + + <%= table_for @comment_votes, class: "striped autofit" do |t| %> + <% t.column "Score" do |vote| %> + <%= link_to sprintf("%+d", vote.score), comment_votes_path(search: { score: vote.score }) %> + <% end %> + + <% t.column "Voter" do |vote| %> + <%= link_to_user vote.user %> + <%= link_to "ยป", comment_votes_path(search: { user_name: vote.user.name }) %> + <% end %> + + <% t.column "Created" do |vote| %> + <%= time_ago_in_words_tagged(vote.created_at) %> + <% end %> + <% end %> + + <%= numbered_paginator(@comment_votes) %> +
+
diff --git a/app/views/comment_votes/index.html.erb b/app/views/comment_votes/index.html.erb index 728ba5e52..8c17a05d7 100644 --- a/app/views/comment_votes/index.html.erb +++ b/app/views/comment_votes/index.html.erb @@ -2,15 +2,7 @@
- <%= search_form_for(comment_votes_path) do |f| %> - <%= f.input :user_name, label: "Voter", input_html: { value: params[:search][:user_name], "data-autocomplete": "user" } %> - <%= f.simple_fields_for :comment do |fc| %> - <%= fc.input :creator_name, label: "Commenter", input_html: { value: params.dig(:search, :comment, :creator_name), "data-autocomplete": "user" } %> - <%= fc.input :post_tags_match, label: "Tags", input_html: { value: params.dig(:search, :comment, :post_tags_match), "data-autocomplete": "tag-query" } %> - <% end %> - <%= f.input :score, collection: [["+1", "1"], ["-1", "-1"]], include_blank: true, selected: params[:search][:score] %> - <%= f.submit "Search" %> - <% end %> + <%= render "search" %> <%= table_for @comment_votes, class: "striped autofit" do |t| %> <% t.column "Post" do |vote| %> diff --git a/test/functional/comment_votes_controller_test.rb b/test/functional/comment_votes_controller_test.rb index 9be3afc2c..cc3f71727 100644 --- a/test/functional/comment_votes_controller_test.rb +++ b/test/functional/comment_votes_controller_test.rb @@ -44,6 +44,13 @@ class CommentVotesControllerTest < ActionDispatch::IntegrationTest should respond_to_search(user: {level: User::Levels::GOLD}).with { @vote } end end + + context "compact variant" do + should "render" do + get_auth comment_votes_path(variant: "compact"), create(:moderator_user) + assert_response :success + end + end end context "create action" do