Add terms to filter

This commit is contained in:
Jose Farias
2024-11-12 19:14:40 -06:00
parent 8bc89d497c
commit 932fc341ce
7 changed files with 30 additions and 25 deletions
+3 -9
View File
@@ -3,16 +3,10 @@ module FiltersHelper
"#{name}_filter--#{value}"
end
def filter_chips(filter, terms, **)
filters = filter.to_h.map do |kind, object|
def filter_chips(filter, **)
filter.to_h.map do |kind, object|
filter_button_from kind, object, **
end
terms = Array.wrap(terms).map do |term|
filter_button_from :terms, term, **
end
safe_join filters + terms
end.join.html_safe
end
def filter_chip_tag(display:, value:, name:, **options)
+4
View File
@@ -28,6 +28,10 @@ class Filter < ApplicationRecord
result = result.assigned_to(assignees.ids) if assignees.present?
result = result.in_bucket(buckets.ids) if buckets.present?
result = result.tagged_with(tags.ids) if tags.present?
result = terms.reduce(result) do |result, term|
result.mentioning(term)
end
result
end
end
+11 -11
View File
@@ -9,20 +9,20 @@ module Filter::Fields
end
end
def assignments=(value)
fields["assignments"] = value
end
included do
store_accessor :fields, :indexed_by, :assignments, :terms
def assignments
fields["assignments"].to_s.inquiry
end
def indexed_by
(super || default_fields["indexed_by"]).inquiry
end
def indexed_by=(value)
fields["indexed_by"] = value
end
def assignments
super.to_s.inquiry
end
def indexed_by
(fields["indexed_by"] || default_fields["indexed_by"]).inquiry
def terms
Array(super)
end
end
private
+2 -1
View File
@@ -1,7 +1,7 @@
module Filter::Params
extend ActiveSupport::Concern
PERMITTED_PARAMS = [ :indexed_by, :assignments, bucket_ids: [], assignee_ids: [], tag_ids: [] ]
PERMITTED_PARAMS = [ :indexed_by, :assignments, bucket_ids: [], assignee_ids: [], tag_ids: [], terms: [] ]
included do
before_save { self.params_digest = self.class.digest_params(as_params) }
@@ -22,6 +22,7 @@ module Filter::Params
h["assignees"] = assignees
h["tags"] = tags
h["buckets"] = buckets
h["terms"] = terms
end.reject do |k, v|
default_fields[k] == v
end.compact_blank
+7 -1
View File
@@ -1,6 +1,6 @@
module Filter::Summarized
def summary
[ index_summary, tag_summary, assignee_summary ].compact.to_sentence + " #{bucket_summary}"
[ index_summary, tag_summary, assignee_summary, terms_summary ].compact.to_sentence + " #{bucket_summary}"
end
def plain_summary
@@ -33,4 +33,10 @@ module Filter::Summarized
"in <mark>all projects</mark>"
end
end
def terms_summary
if terms.any?
"matching <mark>#{terms.map { |term| %Q("#{term}") }.to_sentence}</mark>"
end
end
end
+2 -2
View File
@@ -10,7 +10,7 @@
</button>
<%= form_with url: bubbles_path, method: :get, class: "flex-inline center align-center gap-half", data: { controller: "form" } do %>
<%= filter_chips filter, terms %>
<%= filter_chips filter %>
<% end %>
</div>
@@ -38,7 +38,7 @@
</button>
<%= form_with url: bubbles_path, id: :filter_form, method: :get, class: "flex-inline center align-center gap-half" do %>
<%= filter_chips filter, terms, class: "fill-selected" %>
<%= filter_chips filter, class: "fill-selected" %>
<% end %>
</div>
+1 -1
View File
@@ -8,7 +8,7 @@
<% end %>
<header class="txt-align-center">
<%= render "bubbles/filters", filter: @filter, terms: params[:terms] %>
<%= render "bubbles/filters", filter: @filter %>
</header>
<% if @filter.buckets.any? %>