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
- #component_name ⇒ Object
-
#filter_elections_state_values ⇒ Object
Returns a TreeNode to be used in the list filters to filter elections by its state.
- #filter_sections ⇒ Object
- #question_title(question, tag = :h3, **options) ⇒ Object
- #render_question_description(question) ⇒ Object
- #search_variable ⇒ Object
- #selected_response_option_id(question) ⇒ Object
- #voted_by_current_user?(election) ⇒ Boolean
Instance Method Details
#component_name ⇒ Object
36 37 38 |
# File 'app/helpers/decidim/elections/application_helper.rb', line 36 def component_name (defined?(current_component) && translated_attribute(current_component&.name).presence) || t("decidim.components.elections.name") end |
#filter_elections_state_values ⇒ Object
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_sections ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/decidim/elections/application_helper.rb', line 20 def filter_sections @filter_sections ||= begin items = [{ method: :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, **options) ⇒ Object
40 41 42 43 44 |
# File 'app/helpers/decidim/elections/application_helper.rb', line 40 def question_title(question, tag = :h3, **) content_tag(tag, **) do translated_attribute(question.body) end end |
#render_question_description(question) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/decidim/elections/application_helper.rb', line 46 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_variable ⇒ Object
34 |
# File 'app/helpers/decidim/elections/application_helper.rb', line 34 def search_variable = :search_text_cont |
#selected_response_option_id(question) ⇒ Object
58 59 60 |
# File 'app/helpers/decidim/elections/application_helper.rb', line 58 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
62 63 64 65 |
# File 'app/helpers/decidim/elections/application_helper.rb', line 62 def voted_by_current_user?(election) voter_uid = session[:voter_uid] || election.census.voter_uid(election, {}, current_user:) election.votes.exists?(voter_uid:) end |