Class: Decidim::ParticipatoryProcessGroups::ProcessFiltersCell
- Inherits:
-
Decidim::ParticipatoryProcesses::ProcessFiltersCell
- Object
- ViewModel
- 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’s 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"
)
Constant Summary
Constants inherited from Decidim::ParticipatoryProcesses::ProcessFiltersCell
Decidim::ParticipatoryProcesses::ProcessFiltersCell::ALL_FILTERS
Instance Method Summary collapse
- #base_relation ⇒ Object
- #current_filter ⇒ Object
- #default_date_filter ⇒ Object
- #filter_link(date_filter, type_filter = nil) ⇒ Object
- #filtered_processes(date_filter, filter_with_type: true) ⇒ Object
- #process_count_by_filter ⇒ Object
Methods inherited from Decidim::ParticipatoryProcesses::ProcessFiltersCell
#current_type_filter_name, #explanation, #explanation_text, #filter_name, #filter_params, #filter_type_label, #get_filter, #other_filters, #other_filters_with_value, #participatory_process_types, #participatory_process_types_for_select, #should_show_tabs?, #title
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
70 71 72 |
# File 'app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 70 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, type_filter = nil) ⇒ 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, type_filter = nil) Decidim::ParticipatoryProcesses::Engine .routes .url_helpers .participatory_process_group_path(model, **filter_params(date_filter, type_filter)) end |
#filtered_processes(date_filter, filter_with_type: true) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 55 def filtered_processes(date_filter, filter_with_type: true) query = base_relation.ransack( { with_date: date_filter, with_scope: get_filter(:with_scope), with_area: get_filter(:with_area), with_type: filter_with_type ? get_filter(:with_type) : nil }, current_user: 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 |