Module: Decidim::Assemblies::FilterAssembliesHelper

Included in:
AssembliesHelper
Defined in:
app/helpers/decidim/assemblies/filter_assemblies_helper.rb

Overview

Helpers related to the Assemblies filter by type.

‘filter` returns a Filter object from Decidim::FilterResource

Instance Method Summary collapse

Instance Method Details

#available_filtersObject



9
10
11
12
13
# File 'app/helpers/decidim/assemblies/filter_assemblies_helper.rb', line 9

def available_filters
  return if organization_assembly_types.blank?

  [t("all", scope: "decidim.assemblies.filter")] + organization_assembly_types
end

#current_filter_nameObject



32
33
34
35
36
37
# File 'app/helpers/decidim/assemblies/filter_assemblies_helper.rb', line 32

def current_filter_name
  type = AssembliesType.find_by(id: filter_params[:type_id_eq])
  return translated_attribute type.title if type

  t("all", scope: "decidim.assemblies.filter")
end


15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/decidim/assemblies/filter_assemblies_helper.rb', line 15

def filter_link(type_id)
  Decidim::Assemblies::Engine
    .routes
    .url_helpers
    .assemblies_path(
      filter: {
        with_scope: filter.with_scope,
        with_area: filter.with_area,
        type_id_eq: type_id
      }
    )
end

#help_textObject



28
29
30
# File 'app/helpers/decidim/assemblies/filter_assemblies_helper.rb', line 28

def help_text
  t("help", scope: "decidim.assemblies.filter")
end

#organization_assembly_typesObject



39
40
41
42
43
# File 'app/helpers/decidim/assemblies/filter_assemblies_helper.rb', line 39

def organization_assembly_types
  @organization_assembly_types ||= AssembliesType.where(organization: current_organization).joins(:assemblies).where(
    decidim_assemblies: { id: search.result.unscope(where: :decidim_assemblies_type_id).parent_assemblies }
  ).distinct&.map { |type| [translated_attribute(type.title), type.id] }
end