diff --git a/app/controllers/modqueue_controller.rb b/app/controllers/modqueue_controller.rb index b77b9d083..787429b35 100644 --- a/app/controllers/modqueue_controller.rb +++ b/app/controllers/modqueue_controller.rb @@ -1,9 +1,22 @@ class ModqueueController < ApplicationController respond_to :html, :json, :xml before_action :approver_only + layout "sidebar" def index - @posts = Post.includes(:appeals, :disapprovals, :uploader, flags: [:creator]).reorder(id: :asc).pending_or_flagged.available_for_moderation(search_params[:hidden]).tag_match(search_params[:tags]).paginated_search(params, count_pages: true) + @posts = Post.includes(:appeals, :disapprovals, :uploader, flags: [:creator]).pending_or_flagged.available_for_moderation(search_params[:hidden]).tag_match(search_params[:tags]) + + @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 + + @tags = RelatedTagCalculator.frequent_tags_for_post_relation(@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 diff --git a/app/logical/related_tag_calculator.rb b/app/logical/related_tag_calculator.rb index e375fd567..898a2b308 100644 --- a/app/logical/related_tag_calculator.rb +++ b/app/logical/related_tag_calculator.rb @@ -17,7 +17,11 @@ module RelatedTagCalculator def self.frequent_tags_for_search(tag_query, search_sample_size: 1000, category: nil) sample_posts = Post.tag_match(tag_query).reorder(:md5).limit(search_sample_size) - tag_counts = Post.from(sample_posts).with_unflattened_tags.group("tag").select("tag, COUNT(*) AS overlap_count") + frequent_tags_for_post_relation(sample_posts, category: category) + end + + def self.frequent_tags_for_post_relation(posts, category: nil) + tag_counts = Post.from(posts).with_unflattened_tags.group("tag").select("tag, COUNT(*) AS overlap_count") tags = Tag.from(tag_counts).joins("JOIN tags ON tags.name = tag") tags = tags.select("tags.*, overlap_count") @@ -27,7 +31,7 @@ module RelatedTagCalculator tags end - def self.frequent_tags_for_posts(posts) + def self.frequent_tags_for_post_array(posts) tags_with_counts = posts.flat_map(&:tag_array).group_by(&:itself).transform_values(&:size) tags_with_counts.sort_by { |tag_name, count| [-count, tag_name] }.map(&:first) end diff --git a/app/presenters/post_set_presenters/post.rb b/app/presenters/post_set_presenters/post.rb index b6406348c..f34763267 100644 --- a/app/presenters/post_set_presenters/post.rb +++ b/app/presenters/post_set_presenters/post.rb @@ -44,7 +44,7 @@ module PostSetPresenters end def frequent_tags - RelatedTagCalculator.frequent_tags_for_posts(post_set.posts).take(MAX_TAGS) + RelatedTagCalculator.frequent_tags_for_post_array(post_set.posts).take(MAX_TAGS) end def pattern_tags diff --git a/app/views/layouts/sidebar.html.erb b/app/views/layouts/sidebar.html.erb index 97861a3b7..2e62247ff 100644 --- a/app/views/layouts/sidebar.html.erb +++ b/app/views/layouts/sidebar.html.erb @@ -1,13 +1,21 @@ <% content_for(:layout) do %>
- <% end %> diff --git a/app/views/modqueue/_sidebar.html.erb b/app/views/modqueue/_sidebar.html.erb new file mode 100644 index 000000000..eafe9534d --- /dev/null +++ b/app/views/modqueue/_sidebar.html.erb @@ -0,0 +1,54 @@ +<% content_for(:sidebar) do %> +

Search

+ + <%= 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.button :button, name: nil, id: "search-box-submit" do %> + + <% end %> + <% end %> + + <%= render "posts/partials/index/blacklist" %> + +
Status
+ +

+ +
Uploaders
+ +

+ +
Tags
+ + <%= render "tag_list", tags: @artist_tags %> + <%= render "tag_list", tags: @copyright_tags %> + <%= render "tag_list", tags: @character_tags %> +

+<% end %> diff --git a/app/views/modqueue/_tag_list.html.erb b/app/views/modqueue/_tag_list.html.erb new file mode 100644 index 000000000..5e90c7b24 --- /dev/null +++ b/app/views/modqueue/_tag_list.html.erb @@ -0,0 +1,10 @@ + diff --git a/app/views/modqueue/index.html.erb b/app/views/modqueue/index.html.erb index ba2199d00..1fd5a903a 100644 --- a/app/views/modqueue/index.html.erb +++ b/app/views/modqueue/index.html.erb @@ -1,39 +1,33 @@ -<% page_title "Mod Queue" %> +<% page_title "Moderation Queue" %> -
-
-
-

Moderation Queue

+<% content_for(:top_content) do %> +

Moderation Queue

- <%= search_form_for(modqueue_index_path) do |f| %> - <%= f.input :tags, input_html: { value: params.dig(:search, :tags), "data-autocomplete": "tag-query" } %> - <%= f.submit "Search" %> +
+

Deletion Guidelines

+ + <%= render "desc" %> + +

+ <% if params.dig(:search, :hidden) %> + <%= link_to "View pending posts", modqueue_index_path(search: { tags: params.dig(:search, :tags), hidden: nil }) %>. + <% else %> + <%= link_to "View hidden posts", modqueue_index_path(search: { tags: params.dig(:search, :tags), hidden: true, }) %>. <% end %> - -

-

Deletion Guidelines

- - <%= render "desc" %> - -

- <% if params.dig(:search, :hidden) %> - <%= link_to "View pending posts", modqueue_index_path(search: { tags: params.dig(:search, :tags), hidden: nil }) %>. - <% else %> - <%= link_to "View hidden posts", modqueue_index_path(search: { tags: params.dig(:search, :tags), hidden: true, }) %>. - <% end %> -

-
- - <%= render "posts/partials/common/inline_blacklist" %> - - <% @posts.each do |post| %> - <%= render "post", post: post %> - <% end %> -
- - <%= numbered_paginator(@posts) %> +

-
+<% end %> +<% content_for(:content) do %> +

Posts

+ + <% @posts.each do |post| %> + <%= render "post", post: post %> + <% end %> + + <%= numbered_paginator(@posts) %> +<% end %> + +<%= render "modqueue/sidebar" %> <%= render "post_disapprovals/detailed_rejection_dialog" %> <%= render "posts/partials/common/secondary_links" %> diff --git a/test/unit/related_tag_calculator_test.rb b/test/unit/related_tag_calculator_test.rb index 7ebc05f72..ec9d59b03 100644 --- a/test/unit/related_tag_calculator_test.rb +++ b/test/unit/related_tag_calculator_test.rb @@ -13,14 +13,14 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase end context "RelatedTagCalculator" do - context "#frequent_tags_for_posts" do + context "#frequent_tags_for_post_array" do should "calculate the most frequent tags for a set of posts" do create(:post, tag_string: "aaa bbb ccc ddd") create(:post, tag_string: "aaa bbb ccc") create(:post, tag_string: "aaa bbb") posts = Post.tag_match("aaa") - assert_equal(%w[aaa bbb ccc ddd], RelatedTagCalculator.frequent_tags_for_posts(posts)) + assert_equal(%w[aaa bbb ccc ddd], RelatedTagCalculator.frequent_tags_for_post_array(posts)) end end