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

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

#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
# File 'decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb', line 51

def filtered_proposals
  @filtered_proposals ||= if filtered?
                            proposals.where("title::text ILIKE ?", "%#{search_text}%")
                                     .or(proposals.where("reference ILIKE ?", "%#{search_text}%"))
                                     .or(proposals.where("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


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

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

#proposals_collection_nameObject


67
68
69
# File 'decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb', line 67

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