Class: Decidim::ParticipatoryProcessGroups::ProcessFiltersCell

Inherits:
Decidim::ParticipatoryProcesses::ProcessFiltersCell show all
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

Constants included from AmendmentsHelper

AmendmentsHelper::TOTAL_STEPS

Instance Method Summary collapse

Methods inherited from Decidim::ParticipatoryProcesses::ProcessFiltersCell

#explanation, #explanation_text, #filter_name, #filter_params, #get_filter, #get_filter_in, #other_filters, #other_filters_with_value, #should_show_tabs?, #title

Methods inherited from ViewModel

#call, #current_user, #view_context

Methods included from IconHelper

#component_icon, #manifest_icon, #resource_icon, #resource_type_icon, #resource_type_icon_key, #text_with_resource_icon

Methods included from LayoutHelper

#_icon_classes, #apple_favicon, #application_path, #current_url, #current_user_unread_data, #external_icon, #favicon, #icon, #legacy_favicon, #role, #root_url

Methods included from TooltipHelper

#with_tooltip

Methods included from ModalHelper

#decidim_drawer, #decidim_modal

Methods included from OrganizationHelper

#current_organization_name, #organization_colors, #organization_description_label, #organization_name

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Methods included from ApplicationHelper

#add_body_classes, #cell, #edit_link, #extra_admin_link, #html_truncate, #layout_item_classes, #present, #prevent_timeout_seconds, #resolve_presenter_class, #text_initials

Methods included from CacheHelper

#cache

Methods included from AmendmentsHelper

#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amendments_enabled?, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #current_step, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body, #total_steps, #wizard_aside_back_url, #wizard_header_title

Methods included from RichTextEditorHelper

included, #text_editor_for

Methods included from ContextualHelpHelper

#floating_help

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, #tab_element_class_for, #translated_field_tag

Methods included from OmniauthHelper

#normalize_provider_name, #oauth_icon, #provider_name

Methods included from SanitizeHelper

#decidim_escape_translated, #decidim_html_escape, #decidim_rich_text, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included

Methods included from MarkupHelper

#element_id

Methods included from ReplaceButtonsHelper

#button_to, #submit_tag

Methods included from ActionAuthorizationHelper

#action_authorized_button_to, #action_authorized_link_to, #logged_button_to, #logged_link_to

Methods included from ResourceHelper

#linked_classes_filter_values_for, #linked_classes_for, #resource_locator

Instance Method Details

#base_relationObject



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 ||= options[:base_relation].presence || Decidim::ParticipatoryProcesses::GroupPublishedParticipatoryProcesses.new(
    model,
    current_user
  ).query
end

#current_filterObject



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_filterObject



69
70
71
# File 'decidim-participatory_processes/app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 69

def default_date_filter
  @default_date_filter ||= options[:default_filter].presence || process_count_by_filter.find { |_, count| count.positive? }&.first || "all"
end


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)
  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 'decidim-participatory_processes/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_filterObject



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