Fix #4053: Add disapproval index improvements.
Add search form to /moderator/post/disapprovals.
This commit is contained in:
@@ -3,7 +3,7 @@ module Moderator
|
||||
class DisapprovalsController < ApplicationController
|
||||
before_action :approver_only
|
||||
skip_before_action :api_check
|
||||
respond_to :js, :json, :xml
|
||||
respond_to :js, :html, :json, :xml
|
||||
|
||||
def create
|
||||
cookies.permanent[:moderated] = Time.now.to_i
|
||||
@@ -12,7 +12,8 @@ module Moderator
|
||||
end
|
||||
|
||||
def index
|
||||
@post_disapprovals = PostDisapproval.paginate(params[:page])
|
||||
@post_disapprovals = PostDisapproval.includes(:user).search(search_params).paginate(params[:page], limit: params[:limit])
|
||||
respond_with(@post_disapprovals)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -8,6 +8,7 @@ class PostDisapproval < ApplicationRecord
|
||||
validates_inclusion_of :reason, :in => %w(legacy breaks_rules poor_quality disinterest)
|
||||
|
||||
scope :with_message, -> {where("message is not null and message <> ''")}
|
||||
scope :without_message, -> {where("message is null or message = ''")}
|
||||
scope :breaks_rules, -> {where(:reason => "breaks_rules")}
|
||||
scope :poor_quality, -> {where(:reason => "poor_quality")}
|
||||
scope :disinterest, -> {where(:reason => ["disinterest", "legacy"])}
|
||||
@@ -43,4 +44,37 @@ class PostDisapproval < ApplicationRecord
|
||||
PostVote.create(:score => -1, :post_id => post_id)
|
||||
end
|
||||
end
|
||||
|
||||
concerning :SearchMethods do
|
||||
class_methods do
|
||||
def post_tags_match(query)
|
||||
where(post_id: PostQueryBuilder.new(query).build.reorder(""))
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
q = q.attribute_matches(:post_id, params[:post_id])
|
||||
q = q.attribute_matches(:user_id, params[:user_id])
|
||||
q = q.attribute_matches(:message, params[:message_matches])
|
||||
q = q.search_text_attribute(:message, params)
|
||||
|
||||
q = q.post_tags_match(params[:post_tags_match]) if params[:post_tags_match].present?
|
||||
q = q.where(user_id: User.search(name_matches: params[:creator_name])) if params[:creator_name].present?
|
||||
q = q.where(reason: params[:reason]) if params[:reason].present?
|
||||
|
||||
q = q.with_message if params[:has_message].to_s.truthy?
|
||||
q = q.without_message if params[:has_message].to_s.falsy?
|
||||
|
||||
case params[:order]
|
||||
when "post_id", "post_id_desc"
|
||||
q = q.order(post_id: :desc, id: :desc)
|
||||
else
|
||||
q = q.apply_default_order(params)
|
||||
end
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,20 +2,44 @@
|
||||
<div id="a-index">
|
||||
<h1>Disapprovals</h1>
|
||||
|
||||
<table class="striped" width="100%">
|
||||
<%= simple_form_for(:search, url: moderator_post_disapprovals_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name] } %>
|
||||
<%= f.input :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.input :message_matches, label: "Message", input_html: { value: params[:search][:message_matches] } %>
|
||||
<%= f.input :reason, label: "Reason", collection: %w[breaks_rules disinterest poor_quality].map { |x| [x.humanize, x] }, include_blank: true, selected: params[:search][:reason] %>
|
||||
<%= f.input :has_message, label: "Has Message?", collection: %w[Yes No], include_blank: true, selected: params[:search][:has_message] %>
|
||||
<%= f.input :order, collection: [["ID", "id_desc"], ["Post ID", "post_id_desc"]], selected: params[:search][:order] %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
<table class="striped autofit" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Post</th>
|
||||
<th>Message</th>
|
||||
<th>Reason</th>
|
||||
<th>Creator</th>
|
||||
<th>Created</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @post_disapprovals.each do |post_disapproval| %>
|
||||
<tr>
|
||||
<td><%= link_to post_disapproval.post_id, post_path(post_disapproval.post_id) %></td>
|
||||
<td><%= post_disapproval.reason %>: <%= post_disapproval.message %></td>
|
||||
<td><%= post_disapproval.user.name %></td>
|
||||
<td>
|
||||
<%= link_to "post ##{post_disapproval.post_id}", post_path(post_disapproval.post_id) %>
|
||||
<%= link_to "»", moderator_post_disapprovals_path(search: params[:search].merge(post_id: post_disapproval.post_id)) %>
|
||||
</td>
|
||||
<td class="col-expand"><%= format_text(post_disapproval.message) %></td>
|
||||
<td>
|
||||
<%= link_to post_disapproval.reason.humanize, moderator_post_disapprovals_path(search: params[:search].merge(reason: post_disapproval.reason)) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to_user post_disapproval.user %>
|
||||
<%= link_to "»", moderator_post_disapprovals_path(search: params[:search].merge(creator_name: post_disapproval.user&.name)) %>
|
||||
<p>
|
||||
<%= compact_time(post_disapproval.updated_at) %>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user