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