Module: Decidim::Proposals::ApplicationHelper
- Includes:
- CheckBoxesTreeHelper, Comments::CommentsHelper, EndorsableHelper, FollowableHelper, MapHelper, Decidim::PaginateHelper, CollaborativeDraftHelper, ControlVersionHelper, MapHelper, ProposalVotesHelper, RichTextEditorHelper
- Included in:
- CollaborativeDraftCellsHelper, CollaborativeDraftMetadataCell, ProposalCellsHelper, ProposalGCell, ProposalHistoryCell, ProposalMetadataCell
- Defined in:
- decidim-proposals/app/helpers/decidim/proposals/application_helper.rb
Overview
Custom helpers, scoped to the proposals engine.
Constant Summary
Constants included from AmendmentsHelper
Instance Method Summary collapse
-
#activity_filter_values ⇒ Object
Options to filter Proposals by activity.
-
#collaborative_draft_state_badge_css_class(state) ⇒ Object
Public: The css class applied based on the collaborative draft state.
- #component_name ⇒ Object
-
#filter_origin_values ⇒ Object
Explicitly commenting the used I18n keys so their are not flagged as unused i18n-tasks-use t(‘decidim.proposals.application_helper.filter_origin_values.official’) i18n-tasks-use t(‘decidim.proposals.application_helper.filter_origin_values.participants’) i18n-tasks-use t(‘decidim.proposals.application_helper.filter_origin_values.official’) i18n-tasks-use t(‘decidim.proposals.application_helper.filter_origin_values.meetings’) i18n-tasks-use t(‘decidim.proposals.application_helper.filter_origin_values.all’).
- #filter_proposals_state_values ⇒ Object
-
#filter_sections ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #filter_type_values ⇒ Object
-
#humanize_collaborative_draft_state(state) ⇒ Object
Public: The state of a proposal in a way a human can understand.
-
#humanize_proposal_state(state) ⇒ Object
Public: The state of a proposal in a way a human can understand.
- #layout_item_classes ⇒ Object
- #not_from_collaborative_draft(proposal) ⇒ Object
- #not_from_participatory_text(proposal) ⇒ Object
- #proposal_limit ⇒ Object
- #proposal_limit_enabled? ⇒ Boolean
-
#proposal_state_css_class(proposal) ⇒ Object
Public: The css class applied based on the proposal state.
- #proposal_state_css_style(proposal) ⇒ Object
-
#render_proposal_body(proposal) ⇒ Object
If the content is safe, HTML tags are sanitized, otherwise, they are stripped.
-
#safe_content? ⇒ Boolean
If the proposal is official or the rich text editor is enabled on the frontend, the proposal body is considered as safe content; that is unless the proposal comes from a collaborative_draft or a participatory_text.
-
#safe_content_admin? ⇒ Boolean
For admin entered content, the proposal body can contain certain extra tags, such as iframes.
- #show_voting_rules? ⇒ Boolean
- #templates_available? ⇒ Boolean
-
#text_editor_for_proposal_body(form) ⇒ Object
Returns :text_area or :editor based on the organization’ settings.
Methods included from CheckBoxesTreeHelper
#check_boxes_tree_options, #filter_areas_values, #filter_global_scopes_values, #filter_taxonomy_values_children, #filter_taxonomy_values_for, #filter_text_for, #filter_tree_from_array, #flat_filter_values
Methods included from SanitizeHelper
#decidim_escape_translated, #decidim_html_escape, #decidim_rich_text, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included
Methods included from RichTextEditorHelper
Methods included from ControlVersionHelper
Methods included from CollaborativeDraftHelper
#accept_request_button_label, #collaborative_drafts_filter_sections, #collaborative_drafts_state_class, #filter_collaborative_drafts_state_values, #reject_request_button_label
Methods included from MapHelper
#has_position?, #proposal_preview_data_for_map
Methods included from ApplicationHelper
#add_body_classes, #cell, #edit_link, #extra_admin_link, #html_truncate, #present, #prevent_timeout_seconds, #resolve_presenter_class, #text_initials
Methods included from CacheHelper
Methods included from AmendmentsHelper
#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amendments_enabled?, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #current_step, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body, #total_steps, #wizard_aside_back_url, #wizard_header_title
Methods included from ContextualHelpHelper
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, #tab_element_class_for, #translated_field_tag
Methods included from OmniauthHelper
#normalize_provider_name, #oauth_icon, #provider_name
Methods included from MapHelper
#dynamic_map_for, #static_map_link
Methods included from FollowableHelper
Methods included from EndorsableHelper
#current_user_can_endorse?, #endorsements_blocked?, #endorsements_enabled?, #path_to_create_endorsement, #path_to_destroy_endorsement, #show_endorsements_card?
Methods included from ProposalVotesHelper
#can_accumulate_votes_beyond_threshold?, #current_user_can_vote?, #minimum_votes_per_user_enabled?, #proposal_voted_by_user?, #remaining_minimum_votes_count_for_user, #remaining_votes_count_for_user, #threshold_per_proposal, #threshold_per_proposal_enabled?, #vote_limit_enabled?, #votes_blocked?, #votes_enabled?
Methods included from Decidim::PaginateHelper
Methods included from Comments::CommentsHelper
#comments_for, #inline_comments_for
Instance Method Details
#activity_filter_values ⇒ Object
Options to filter Proposals by activity.
162 163 164 165 166 167 168 169 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 162 def activity_filter_values base = [ ["all", t("decidim.proposals.proposals.filters.all")], ["my_proposals", t("decidim.proposals.proposals.filters.my_proposals")] ] base += [["voted", t("decidim.proposals.proposals.filters.voted")]] if current_settings.votes_enabled? base end |
#collaborative_draft_state_badge_css_class(state) ⇒ Object
Public: The css class applied based on the collaborative draft state.
state - The String state of the collaborative draft.
Returns a String.
71 72 73 74 75 76 77 78 79 80 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 71 def collaborative_draft_state_badge_css_class(state) case state when "open" "success" when "withdrawn" "alert" when "published" "secondary" end end |
#component_name ⇒ Object
238 239 240 241 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 238 def component_name i18n_key = controller_name == "collaborative_drafts" ? "decidim.proposals.collaborative_drafts.name" : "decidim.components.proposals.name" (defined?(current_component) && translated_attribute(current_component&.name).presence) || t(i18n_key) end |
#filter_origin_values ⇒ Object
Explicitly commenting the used I18n keys so their are not flagged as unused i18n-tasks-use t(‘decidim.proposals.application_helper.filter_origin_values.official’) i18n-tasks-use t(‘decidim.proposals.application_helper.filter_origin_values.participants’) i18n-tasks-use t(‘decidim.proposals.application_helper.filter_origin_values.official’) i18n-tasks-use t(‘decidim.proposals.application_helper.filter_origin_values.meetings’) i18n-tasks-use t(‘decidim.proposals.application_helper.filter_origin_values.all’)
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 177 def filter_origin_values scope = "decidim.proposals.application_helper.filter_origin_values" origin_values = [] origin_values << TreePoint.new("official", t("official", scope:)) if component_settings.official_proposals_enabled origin_values << TreePoint.new("participants", t("participants", scope:)) origin_values << TreePoint.new("meeting", t("meetings", scope:)) TreeNode.new( TreePoint.new("", t("all", scope:)), origin_values ) end |
#filter_proposals_state_values ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 190 def filter_proposals_state_values Decidim::CheckBoxesTreeHelper::TreeNode.new( Decidim::CheckBoxesTreeHelper::TreePoint.new("", t("decidim.proposals.application_helper.filter_state_values.all")), [ Decidim::CheckBoxesTreeHelper::TreePoint.new("state_not_published", t("decidim.proposals.application_helper.filter_state_values.not_answered")) ] + Decidim::Proposals::ProposalState.where(component: current_component).where.not(token: "not_answered").map do |state| Decidim::CheckBoxesTreeHelper::TreePoint.new(state.token, translated_attribute(state.title)) end ) end |
#filter_sections ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 203 def filter_sections @filter_sections ||= begin items = [] if component_settings.proposal_answering_enabled && current_settings.proposal_answering_enabled items.append(method: :with_any_state, collection: filter_proposals_state_values, label: t("decidim.proposals.proposals.filters.state"), id: "state") end current_component.available_taxonomy_filters.each do |taxonomy_filter| items.append(method: "with_any_taxonomies[#{taxonomy_filter.root_taxonomy_id}]", collection: filter_taxonomy_values_for(taxonomy_filter), label: decidim_sanitize_translated(taxonomy_filter.name), id: "taxonomy-#{taxonomy_filter.root_taxonomy_id}") end if component_settings.official_proposals_enabled items.append(method: :with_any_origin, collection: filter_origin_values, label: t("decidim.proposals.proposals.filters.origin"), id: "origin") end if current_user items.append(method: :activity, collection: activity_filter_values, label: t("decidim.proposals.proposals.filters.activity"), id: "activity", type: :radio_buttons) end if @proposals.only_emendations.any? items.append(method: :type, collection: filter_type_values, label: t("decidim.proposals.proposals.filters.amendment_type"), id: "amendment_type", type: :radio_buttons) end if linked_classes_for(Decidim::Proposals::Proposal).any? items.append( method: :related_to, collection: linked_classes_filter_values_for(Decidim::Proposals::Proposal), label: t("decidim.proposals.proposals.filters.related_to"), id: "related_to", type: :radio_buttons ) end end # rubocop:enable Metrics/CyclomaticComplexity items.reject { |item| item[:collection].blank? } end |
#filter_type_values ⇒ Object
153 154 155 156 157 158 159 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 153 def filter_type_values [ ["all", t("decidim.proposals.application_helper.filter_type_values.all")], ["proposals", t("decidim.proposals.application_helper.filter_type_values.proposals")], ["amendments", t("decidim.proposals.application_helper.filter_type_values.amendments")] ] end |
#humanize_collaborative_draft_state(state) ⇒ Object
Public: The state of a proposal in a way a human can understand.
state - The String state of the proposal.
Returns a String.
62 63 64 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 62 def humanize_collaborative_draft_state(state) I18n.t("decidim.proposals.collaborative_drafts.states.#{state}", default: :open) end |
#humanize_proposal_state(state) ⇒ Object
Public: The state of a proposal in a way a human can understand.
state - The String state of the proposal.
Returns a String.
25 26 27 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 25 def humanize_proposal_state(state) I18n.t(state, scope: "decidim.proposals.answers", default: :not_answered) end |
#layout_item_classes ⇒ Object
135 136 137 138 139 140 141 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 135 def layout_item_classes if show_voting_rules? "layout-item lg:pt-4" else "layout-item" end end |
#not_from_collaborative_draft(proposal) ⇒ Object
86 87 88 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 86 def not_from_collaborative_draft(proposal) proposal.linked_resources(:proposals, "created_from_collaborative_draft").empty? end |
#not_from_participatory_text(proposal) ⇒ Object
90 91 92 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 90 def not_from_participatory_text(proposal) proposal.participatory_text_level.nil? end |
#proposal_limit ⇒ Object
129 130 131 132 133 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 129 def proposal_limit return if component_settings.proposal_limit.zero? component_settings.proposal_limit end |
#proposal_limit_enabled? ⇒ Boolean
82 83 84 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 82 def proposal_limit_enabled? proposal_limit.present? end |
#proposal_state_css_class(proposal) ⇒ Object
Public: The css class applied based on the proposal state.
proposal - The proposal to evaluate.
Returns a String.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 41 def proposal_state_css_class(proposal) return "alert" if proposal.withdrawn? return if proposal.state.blank? case proposal.state when "accepted" "success" when "rejected", "withdrawn" "alert" when "evaluating" "warning" else "info" end end |
#proposal_state_css_style(proposal) ⇒ Object
29 30 31 32 33 34 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 29 def proposal_state_css_style(proposal) return "" if proposal.emendation? return "" if proposal.withdrawn? proposal.proposal_state&.css_style end |
#render_proposal_body(proposal) ⇒ Object
If the content is safe, HTML tags are sanitized, otherwise, they are stripped.
109 110 111 112 113 114 115 116 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 109 def render_proposal_body(proposal) sanitized = render_sanitized_content(proposal, :body) if safe_content? Decidim::ContentProcessor.render_without_format(sanitized).html_safe else Decidim::ContentProcessor.render(sanitized) end end |
#safe_content? ⇒ Boolean
If the proposal is official or the rich text editor is enabled on the frontend, the proposal body is considered as safe content; that is unless the proposal comes from a collaborative_draft or a participatory_text.
97 98 99 100 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 97 def safe_content? (rich_text_editor_in_public_views? && not_from_collaborative_draft(@proposal)) || safe_content_admin? end |
#safe_content_admin? ⇒ Boolean
For admin entered content, the proposal body can contain certain extra tags, such as iframes.
104 105 106 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 104 def safe_content_admin? (@proposal.official? || @proposal.official_meeting?) && not_from_participatory_text(@proposal) end |
#show_voting_rules? ⇒ Boolean
143 144 145 146 147 148 149 150 151 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 143 def show_voting_rules? return false if !votes_enabled? || votes_blocked? return true if vote_limit_enabled? return true if threshold_per_proposal_enabled? return true if proposal_limit_enabled? return true if can_accumulate_votes_beyond_threshold? return true if minimum_votes_per_user_enabled? end |
#templates_available? ⇒ Boolean
243 244 245 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 243 def templates_available? Decidim.module_installed?(:templates) && defined?(Decidim::Templates::Template) && Decidim::Templates::Template.exists?(templatable: current_component) end |
#text_editor_for_proposal_body(form) ⇒ Object
Returns :text_area or :editor based on the organization’ settings.
119 120 121 122 123 124 125 126 127 |
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 119 def text_editor_for_proposal_body(form) = { class: "js-hashtags", hashtaggable: true, value: form_presenter.body(extras: false, strip_tags: !current_organization.rich_text_editor_in_public_views).strip } text_editor_for(form, :body, ) end |