aliases/implications: allow searching by antecedent or consequent tag type.

This commit is contained in:
evazion
2018-12-31 18:55:36 -06:00
parent fd1c9dbf30
commit 17a5db72a6
2 changed files with 14 additions and 1 deletions

View File

@@ -79,6 +79,11 @@ class TagRelationship < ApplicationRecord
end
end
def tag_matches(field, params)
return all if params.blank?
where(field => Tag.search(params).reorder(nil).select(:name))
end
def pending_first
# unknown statuses return null and are sorted first
order(Arel.sql("array_position(array['queued', 'processing', 'pending', 'active', 'deleted', 'retired'], status) NULLS FIRST, antecedent_name, consequent_name"))
@@ -111,6 +116,9 @@ class TagRelationship < ApplicationRecord
q = q.status_matches(params[:status])
end
q = q.tag_matches(:antecedent_name, params[:antecedent_tag])
q = q.tag_matches(:consequent_name, params[:consequent_tag])
if params[:category].present?
q = q.joins(:consequent_tag).where("tags.category": params[:category].split)
end

View File

@@ -3,7 +3,12 @@
<%= simple_form_for(:search, method: :get, url: url, 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: %w[Approved Active Pending Deleted Retired Processing Queued], include_blank: true, selected: params[:search][:status] %>
<%= f.input :category, label: "Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true, selected: params[:search][:category] %>
<%= f.simple_fields_for :antecedent_tag do |fa| %>
<%= fa.input :category, label: "From Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true, selected: params.dig(:search, :antecedent_tag, :category) %>
<% end %>
<%= f.simple_fields_for :consequent_tag do |fa| %>
<%= fa.input :category, label: "To Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true, selected: params.dig(:search, :consequent_tag, :category) %>
<% end %>
<%= 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 %>