Module: Decidim::Elections::ApplicationHelper

Includes:
CheckBoxesTreeHelper, DateRangeHelper, PaginateHelper
Defined in:
app/helpers/decidim/elections/application_helper.rb

Overview

Custom helpers, scoped to the elections engine.

Instance Method Summary collapse

Instance Method Details

#component_nameObject



37
38
39
# File 'app/helpers/decidim/elections/application_helper.rb', line 37

def component_name
  (defined?(current_component) && translated_attribute(current_component&.name).presence) || t("decidim.components.elections.name")
end

#filter_elections_state_valuesObject

Returns a TreeNode to be used in the list filters to filter elections by its state.



14
15
16
17
18
# File 'app/helpers/decidim/elections/application_helper.rb', line 14

def filter_elections_state_values
  %w(scheduled ongoing finished).map { |k| [k, t(k, scope: "decidim.elections.elections.filters.state_values")] }.prepend(
    ["all", t("all", scope: "decidim.elections.elections.filters")]
  )
end

#filter_sectionsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/decidim/elections/application_helper.rb', line 20

def filter_sections
  @filter_sections ||= begin
    items = [{
      method: :with_any_state,
      name: "[with_any_state]",
      collection: filter_elections_state_values,
      label: t("decidim.elections.elections.filters.state"),
      id: "date",
      type: :radio_buttons
    }]

    items.reject { |item| item[:collection].blank? }
  end
end

#question_title(question, tag = :h3) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'app/helpers/decidim/elections/application_helper.rb', line 41

def question_title(question, tag = :h3, **)
  (tag, **) do
    title = translated_attribute(question.body)
    if question.max_choices.present? && question.question_type == "multiple_option"
      title += " (#{t("decidim.elections.votes.question.max_choices", count: question.max_choices)})"
    end
    title.html_safe
  end
end

#render_question_description(question) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/decidim/elections/application_helper.rb', line 51

def render_question_description(question)
  description = translated_attribute(question.description)
  return if description.blank?

  sanitized = decidim_sanitize_admin(description)
  if rich_text_editor_in_public_views?
    Decidim::ContentProcessor.render_without_format(sanitized).html_safe
  else
    Decidim::ContentProcessor.render(sanitized, "div")
  end
end

#search_variableObject



35
# File 'app/helpers/decidim/elections/application_helper.rb', line 35

def search_variable = :search_text_cont

#selected_response_option_id(question) ⇒ Object



63
64
65
# File 'app/helpers/decidim/elections/application_helper.rb', line 63

def selected_response_option_id(question)
  session.dig(:votes_buffer, question.id.to_s, "response_option_id")&.to_i
end

#voted_by_current_user?(election) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
# File 'app/helpers/decidim/elections/application_helper.rb', line 67

def voted_by_current_user?(election)
  voter_uid = session[:voter_uid] || election.census.voter_uid(election, {}, current_user:)
  election.votes.exists?(voter_uid:)
end