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'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

Methods inherited from Decidim::ParticipatoryProcesses::ProcessFiltersCell

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

Methods inherited from ViewModel

#call, #current_user

Methods included from FilterParamsHelper

#filter_link_params

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 ScopesHelper

#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_picker_tag

Methods included from TranslatableAttributes

#default_locale?

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

Methods included from ResourceHelper

#linked_classes_filter_values_for, #linked_classes_for, #linked_resources_for, #resource_locator, #resource_title

Instance Method Details

#base_relationObject


46
47
48
49
50
51
# File 'decidim-participatory_processes/app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 46

def base_relation
  @base_relation ||= options[:base_relation].presence || Decidim::ParticipatoryProcesses::GroupPublishedParticipatoryProcesses.new(
    model,
    current_user
  ).query
end

#current_filterObject


42
43
44
# File 'decidim-participatory_processes/app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 42

def current_filter
  get_filter(:date, default_date_filter)
end

#default_date_filterObject


73
74
75
# File 'decidim-participatory_processes/app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 73

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
34
35
36
37
38
39
40
# File 'decidim-participatory_processes/app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 28

def filter_link(filter)
  Decidim::ParticipatoryProcesses::Engine
    .routes
    .url_helpers
    .participatory_process_group_path(
      model,
      filter: {
        scope_id: get_filter(:scope_id),
        area_id: get_filter(:area_id),
        date: filter
      }
    )
end

#filtered_processes(date_filter) ⇒ Object


62
63
64
65
66
67
68
69
70
71
# File 'decidim-participatory_processes/app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 62

def filtered_processes(date_filter)
  Decidim::ParticipatoryProcesses::ParticipatoryProcessSearch.new(
    base_relation: base_relation,
    date: date_filter,
    scope_id: get_filter(:scope_id),
    area_id: get_filter(:area_id),
    current_user: current_user,
    organization: current_organization
  )
end

#process_count_by_filterObject


53
54
55
56
57
58
59
60
# File 'decidim-participatory_processes/app/cells/decidim/participatory_process_groups/process_filters_cell.rb', line 53

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).results.count)
    end
    counts.update("all" => counts.values.sum)
  end
end