aliases/implications: add status/tag type/order search options.
This commit is contained in:
@@ -22,8 +22,7 @@ class TagAliasesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@search = TagAlias.search(params[:search])
|
@tag_aliases = TagAlias.search(params[:search]).paginate(params[:page], :limit => params[:limit])
|
||||||
@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])
|
|
||||||
respond_with(@tag_aliases) do |format|
|
respond_with(@tag_aliases) do |format|
|
||||||
format.xml do
|
format.xml do
|
||||||
render :xml => @tag_aliases.to_xml(:root => "tag-aliases")
|
render :xml => @tag_aliases.to_xml(:root => "tag-aliases")
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ class TagImplicationsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@search = TagImplication.search(params[:search])
|
@tag_implications = TagImplication.search(params[:search]).paginate(params[:page], :limit => params[:limit])
|
||||||
@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])
|
|
||||||
respond_with(@tag_implications) do |format|
|
respond_with(@tag_implications) do |format|
|
||||||
format.xml do
|
format.xml do
|
||||||
render :xml => @tag_implications.to_xml(:root => "tag-implications")
|
render :xml => @tag_implications.to_xml(:root => "tag-implications")
|
||||||
|
|||||||
@@ -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)
|
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
|
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
|
def active
|
||||||
where(status: %w[active processing queued])
|
where(status: %w[active processing queued])
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = where("true")
|
q = all
|
||||||
return q if params.blank?
|
|
||||||
|
|
||||||
if params[:id].present?
|
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
|
end
|
||||||
|
|
||||||
if params[:name_matches].present?
|
if params[:name_matches].present?
|
||||||
@@ -71,16 +84,33 @@ class TagRelationship < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
if params[:antecedent_name].present?
|
if params[:antecedent_name].present?
|
||||||
q = q.where("antecedent_name = ?", params[:antecedent_name])
|
q = q.where(antecedent_name: params[:antecedent_name].split)
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:consequent_name].present?
|
if params[:consequent_name].present?
|
||||||
q = q.where("consequent_name = ?", params[:consequent_name])
|
q = q.where(consequent_name: params[:consequent_name].split)
|
||||||
end
|
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"
|
when "created_at"
|
||||||
q = q.order("created_at desc")
|
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
|
end
|
||||||
|
|
||||||
q
|
q
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% tag_aliases.each do |tag_alias| %>
|
<% tag_aliases.each do |tag_alias| %>
|
||||||
<tr id="tag-alias-<%= tag_alias.id %>">
|
<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 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>
|
<td>
|
||||||
<% if tag_alias.forum_topic_id %>
|
<% if tag_alias.forum_topic_id %>
|
||||||
@@ -45,4 +45,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
<div id="c-tag-aliases">
|
<div id="c-tag-aliases">
|
||||||
<div id="a-index">
|
<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 :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" %>
|
<%= f.submit "Search" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
@@ -16,4 +19,3 @@
|
|||||||
<% content_for(:page_title) do %>
|
<% content_for(:page_title) do %>
|
||||||
Tag Aliases - <%= Danbooru.config.app_name %>
|
Tag Aliases - <%= Danbooru.config.app_name %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
<div id="c-tag-implications">
|
<div id="c-tag-implications">
|
||||||
<div id="a-index">
|
<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 :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" %>
|
<%= f.submit "Search" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user