Class: Decidim::Votings::PollingOfficers::PollingOfficersPickerCell

Inherits:
Decidim::ViewModel
  • Object
show all
Defined in:
decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb

Overview

This cell renders a polling officers picker.

Constant Summary collapse

MAX_POLLING_OFFICERS =
1000

Instance Method Summary collapse

Methods inherited from Decidim::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_polling_officersObject


44
45
46
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 44

def decorated_polling_officers
  filtered_polling_officers.limit(MAX_POLLING_OFFICERS)
end

#filtered?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 20

def filtered?
  !search_text.nil?
end

#filtered_polling_officersObject


48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 48

def filtered_polling_officers
  @filtered_polling_officers ||= if filtered?
                                   query = polling_officers.joins(:user)
                                   if search_text.start_with?("@")
                                     query.where("nickname ILIKE ?", "#{search_text.delete("@")}%")
                                   else
                                     query.where("name ILIKE ?", "%#{search_text}%").or(
                                       query.where("email ILIKE ?", "%#{search_text}%")
                                     )
                                   end
                                 else
                                   polling_officers
                                 end
end

#more_polling_officers?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 32

def more_polling_officers?
  @more_polling_officers ||= more_polling_officers_count.positive?
end

#more_polling_officers_countObject


36
37
38
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 36

def more_polling_officers_count
  @more_polling_officers_count ||= polling_officers_count - MAX_POLLING_OFFICERS
end

#picker_pathObject


24
25
26
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 24

def picker_path
  request.path
end

#polling_officersObject


63
64
65
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 63

def polling_officers
  @polling_officers ||= model.available_polling_officers
end

#polling_officers_collection_nameObject


67
68
69
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 67

def polling_officers_collection_name
  Decidim::Votings::PollingOfficer.model_name.human(count: 2)
end

#polling_officers_countObject


40
41
42
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 40

def polling_officers_count
  @polling_officers_count ||= filtered_polling_officers.count
end

#search_textObject


28
29
30
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 28

def search_text
  params[:q]
end

#showObject


12
13
14
15
16
# File 'decidim-elections/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb', line 12

def show
  return render :polling_officers if filtered?

  render
end