Class: Decidim::ParticipatoryProcessGroups::ProcessFiltersCell
- Inherits:
-
Decidim::ParticipatoryProcesses::ProcessFiltersCell
- Object
- Decidim::ParticipatoryProcesses::ProcessFiltersCell
- Decidim::ParticipatoryProcessGroups::ProcessFiltersCell
- Defined in:
- app/cells/decidim/participatory_process_groups/process_filters_cell.rb
Overview
This cell renders the filter tabs of participatory processes in a group. It is inherited from ProcessFiltersCell of participatory processes index but is based in the group processes
The model must be a Decidim::ParticipatoryProcessGroup`
Available options:
:base_relation=> A relation of participatory processes. If not provided is based on the model processes using GroupPublishedParticipatoryProcesses query.default_date_filter=> The date filter to use if not given by params. If not provided is inferred from the base relation
Example:
cell( "decidim/participatory_process_groups/process_filters", group, base_relation: group.participatory_processes.published, date_filter: "active" )
Instance Method Summary collapse
- #base_relation ⇒ Object
- #current_filter ⇒ Object
- #default_date_filter ⇒ Object
- #filter_link(date_filter) ⇒ Object
- #filtered_processes(date_filter) ⇒ Object
- #process_count_by_filter ⇒ Object
Instance Method Details
#base_relation ⇒ Object
39 40 41 42 43 44 |
# File 'app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 39 def base_relation @base_relation ||= [:base_relation].presence || Decidim::ParticipatoryProcesses::GroupPublishedParticipatoryProcesses.new( model, current_user ).query end |
#current_filter ⇒ Object
35 36 37 |
# File 'app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 35 def current_filter get_filter(:with_date, default_date_filter) end |
#default_date_filter ⇒ Object
69 70 71 |
# File 'app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 69 def default_date_filter @default_date_filter ||= [:default_filter].presence || process_count_by_filter.find { |_, count| count.positive? }&.first || "all" end |
#filter_link(date_filter) ⇒ Object
28 29 30 31 32 33 |
# File 'app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 28 def filter_link(date_filter) Decidim::ParticipatoryProcesses::Engine .routes .url_helpers .participatory_process_group_path(model, **filter_params(date_filter)) end |
#filtered_processes(date_filter) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 55 def filtered_processes(date_filter) query = base_relation.ransack( { with_date: date_filter, with_any_scope: get_filter(:with_any_scope), with_any_area: get_filter(:with_any_area) }, current_user:, organization: current_organization ).result query.published.visible_for(current_user) end |
#process_count_by_filter ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 46 def process_count_by_filter @process_count_by_filter ||= begin counts = ALL_FILTERS.without("all").each_with_object({}) do |filter_name, collection_by_filter| collection_by_filter.update(filter_name => filtered_processes(filter_name).count) end counts.update("all" => counts.values.sum) end end |