modqueue: add order options; change default order to newest first.
* Add options for changing the order of the modqueue (newest first, oldest first, highest scoring first, lowest scoring first). * Change the default order from oldest posts first to most recently flagged or uploaded posts first. * Add an order:modqueue metatag to order by most recently flagged or uploaded in standard searches.
This commit is contained in:
@@ -4,19 +4,20 @@ class ModqueueController < ApplicationController
|
||||
layout "sidebar"
|
||||
|
||||
def index
|
||||
@posts = Post.includes(:appeals, :disapprovals, :uploader, flags: [:creator]).pending_or_flagged.available_for_moderation(search_params[:hidden]).tag_match(search_params[:tags])
|
||||
@posts = Post.includes(:appeals, :disapprovals, :uploader, flags: [:creator]).pending_or_flagged.available_for_moderation(search_params[:hidden])
|
||||
@posts = @posts.paginated_search(params, order: "modqueue", count_pages: true)
|
||||
|
||||
@pending_post_count = @posts.pending.count
|
||||
@flagged_post_count = @posts.flagged.count
|
||||
@disapproval_reasons = PostDisapproval.where(post: @posts).where.not(reason: "disinterest").group(:reason).order(count: :desc).distinct.count(:post_id)
|
||||
@uploaders = @posts.reorder(nil).group(:uploader).order(count: :desc).limit(20).count
|
||||
@modqueue_posts = @posts.except(:offset, :limit, :order)
|
||||
@pending_post_count = @modqueue_posts.pending.count
|
||||
@flagged_post_count = @modqueue_posts.flagged.count
|
||||
@disapproval_reasons = PostDisapproval.where(post: @modqueue_posts).where.not(reason: "disinterest").group(:reason).order(count: :desc).distinct.count(:post_id)
|
||||
@uploaders = @modqueue_posts.group(:uploader).order(count: :desc).limit(20).count
|
||||
|
||||
@tags = RelatedTagCalculator.frequent_tags_for_post_relation(@posts)
|
||||
@tags = RelatedTagCalculator.frequent_tags_for_post_relation(@modqueue_posts)
|
||||
@artist_tags = @tags.select { |tag| tag.category == Tag.categories.artist }.sort_by(&:overlap_count).reverse.take(10)
|
||||
@copyright_tags = @tags.select { |tag| tag.category == Tag.categories.copyright }.sort_by(&:overlap_count).reverse.take(10)
|
||||
@character_tags = @tags.select { |tag| tag.category == Tag.categories.character }.sort_by(&:overlap_count).reverse.take(10)
|
||||
|
||||
@posts = @posts.reorder(id: :asc).paginated_search(params, count_pages: true)
|
||||
respond_with(@posts)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -493,7 +493,17 @@ class PostQueryBuilder
|
||||
relation = relation.where("posts.image_width IS NOT NULL and posts.image_height IS NOT NULL")
|
||||
end
|
||||
|
||||
case q[:order]
|
||||
if q[:order] == "custom" && q[:post_id].present? && q[:post_id][0] == :in
|
||||
relation = relation.find_ordered(q[:post_id][1])
|
||||
else
|
||||
relation = PostQueryBuilder.search_order(relation, q[:order])
|
||||
end
|
||||
|
||||
relation
|
||||
end
|
||||
|
||||
def self.search_order(relation, order)
|
||||
case order.to_s
|
||||
when "id", "id_asc"
|
||||
relation = relation.order("posts.id ASC")
|
||||
|
||||
@@ -602,10 +612,11 @@ class PostQueryBuilder
|
||||
.select("posts.*, COUNT(*) AS contributor_fav_count")
|
||||
.order("contributor_fav_count DESC, posts.fav_count DESC, posts.id DESC")
|
||||
|
||||
when "custom"
|
||||
if q[:post_id].present? && q[:post_id][0] == :in
|
||||
relation = relation.find_ordered(q[:post_id][1])
|
||||
end
|
||||
when "modqueue", "modqueue_desc"
|
||||
relation = relation.left_outer_joins(:flags).order("GREATEST(posts.created_at, post_flags.created_at) DESC, posts.id DESC")
|
||||
|
||||
when "modqueue_asc"
|
||||
relation = relation.left_outer_joins(:flags).order("GREATEST(posts.created_at, post_flags.created_at) ASC, posts.id ASC")
|
||||
|
||||
else
|
||||
relation = relation.order("posts.id DESC")
|
||||
|
||||
@@ -11,7 +11,7 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
extending(PaginationExtension).paginate(*args, **options)
|
||||
end
|
||||
|
||||
def paginated_search(params, defaults: {}, count_pages: params[:search].present?)
|
||||
def paginated_search(params, count_pages: params[:search].present?, **defaults)
|
||||
search_params = params.fetch(:search, {}).permit!
|
||||
search_params = defaults.merge(search_params).with_indifferent_access
|
||||
|
||||
|
||||
@@ -1546,6 +1546,30 @@ class Post < ApplicationRecord
|
||||
def tag_match(query)
|
||||
PostQueryBuilder.new(query).build
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
q = q.search_attributes(params,
|
||||
:approver, :uploader, :rating, :source, :pixiv_id, :fav_count, :score, :up_score,
|
||||
:down_score, :md5, :file_ext, :file_size, :image_width, :image_height, :tag_count,
|
||||
:parent, :has_children, :has_active_children, :is_note_locked, :is_rating_locked,
|
||||
:is_status_locked, :is_pending, :is_flagged, :is_deleted, :is_banned,
|
||||
:last_comment_bumped_at, :last_commented_at, :last_noted_at
|
||||
)
|
||||
|
||||
if params[:tags].present?
|
||||
q = q.tag_match(params[:tags])
|
||||
end
|
||||
|
||||
if params[:order].present?
|
||||
q = PostQueryBuilder.search_order(q, params[:order])
|
||||
else
|
||||
q = q.apply_default_order(params)
|
||||
end
|
||||
|
||||
q
|
||||
end
|
||||
end
|
||||
|
||||
module PixivMethods
|
||||
|
||||
@@ -38,6 +38,7 @@ class Tag < ApplicationRecord
|
||||
tagcount tagcount_asc
|
||||
rank
|
||||
curated
|
||||
modqueue
|
||||
random
|
||||
custom
|
||||
] +
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
<%= search_form_for(modqueue_index_path, classes: "one-line-form") do |f| %>
|
||||
<%= f.input :tags, label: false, input_html: { placeholder: "Tags", value: params.dig(:search, :tags), "data-autocomplete": "tag-query" } %>
|
||||
<%= f.input :order, label: false, collection: [["Newest", "modqueue"], ["Oldest", "modqueue_asc"], ["Score (Highest)", "score"], ["Score (Lowest)", "score_asc"]], selected: params[:search][:order] %>
|
||||
<%= f.button :button, name: nil, id: "search-box-submit" do %>
|
||||
<i class="fas fa-search"></i>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user