Class: Decidim::Proposals::ProposalsPickerCell

Inherits:
ViewModel
  • Object
show all
Defined in:
app/cells/decidim/proposals/proposals_picker_cell.rb

Overview

This cell renders a proposals picker.

Constant Summary collapse

MAX_PROPOSALS =
1000

Instance Method Summary collapse

Instance Method Details

#decorated_proposalsObject



45
46
47
48
49
# File 'app/cells/decidim/proposals/proposals_picker_cell.rb', line 45

def decorated_proposals
  proposals.limit(MAX_PROPOSALS).each do |proposal|
    yield Decidim::Proposals::ProposalPresenter.new(proposal)
  end
end

#fieldObject



21
22
23
# File 'app/cells/decidim/proposals/proposals_picker_cell.rb', line 21

def field
  options[:field]
end

#formObject



17
18
19
# File 'app/cells/decidim/proposals/proposals_picker_cell.rb', line 17

def form
  options[:form]
end

#form_nameObject



25
26
27
# File 'app/cells/decidim/proposals/proposals_picker_cell.rb', line 25

def form_name
  "#{form.object_name}[#{method_name}]"
end

#method_nameObject



29
30
31
# File 'app/cells/decidim/proposals/proposals_picker_cell.rb', line 29

def method_name
  field.to_s.sub(/s$/, "_ids")
end

#proposalsObject



37
38
39
40
41
42
43
# File 'app/cells/decidim/proposals/proposals_picker_cell.rb', line 37

def proposals
  @proposals ||= Decidim.find_resource_manifest(:proposals).try(:resource_scope, component)
                   &.includes(:component)
                   &.published
                   &.not_hidden
                   &.order(id: :asc)
end

#selected_idsObject



33
34
35
# File 'app/cells/decidim/proposals/proposals_picker_cell.rb', line 33

def selected_ids
  form.object.send(method_name)
end

#showObject



11
12
13
# File 'app/cells/decidim/proposals/proposals_picker_cell.rb', line 11

def show
  render
end