diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index 8b9739350..8913a806b 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -22,8 +22,7 @@ class TagAliasesController < ApplicationController end def index - @search = TagAlias.search(params[:search]) - @tag_aliases = @search.order("(case status when 'pending' then 1 when 'queued' then 2 when 'active' then 3 else 0 end), antecedent_name, consequent_name").paginate(params[:page], :limit => params[:limit]) + @tag_aliases = TagAlias.search(params[:search]).paginate(params[:page], :limit => params[:limit]) respond_with(@tag_aliases) do |format| format.xml do render :xml => @tag_aliases.to_xml(:root => "tag-aliases") diff --git a/app/controllers/tag_implications_controller.rb b/app/controllers/tag_implications_controller.rb index 12f268e8a..387d984de 100644 --- a/app/controllers/tag_implications_controller.rb +++ b/app/controllers/tag_implications_controller.rb @@ -22,8 +22,7 @@ class TagImplicationsController < ApplicationController end def index - @search = TagImplication.search(params[:search]) - @tag_implications = @search.order("(case status when 'pending' then 1 when 'queued' then 2 when 'active' then 3 else 0 end), antecedent_name, consequent_name").paginate(params[:page], :limit => params[:limit]) + @tag_implications = TagImplication.search(params[:search]).paginate(params[:page], :limit => params[:limit]) respond_with(@tag_implications) do |format| format.xml do render :xml => @tag_implications.to_xml(:root => "tag-implications") diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index c581c75a3..21515be19 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -54,16 +54,29 @@ class TagRelationship < ApplicationRecord where("(antecedent_name like ? escape E'\\\\' or consequent_name like ? escape E'\\\\')", name.mb_chars.downcase.to_escaped_for_sql_like, name.mb_chars.downcase.to_escaped_for_sql_like) end + def status_matches(status) + status = status.downcase + + if status == "approved" + where(status: %w[active processing queued]) + else + where(status: status) + end + end + + def pending_first + order("(case status when 'pending' then 1 when 'queued' then 2 when 'active' then 3 else 0 end), antecedent_name, consequent_name") + end + def active where(status: %w[active processing queued]) end def search(params) - q = where("true") - return q if params.blank? + q = all if params[:id].present? - q = q.where("id in (?)", params[:id].split(",").map(&:to_i)) + q = q.where(id: params[:id].split(",").map(&:to_i)) end if params[:name_matches].present? @@ -71,16 +84,33 @@ class TagRelationship < ApplicationRecord end if params[:antecedent_name].present? - q = q.where("antecedent_name = ?", params[:antecedent_name]) + q = q.where(antecedent_name: params[:antecedent_name].split) end if params[:consequent_name].present? - q = q.where("consequent_name = ?", params[:consequent_name]) + q = q.where(consequent_name: params[:consequent_name].split) end - case params[:order] + if params[:status].present? + q = q.status_matches(params[:status]) + end + + if params[:category].present? + q = q.joins(:consequent_tag).where("tags.category": params[:category].split) + end + + params[:order] ||= "status" + case params[:order].downcase + when "status" + q = q.pending_first when "created_at" q = q.order("created_at desc") + when "updated_at" + q = q.order("updated_at desc") + when "name" + q = q.order("antecedent_name asc, consequent_name asc") + when "tag_count" + q = q.joins(:consequent_tag).order("tags.post_count desc, antecedent_name asc, consequent_name asc") end q diff --git a/app/views/tag_aliases/_listing.html.erb b/app/views/tag_aliases/_listing.html.erb index 354c1bb20..41aec5c86 100644 --- a/app/views/tag_aliases/_listing.html.erb +++ b/app/views/tag_aliases/_listing.html.erb @@ -12,7 +12,7 @@ <% tag_aliases.each do |tag_alias| %> - <%= link_to tag_alias.antecedent_name, posts_path(:tags => tag_alias.antecedent_name) %> <%= tag_alias.antecedent_tag.post_count rescue 0 %> + <%= link_to tag_alias.antecedent_name, posts_path(:tags => tag_alias.antecedent_name) %> <%= tag_alias.antecedent_tag.post_count rescue 0 %> <%= link_to tag_alias.consequent_name, posts_path(:tags => tag_alias.consequent_name) %> <%= tag_alias.consequent_tag.post_count rescue 0 %> <% if tag_alias.forum_topic_id %> @@ -45,4 +45,4 @@ <% end %> - \ No newline at end of file + diff --git a/app/views/tag_aliases/index.html.erb b/app/views/tag_aliases/index.html.erb index c4490abcc..2f4b59f7c 100644 --- a/app/views/tag_aliases/index.html.erb +++ b/app/views/tag_aliases/index.html.erb @@ -1,7 +1,10 @@
- <%= simple_form_for(:search, method: :get, url: tag_aliases_path, defaults: { required: false }) do |f| %> + <%= simple_form_for(:search, method: :get, url: tag_aliases_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %> <%= f.input :name_matches, label: "Name", input_html: { value: params[:search][:name_matches], data: { autocomplete: "tag" } } %> + <%= f.input :status, label: "Status", collection: ["", "Approved", "Pending"], selected: params[:search][:status] %> + <%= f.input :category, label: "Category", collection: Danbooru.config.canonical_tag_category_mapping.to_a, include_blank: true, selected: params[:search][:category] %> + <%= f.input :order, label: "Order", collection: [%w[Status status], %w[Recently\ created created_at], %w[Recently\ updated updated_at], %w[Name name], %w[Tag\ count tag_count]], selected: params[:search][:order] %> <%= f.submit "Search" %> <% end %> @@ -16,4 +19,3 @@ <% content_for(:page_title) do %> Tag Aliases - <%= Danbooru.config.app_name %> <% end %> - diff --git a/app/views/tag_implications/index.html.erb b/app/views/tag_implications/index.html.erb index 7bdafbbc1..fb983ea2e 100644 --- a/app/views/tag_implications/index.html.erb +++ b/app/views/tag_implications/index.html.erb @@ -1,7 +1,10 @@
- <%= simple_form_for(:search, method: :get, url: tag_implications_path, defaults: { required: false }) do |f| %> + <%= simple_form_for(:search, method: :get, url: tag_implications_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %> <%= f.input :name_matches, label: "Name", input_html: { value: params[:search][:name_matches], data: { autocomplete: "tag" } } %> + <%= f.input :status, label: "Status", collection: ["", "Approved", "Pending"], selected: params[:search][:status] %> + <%= f.input :category, label: "Category", collection: Danbooru.config.canonical_tag_category_mapping.to_a, include_blank: true, selected: params[:search][:category] %> + <%= f.input :order, label: "Order", collection: [%w[Status status], %w[Recently\ created created_at], %w[Recently\ updated updated_at], %w[Name name], %w[Tag\ count tag_count]], selected: params[:search][:order] %> <%= f.submit "Search" %> <% end %>