From 92042333bd2ca56342236d4a896a04044433cdef Mon Sep 17 00:00:00 2001 From: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Date: Mon, 31 Aug 2020 09:23:19 -0600 Subject: [PATCH] [deploy] Add Recent Vomit Reaction Reports to Users' Admin Users Page (#10059) * Capitalizes Admin on Admin Profile button for better consistency * Adds reactions and reports partials and adjusts filenames of _notes, _activity, and _credits * Removes code related to reports to separate this PR and the reports PR * Adds ability to toggle Recent Reactions and adds #get_related_reactions to controller - Adds a #get_related_reactions method to the Admin::Users::Controller - Moves the rendering of the reactions partial below the notes partial in edit - Styles Recent Reactions in a list format with the ability to toggle * Modifies #set_related_reactions name, query, and limit and the _reactions view with it - Adjust #get_related_reactions to read #set_related_reactions - Sort reactions by descending created_at - Add a limit of 15 to reactions displayed for any given user - Add .empty? in place of .nil? to _reactions.html.erb reaction check * Adjusts the format of how Recent Reactions are displayed and adds Reaction category * Adds a check for category: vomit in #set_related_reactions * Renames partial, adds User reactions to #set_related_reactions, and adjusts partial styling * Rewords message displayed when no negative reactions exist to make it fun * Adds additional styling changes to recent reactions --- app/controllers/admin/users_controller.rb | 12 ++++++++++ app/views/admin/users/_activity.erb | 24 ------------------- app/views/admin/users/_activity.html.erb | 22 +++++++++++++++++ .../users/{_credits.erb => _credits.html.erb} | 0 .../admin/users/_negative_reactions.html.erb | 21 ++++++++++++++++ .../users/{_notes.erb => _notes.html.erb} | 0 app/views/admin/users/edit.html.erb | 5 ++-- app/views/admin/users/show.html.erb | 12 ++++------ 8 files changed, 63 insertions(+), 33 deletions(-) delete mode 100644 app/views/admin/users/_activity.erb create mode 100644 app/views/admin/users/_activity.html.erb rename app/views/admin/users/{_credits.erb => _credits.html.erb} (100%) create mode 100644 app/views/admin/users/_negative_reactions.html.erb rename app/views/admin/users/{_notes.erb => _notes.html.erb} (100%) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 0e20af8e9..19f5ceb85 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -15,6 +15,7 @@ module Admin def edit @user = User.find(params[:id]) @notes = @user.notes.order(created_at: :desc).limit(10).load + set_related_reactions end def show @@ -170,6 +171,17 @@ module Admin Credit.remove_from(org, amount) end + def set_related_reactions + user_article_ids = @user.articles.ids + user_comment_ids = @user.comments.ids + @related_vomit_reactions = Reaction.where(reactable_type: "Comment", reactable_id: user_comment_ids, + category: "vomit") + .or(Reaction.where(reactable_type: "Article", reactable_id: user_article_ids, category: "vomit")) + .or(Reaction.where(reactable_type: "User", user_id: @user.id, category: "vomit")) + .includes(:reactable) + .order(created_at: :desc).limit(15) + end + def user_params allowed_params = %i[ new_note note_for_current_role user_status diff --git a/app/views/admin/users/_activity.erb b/app/views/admin/users/_activity.erb deleted file mode 100644 index 728bdf5ae..000000000 --- a/app/views/admin/users/_activity.erb +++ /dev/null @@ -1,24 +0,0 @@ -
-
-
-

Activity

-
    -
  • <%= @user.comments_count %> comments
  • -
  • <%= @user.articles_count %> articles
  • -
  • <%= @user.reactions_count %> reactions
  • -
  • <%= @user.followers_count %> followers
  • -
  • <%= @user.following_users_count %> users following
  • -
  • <%= @user.badge_achievements_count %> badges
  • -
-
-
-

Current Roles

-

(view full history in notes below)

-
    - <% @user.roles.each do |role| %> -
  • <%= role.name %> <%= "- " + Tag.find(role.resource_id).name if role.resource_id.present? %>
  • - <% end %> -
-
-
-
diff --git a/app/views/admin/users/_activity.html.erb b/app/views/admin/users/_activity.html.erb new file mode 100644 index 000000000..a3ce5b75f --- /dev/null +++ b/app/views/admin/users/_activity.html.erb @@ -0,0 +1,22 @@ +
+
+

Activity

+ +
+
+

Current Roles

+

(view full history in notes below)

+ +
+
diff --git a/app/views/admin/users/_credits.erb b/app/views/admin/users/_credits.html.erb similarity index 100% rename from app/views/admin/users/_credits.erb rename to app/views/admin/users/_credits.html.erb diff --git a/app/views/admin/users/_negative_reactions.html.erb b/app/views/admin/users/_negative_reactions.html.erb new file mode 100644 index 000000000..01399504b --- /dev/null +++ b/app/views/admin/users/_negative_reactions.html.erb @@ -0,0 +1,21 @@ +
+
+

Recent Reactions

+ +
+
+
+ <% unless @related_vomit_reactions.empty? %> + <% @related_vomit_reactions.each do |reaction| %> + + 🤢 <%= reaction.category.capitalize %> + <%= reaction.reactable_type %><%= reaction.reactable_type == "User" ? "" : ": #{reaction.reactable.title}" %> + <%= reaction.created_at&.strftime("%b %e '%y") %> + + <% end %> + <% else %> +

Nothing negative to see here! 👀

+ <% end %> +
+
+
diff --git a/app/views/admin/users/_notes.erb b/app/views/admin/users/_notes.html.erb similarity index 100% rename from app/views/admin/users/_notes.erb rename to app/views/admin/users/_notes.html.erb diff --git a/app/views/admin/users/edit.html.erb b/app/views/admin/users/edit.html.erb index 8d247f63e..5956f2890 100644 --- a/app/views/admin/users/edit.html.erb +++ b/app/views/admin/users/edit.html.erb @@ -9,7 +9,7 @@ <%= link_to "Unlock access", unlock_access_admin_user_path(@user), method: :patch, class: "btn btn-success" %> <% end %> - admin Profile + Admin Profile

Member since <%= @user.created_at.strftime("%b %e '%y") %>

@@ -47,7 +47,8 @@ <% end %> - <%= render "notes" %> +<%= render "notes" %> +<%= render "negative_reactions" %>
diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/users/show.html.erb index 77a63c744..062413d4d 100644 --- a/app/views/admin/users/show.html.erb +++ b/app/views/admin/users/show.html.erb @@ -35,10 +35,8 @@
- <%= render "activity" %> - <%= render "credits" %> - <%= render "notes" %> - <%= render "user_organizations" %> - <%= render "email_tools" %> - -
+<%= render "activity" %> +<%= render "credits" %> +<%= render "notes" %> +<%= render "user_organizations" %> +<%= render "email_tools" %>