Class: Decidim::TaxonomyFilter
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::TaxonomyFilter
- Includes:
- Traceable, TranslatableResource
- Defined in:
- app/models/decidim/taxonomy_filter.rb
Overview
Represents the association between a taxonomy and a filterable entity within the system.
Class Method Summary collapse
-
.log_presenter_class_for(_log) ⇒ Object
Returns the presenter class for this log.
Instance Method Summary collapse
-
#components ⇒ Object
Components that have this taxonomy filter enabled.
- #filter_taxonomy_ids ⇒ Object
-
#internal_name ⇒ Object
Internal name for this filter, defaults to the root taxonomy name.
-
#name ⇒ Object
Public name for this filter, defaults to the root taxonomy name.
- #presenter ⇒ Object
- #reset_all_counters ⇒ Object
-
#taxonomies ⇒ Object
that respects the order given by the taxonomies table.
- #update_components_count ⇒ Object
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
Returns the presenter class for this log.
log - A Decidim::Log instance.
Returns a Decidim::AdminLog::TaxonomyFilterPresenter class
41 42 43 |
# File 'app/models/decidim/taxonomy_filter.rb', line 41 def self.log_presenter_class_for(_log) Decidim::AdminLog::TaxonomyFilterPresenter end |
Instance Method Details
#components ⇒ Object
Components that have this taxonomy filter enabled.
60 61 62 |
# File 'app/models/decidim/taxonomy_filter.rb', line 60 def components @components ||= Decidim::Component.where("(settings->'global'->'taxonomy_filters') @> ?", "\"#{id}\"") end |
#filter_taxonomy_ids ⇒ Object
64 65 66 |
# File 'app/models/decidim/taxonomy_filter.rb', line 64 def filter_taxonomy_ids @filter_taxonomy_ids ||= filter_items.map(&:taxonomy_item_id) end |
#internal_name ⇒ Object
Internal name for this filter, defaults to the root taxonomy name.
53 54 55 56 57 |
# File 'app/models/decidim/taxonomy_filter.rb', line 53 def internal_name return root_taxonomy&.name if super&.compact_blank.blank? super end |
#name ⇒ Object
Public name for this filter, defaults to the root taxonomy name.
46 47 48 49 50 |
# File 'app/models/decidim/taxonomy_filter.rb', line 46 def name return root_taxonomy&.name if super&.compact_blank.blank? super end |
#presenter ⇒ Object
32 33 34 |
# File 'app/models/decidim/taxonomy_filter.rb', line 32 def presenter Decidim::TaxonomyFilterPresenter.new(self) end |
#reset_all_counters ⇒ Object
95 96 97 98 |
# File 'app/models/decidim/taxonomy_filter.rb', line 95 def reset_all_counters Decidim::TaxonomyFilter.reset_counters(id, :filter_items_count) update_components_count end |
#taxonomies ⇒ Object
that respects the order given by the taxonomies table. The returned hash structure is:
_object_id_ => {
taxonomy: _object_,
children: {
_sub_object_id_: {
taxonomy: _sub_object_,
children: {
...
82 83 84 85 86 87 88 89 |
# File 'app/models/decidim/taxonomy_filter.rb', line 82 def taxonomies @taxonomies ||= root_taxonomy .all_children .where(id: filter_taxonomy_ids) .each_with_object({}) do |taxonomy, tree| insert_child(taxonomy, tree) end end |
#update_components_count ⇒ Object
91 92 93 |
# File 'app/models/decidim/taxonomy_filter.rb', line 91 def update_components_count update(components_count: components.count) end |