aliases/implications: add status/tag type/order search options.

This commit is contained in:
evazion
2017-07-29 16:21:09 -05:00
parent 49f5a1060e
commit 8142f74381
6 changed files with 48 additions and 15 deletions

View File

@@ -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")

View File

@@ -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")

View File

@@ -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

View File

@@ -12,7 +12,7 @@
<tbody>
<% tag_aliases.each do |tag_alias| %>
<tr id="tag-alias-<%= tag_alias.id %>">
<td class="category-<%= tag_alias.antecedent_tag.category %>"><%= link_to tag_alias.antecedent_name, posts_path(:tags => tag_alias.antecedent_name) %> <span class="count"><%= tag_alias.antecedent_tag.post_count rescue 0 %></span></td>
<td class="category-<%= tag_alias.antecedent_tag.try(:category) %>"><%= link_to tag_alias.antecedent_name, posts_path(:tags => tag_alias.antecedent_name) %> <span class="count"><%= tag_alias.antecedent_tag.post_count rescue 0 %></span></td>
<td class="category-<%= tag_alias.consequent_tag.try(:category) %>"><%= link_to tag_alias.consequent_name, posts_path(:tags => tag_alias.consequent_name) %> <span class="count"><%= tag_alias.consequent_tag.post_count rescue 0 %></span></td>
<td>
<% if tag_alias.forum_topic_id %>
@@ -45,4 +45,4 @@
</tr>
<% end %>
</tbody>
</table>
</table>

View File

@@ -1,7 +1,10 @@
<div id="c-tag-aliases">
<div id="a-index">
<%= 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 %>

View File

@@ -1,7 +1,10 @@
<div id="c-tag-implications">
<div id="a-index">
<%= 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 %>