Class: Decidim::ParticipatoryProcessGroups::ProcessFiltersCell
- Inherits:
-
Decidim::ParticipatoryProcesses::ProcessFiltersCell
- Object
- Cell::ViewModel
- ViewModel
- Decidim::ParticipatoryProcesses::ProcessFiltersCell
- Decidim::ParticipatoryProcessGroups::ProcessFiltersCell
- Defined in:
- decidim-participatory_processes/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"
)
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, #get_filter_in, #other_filters, #other_filters_with_value, #participatory_process_types, #participatory_process_types_for_select, #should_show_tabs?, #title
Methods inherited from ViewModel
#call, #current_user, #view_context
Methods included from LayoutHelper
#_icon_classes, #apple_favicon, #application_path, #current_user_unread_data, #extended_navigation_bar, #external_icon, #favicon, #icon, #legacy_favicon, #organization_colors, #role
Methods included from TooltipHelper
Methods included from ModalHelper
Methods included from MarkupHelper
Methods included from ReplaceButtonsHelper
Methods included from ActionAuthorizationHelper
#action_authorized_button_to, #action_authorized_link_to, #logged_button_to, #logged_link_to
Methods included from ScopesHelper
#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_select_field, #scopes_select_tag
Methods included from TranslatableAttributes
Methods included from DecidimFormHelper
#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #ordered_scopes_descendants, #ordered_scopes_descendants_for_select, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag
Methods included from ResourceHelper
#linked_classes_filter_values_for, #linked_classes_for, #resource_locator, #resource_title
Instance Method Details
#base_relation ⇒ Object
39 40 41 42 43 44 |
# File 'decidim-participatory_processes/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 'decidim-participatory_processes/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 'decidim-participatory_processes/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 'decidim-participatory_processes/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 'decidim-participatory_processes/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_any_scope: get_filter(:with_any_scope), with_any_area: get_filter(:with_any_area), with_any_type: filter_with_type ? get_filter(:with_any_type) : nil }, 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 'decidim-participatory_processes/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 |