Add Recent Reports to Users' Admin User Page (#10058) [deploy]
* Adds _reports partial and renders _reports.html.erb in /admin/users/edit.html.erb * Adds a Recent Reports sections and a toggle function to /admin/users/_reports * WIP: display feedback_messages in _reports.html.erb * Adds #set_feedback_messages to Admin::Users::Controller and adjusts _reports.html.erb * Adjusts #set_feedback_messages to look for message ids and adds to _reports.html.erb data * Remove accidental dead code from Admin::Users::Controller * Adjusts the else statement wording to be more fun * Adjusts style of recent reports to mirror style of recent reactions * Implement Admin UI changes to Recent Reports section of admin/users/:id/edit * Adds a link to the admin_feedback_messages_path for each report in _reports.html.erb * Adjusts the path used when a report is clicked on in _reports.html.erb * Adds #user_types check to feedback_message.rb to determine Affected, Offender, or Reporter in _reports
This commit is contained in:
parent
f49ca8909a
commit
31990b3d3b
4 changed files with 33 additions and 10 deletions
|
|
@ -15,7 +15,7 @@ module Admin
|
|||
def edit
|
||||
@user = User.find(params[:id])
|
||||
@notes = @user.notes.order(created_at: :desc).limit(10).load
|
||||
set_related_reactions
|
||||
set_feedback_messages
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
@ -171,14 +171,10 @@ 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)
|
||||
def set_feedback_messages
|
||||
@related_reports = FeedbackMessage.where(id: @user.reporter_feedback_messages.ids)
|
||||
.or(FeedbackMessage.where(id: @user.affected_feedback_messages.ids))
|
||||
.or(FeedbackMessage.where(id: @user.offender_feedback_messages.ids))
|
||||
.order(created_at: :desc).limit(15)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -26,4 +26,12 @@ class FeedbackMessage < ApplicationRecord
|
|||
def capitalize_status
|
||||
self.status = status.capitalize if status.present?
|
||||
end
|
||||
|
||||
def user_types(user_id)
|
||||
types = []
|
||||
types << "Affected" if user_id == affected_id
|
||||
types << "Offender" if user_id == offender_id
|
||||
types << "Reporter" if user_id == reporter_id
|
||||
types
|
||||
end
|
||||
end
|
||||
|
|
|
|||
19
app/views/admin/users/_reports.html.erb
Normal file
19
app/views/admin/users/_reports.html.erb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<div class="crayons-card p-6">
|
||||
<div>
|
||||
<h2 class="d-inline">Recent Reports</h2>
|
||||
<button type="button" data-toggle="collapse" data-target="#reactions-row" class="btn btn-secondary float-right">Toggle</button>
|
||||
</div>
|
||||
<div class="pt-6 collapse" id="reactions-row">
|
||||
<% unless @related_reports.empty? %>
|
||||
<% @related_reports.each do |report| %>
|
||||
<a href="<%= admin_report_path(report.id) %>" class="list-group-item list-group-item-action action px-5 d-flex justify-content-between">
|
||||
<span><%= report.category.capitalize %> (<%= report.status %>)</span>
|
||||
<span><strong><%= report.user_types(@user.id).to_sentence %></strong>: <%= report.message %></span>
|
||||
<em> <%= report.created_at&.strftime("%b %e '%y") %></em>
|
||||
</a>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<p><em>Nothing to report here! 👀</em></p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -48,7 +48,7 @@
|
|||
</div>
|
||||
|
||||
<%= render "notes" %>
|
||||
<%= render "negative_reactions" %>
|
||||
<%= render "reports" %>
|
||||
|
||||
<div class="crayons-card p-6">
|
||||
<div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue