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"
|
layout "sidebar"
|
||||||
|
|
||||||
def index
|
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
|
@modqueue_posts = @posts.except(:offset, :limit, :order)
|
||||||
@flagged_post_count = @posts.flagged.count
|
@pending_post_count = @modqueue_posts.pending.count
|
||||||
@disapproval_reasons = PostDisapproval.where(post: @posts).where.not(reason: "disinterest").group(:reason).order(count: :desc).distinct.count(:post_id)
|
@flagged_post_count = @modqueue_posts.flagged.count
|
||||||
@uploaders = @posts.reorder(nil).group(:uploader).order(count: :desc).limit(20).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)
|
@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)
|
@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)
|
@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)
|
respond_with(@posts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -493,7 +493,17 @@ class PostQueryBuilder
|
|||||||
relation = relation.where("posts.image_width IS NOT NULL and posts.image_height IS NOT NULL")
|
relation = relation.where("posts.image_width IS NOT NULL and posts.image_height IS NOT NULL")
|
||||||
end
|
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"
|
when "id", "id_asc"
|
||||||
relation = relation.order("posts.id ASC")
|
relation = relation.order("posts.id ASC")
|
||||||
|
|
||||||
@@ -602,10 +612,11 @@ class PostQueryBuilder
|
|||||||
.select("posts.*, COUNT(*) AS contributor_fav_count")
|
.select("posts.*, COUNT(*) AS contributor_fav_count")
|
||||||
.order("contributor_fav_count DESC, posts.fav_count DESC, posts.id DESC")
|
.order("contributor_fav_count DESC, posts.fav_count DESC, posts.id DESC")
|
||||||
|
|
||||||
when "custom"
|
when "modqueue", "modqueue_desc"
|
||||||
if q[:post_id].present? && q[:post_id][0] == :in
|
relation = relation.left_outer_joins(:flags).order("GREATEST(posts.created_at, post_flags.created_at) DESC, posts.id DESC")
|
||||||
relation = relation.find_ordered(q[:post_id][1])
|
|
||||||
end
|
when "modqueue_asc"
|
||||||
|
relation = relation.left_outer_joins(:flags).order("GREATEST(posts.created_at, post_flags.created_at) ASC, posts.id ASC")
|
||||||
|
|
||||||
else
|
else
|
||||||
relation = relation.order("posts.id DESC")
|
relation = relation.order("posts.id DESC")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
extending(PaginationExtension).paginate(*args, **options)
|
extending(PaginationExtension).paginate(*args, **options)
|
||||||
end
|
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 = params.fetch(:search, {}).permit!
|
||||||
search_params = defaults.merge(search_params).with_indifferent_access
|
search_params = defaults.merge(search_params).with_indifferent_access
|
||||||
|
|
||||||
|
|||||||
@@ -1546,6 +1546,30 @@ class Post < ApplicationRecord
|
|||||||
def tag_match(query)
|
def tag_match(query)
|
||||||
PostQueryBuilder.new(query).build
|
PostQueryBuilder.new(query).build
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
module PixivMethods
|
module PixivMethods
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class Tag < ApplicationRecord
|
|||||||
tagcount tagcount_asc
|
tagcount tagcount_asc
|
||||||
rank
|
rank
|
||||||
curated
|
curated
|
||||||
|
modqueue
|
||||||
random
|
random
|
||||||
custom
|
custom
|
||||||
] +
|
] +
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
<%= search_form_for(modqueue_index_path, classes: "one-line-form") do |f| %>
|
<%= 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 :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 %>
|
<%= f.button :button, name: nil, id: "search-box-submit" do %>
|
||||||
<i class="fas fa-search"></i>
|
<i class="fas fa-search"></i>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user