Class: SnFilterable::FilterCategoryComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- SnFilterable::FilterCategoryComponent
- Includes:
- FilteredHelper
- Defined in:
- app/components/sn_filterable/filter_category_component.rb
Overview
Component for a filter’s category for the filters sidebar
Instance Method Summary collapse
-
#initialize(filtered:, filter:) ⇒ FilterCategoryComponent
constructor
A new instance of FilterCategoryComponent.
-
#sub_filter_checked?(sub_filter) ⇒ Boolean
Returns if this sub filter should be checked, denoting that the filter is active.
Methods included from FilteredHelper
#add_filter_url, #clear_all_url, #clear_filter_url, #clear_sort_url, #filtered_form_inputs, #filtered_form_with, #filtered_paginate, #remove_filter_url, #remove_sub_filter_url, #set_filter_url, #sort_url, #table_header_sort_link
Constructor Details
#initialize(filtered:, filter:) ⇒ FilterCategoryComponent
Returns a new instance of FilterCategoryComponent.
9 10 11 12 |
# File 'app/components/sn_filterable/filter_category_component.rb', line 9 def initialize(filtered:, filter:) @filtered = filtered @filter = filter end |
Instance Method Details
#sub_filter_checked?(sub_filter) ⇒ Boolean
Returns if this sub filter should be checked, denoting that the filter is active
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/components/sn_filterable/filter_category_component.rb', line 18 def sub_filter_checked?(sub_filter) filter_query_value = @filtered.queries.dig("filter", @filter[:filter_name]) return false if filter_query_value.blank? if filter_query_value.is_a?(Array) filter_query_value.include?((sub_filter[:value]).to_s) else filter_query_value == (sub_filter[:value]).to_s end end |