Class: Decidim::Proposals::ProposalsPickerCell

Inherits:
ViewModel
  • Object
show all
Defined in:
decidim-proposals/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 'decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb', line 45

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

#filtered?Boolean

Returns:

  • (Boolean)

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

def filtered?
  !search_text.nil?
end

#filtered_proposalsObject


51
52
53
54
55
56
57
58
59
60
# File 'decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb', line 51

def filtered_proposals
  @filtered_proposals ||= if filtered?
                            table_name = Decidim::Proposals::Proposal.table_name
                            proposals.where(%("#{table_name}"."title"::text ILIKE ?), "%#{search_text}%")
                                     .or(proposals.where(%("#{table_name}"."reference" ILIKE ?), "%#{search_text}%"))
                                     .or(proposals.where(%("#{table_name}"."id"::text ILIKE ?), "%#{search_text}%"))
                          else
                            proposals
                          end
end

#more_proposals?Boolean

Returns:

  • (Boolean)

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

def more_proposals?
  @more_proposals ||= more_proposals_count.positive?
end

#more_proposals_countObject


37
38
39
# File 'decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb', line 37

def more_proposals_count
  @more_proposals_count ||= proposals_count - MAX_PROPOSALS
end

#picker_pathObject


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

def picker_path
  request.path
end

#proposalsObject


62
63
64
65
66
67
68
# File 'decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb', line 62

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

#proposals_collection_nameObject


70
71
72
# File 'decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb', line 70

def proposals_collection_name
  Decidim::Proposals::Proposal.model_name.human(count: 2)
end

#proposals_countObject


41
42
43
# File 'decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb', line 41

def proposals_count
  @proposals_count ||= filtered_proposals.count
end

#search_textObject


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

def search_text
  params[:q]
end

#showObject


11
12
13
14
15
16
17
# File 'decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb', line 11

def show
  if filtered?
    render :proposals
  else
    render
  end
end