From bc2d7702ee8d81b29490fada0cc2a67b3a5665b8 Mon Sep 17 00:00:00 2001 From: Rajat Talesra Date: Fri, 30 Jun 2023 00:31:07 +0530 Subject: [PATCH] Standalone "admin" page for each comment (#19644) * Created separate comments page * Optimised code for single comment and multiple comments * Indifual comments poage added * Minor header change * Created show method * Applied review changes * Removed like button from admin comments page --- app/controllers/admin/comments_controller.rb | 4 ++ app/views/admin/comments/_comment.html.erb | 38 ++++++++++++++ app/views/admin/comments/index.html.erb | 52 +------------------- app/views/admin/comments/show.html.erb | 2 + config/locales/views/moderations/en.yml | 3 ++ config/locales/views/moderations/fr.yml | 3 ++ config/routes/admin.rb | 2 +- 7 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 app/views/admin/comments/_comment.html.erb create mode 100644 app/views/admin/comments/show.html.erb diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index bbed32298..b404618bf 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb @@ -19,6 +19,10 @@ module Admin end end + def show + @comment = Comment.includes(:user, :commentable).find(params[:id]) + end + private def authorize_admin diff --git a/app/views/admin/comments/_comment.html.erb b/app/views/admin/comments/_comment.html.erb new file mode 100644 index 000000000..ee180ff21 --- /dev/null +++ b/app/views/admin/comments/_comment.html.erb @@ -0,0 +1,38 @@ +
+
+ <% if comment.commentable %> +
+
+ <% if comment.user %> + + <%= comment.user.username %> profile + + <% end %> +

+ <%= comment.user.username %> + on: + <%= comment.commentable.title %> +

+
+
+ <% end %> +
+ <%= sanitize comment.processed_html, + tags: %w[strong em p h1 h2 h3 h4 h5 h6 i u b code pre br ul ol li small sup img a span hr blockquote], + attributes: %w[href strong em ref rel src title alt class] %> +
+ +
+
diff --git a/app/views/admin/comments/index.html.erb b/app/views/admin/comments/index.html.erb index 2b5b4a228..d27c1086b 100644 --- a/app/views/admin/comments/index.html.erb +++ b/app/views/admin/comments/index.html.erb @@ -1,58 +1,8 @@

Comments

- <%= paginate @comments %>
- <% @comments.each do |comment| %> -
- <% if comment.commentable %> -
-
- <% if comment.user %> - - <%= comment.user.username %> profile - - <% end %> -

- <%= comment.user.username %> - on: - <%= comment.commentable.title %> -

-
-
- <% end %> -
- <%= sanitize comment.processed_html, - tags: %w[strong em p h1 h2 h3 h4 h5 h6 i u b code pre br ul ol li small sup img a span hr blockquote], - attributes: %w[href strong em ref rel src title alt class] %> -
-
- ❤️ <%= pluralize(comment.public_reactions_count, "like") %> - <% if comment.reactions.where(user_id: current_user.id).empty? %> - <%= form_tag(reactions_path, remote: true) do %> - <%= hidden_field_tag(:reactable_type, "Comment") %> - <%= hidden_field_tag(:reactable_id, comment.id) %> - - <% end %> - <% end %> -
- View -
-
-
- <% end %> + <%= render partial: "comment", collection: @comments, locals: { is_individual_comment: false } %>
<%= paginate @comments %> - - diff --git a/app/views/admin/comments/show.html.erb b/app/views/admin/comments/show.html.erb new file mode 100644 index 000000000..9e2ffcf89 --- /dev/null +++ b/app/views/admin/comments/show.html.erb @@ -0,0 +1,2 @@ +

Comment

+<%= render partial: "comment", locals: { comment: @comment, is_individual_comment: true } %> diff --git a/config/locales/views/moderations/en.yml b/config/locales/views/moderations/en.yml index 63d178c8d..9a05561ca 100644 --- a/config/locales/views/moderations/en.yml +++ b/config/locales/views/moderations/en.yml @@ -162,6 +162,9 @@ en: terms_and_conditions: Terms & Conditions trusted: Trusted User Guide author: Author + comments: + view_comment: View Comment + view_details: View Details date: Date notice: subtitle: '%{community} Mods' diff --git a/config/locales/views/moderations/fr.yml b/config/locales/views/moderations/fr.yml index 22989a6c1..f20aa89e3 100644 --- a/config/locales/views/moderations/fr.yml +++ b/config/locales/views/moderations/fr.yml @@ -161,6 +161,9 @@ fr: terms_and_conditions: Conditions générales d'utilisation trusted: Guide de l'utilisateur de confiance author: Auteur + comments: + view_comment: Voir le commentaire + view_details: Voir les détails date: Date notice: subtitle: '%{community} Mods' diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 199683aae..ec6ba0729 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -82,7 +82,7 @@ namespace :admin do resources :badge_achievements, only: %i[index destroy] get "/badge_achievements/award_badges", to: "badge_achievements#award" post "/badge_achievements/award_badges", to: "badge_achievements#award_badges" - resources :comments, only: [:index] + resources :comments, only: %i[index show] resources :organizations, only: %i[index show] do member do patch "update_org_credits"