mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-09 23:06:06 +00:00
Add "None" option to tags filter in product search
This commit is contained in:
@@ -7,6 +7,7 @@ module Admin
|
||||
|
||||
before_action :init_filters_params
|
||||
before_action :init_pagination_params
|
||||
before_action :init_none_tag
|
||||
|
||||
def index
|
||||
fetch_products
|
||||
@@ -242,11 +243,8 @@ module Admin
|
||||
def apply_tags_filter(base_query)
|
||||
return base_query if @tags.blank?
|
||||
|
||||
tags = Array(@tags)
|
||||
none_key = I18n.t('admin.products_v3.filters.tags.none')
|
||||
|
||||
has_none = tags.include?(none_key)
|
||||
tag_names = tags.reject { |t| t == none_key }
|
||||
tag_names = Array(@tags).dup
|
||||
has_none_tag = (tag_names.delete(@none_tag_value) == @none_tag_value)
|
||||
|
||||
queries = []
|
||||
|
||||
@@ -260,7 +258,7 @@ module Admin
|
||||
queries << base_query.where(id: tagged_product_ids)
|
||||
end
|
||||
|
||||
if has_none
|
||||
if has_none_tag
|
||||
# Products where no variants have any tags
|
||||
tagged_product_ids = Spree::Variant
|
||||
.joins(:taggings)
|
||||
@@ -333,6 +331,10 @@ module Admin
|
||||
t('.error')
|
||||
end
|
||||
end
|
||||
|
||||
def init_none_tag
|
||||
@none_tag_value = "without_any_tag"
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/ClassLength
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
- select_tag_options = { class: "fullwidth",
|
||||
multiple: true ,
|
||||
data: { controller: "tom-select", "tom-select-placeholder-value": t(".select_tag"), "tom-select-options-value": '{ "maxItems": 5 , "plugins": { "remove_button": {} , "no_active_items": {}, "checkbox_options": { "checkedClassNames": ["ts-checked"], "uncheckedClassNames": ["ts-unchecked"] } } }' } }
|
||||
= select_tag :tags_name_in, options_for_select(available_tags.unshift(t('.tags.none')), tags), select_tag_options
|
||||
= select_tag :tags_name_in, options_for_select(available_tags.unshift([t('.tags.none'), @none_tag_value]), tags), select_tag_options
|
||||
.submit
|
||||
.search-button
|
||||
= button_tag t(".search"), class: "secondary icon-search relaxed", name: nil
|
||||
|
||||
Reference in New Issue
Block a user