Class: Decidim::HomepageProposals::ContentBlocks::ProposalsSliderCell

Inherits:
ViewModel
  • Object
show all
Includes:
ActionView::Helpers::FormOptionsHelper, Cell::ViewModel::Partial, ComponentPathHelper, FilterResource, FiltersHelper, IconHelper
Defined in:
app/cells/decidim/homepage_proposals/content_blocks/proposals_slider_cell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#glanced_proposalsObject

Returns the value of attribute glanced_proposals.



7
8
9
# File 'app/cells/decidim/homepage_proposals/content_blocks/proposals_slider_cell.rb', line 7

def glanced_proposals
  @glanced_proposals
end

Instance Method Details

#categories_filterObject



50
51
52
# File 'app/cells/decidim/homepage_proposals/content_blocks/proposals_slider_cell.rb', line 50

def categories_filter
  @categories_filter ||= Decidim::Category.where(id: linked_components.map(&:categories).flatten)
end

#content_block_settingsObject



23
24
25
26
27
28
# File 'app/cells/decidim/homepage_proposals/content_blocks/proposals_slider_cell.rb', line 23

def content_block_settings
  @content_block_settings ||= Decidim::ContentBlock.find_by(
    manifest_name: "proposals_slider",
    organization: current_organization
  ).settings
end

#default_filter_paramsObject



42
43
44
45
46
47
48
# File 'app/cells/decidim/homepage_proposals/content_blocks/proposals_slider_cell.rb', line 42

def default_filter_params
  {
    scope_id: nil,
    category_id: nil,
    component_id: nil
  }
end

#default_linked_component_pathObject



17
18
19
20
21
# File 'app/cells/decidim/homepage_proposals/content_blocks/proposals_slider_cell.rb', line 17

def default_linked_component_path
  main_component_path(Decidim::Component.find(selected_component_id))
rescue ActiveRecord::RecordNotFound
  root_path
end

#linked_componentsObject



38
39
40
# File 'app/cells/decidim/homepage_proposals/content_blocks/proposals_slider_cell.rb', line 38

def linked_components
  @linked_components ||= Decidim::Component.where(id: content_block_settings.linked_components_id.compact)
end

#options_for_default_componentObject



30
31
32
33
34
35
36
# File 'app/cells/decidim/homepage_proposals/content_blocks/proposals_slider_cell.rb', line 30

def options_for_default_component
  options = linked_components.map do |component|
    ["#{translated_attribute(component.name)} (#{translated_attribute(component.participatory_space.title)})", component.id]
  end

  options_for_select(options, selected: selected_component_id)
end

#selected_component_idObject



54
55
56
# File 'app/cells/decidim/homepage_proposals/content_blocks/proposals_slider_cell.rb', line 54

def selected_component_id
  @selected_component_id ||= params.dig(:filter, :component_id) || content_block_settings.default_linked_component
end