Module: Decidim::Proposals::ApplicationHelper

Includes:
Comments::CommentsHelper, MapHelper, CollaborativeDraftHelper, ControlVersionHelper, MapHelper, ProposalEndorsementsHelper, ProposalVotesHelper, PaginateHelper
Included in:
CollaborativeDraftCellsHelper, ProposalCellsHelper
Defined in:
app/helpers/decidim/proposals/application_helper.rb

Overview

Custom helpers, scoped to the proposals engine.

Instance Method Summary collapse

Methods included from ControlVersionHelper

#back_to_resource_path, #back_to_resource_path_text, #proposal?, #resource_all_versions_path, #resource_version_path, #versions_controller?

Methods included from CollaborativeDraftHelper

#accept_request_button_label, #collaborative_drafts_states_collection, #reject_request_button_label

Methods included from MapHelper

#proposals_data_for_map

Methods included from ProposalEndorsementsHelper

#current_user_can_endorse?, #endorsement_button, #endorsement_button_classes, #endorsement_identity_presenter, #endorsements_blocked?, #endorsements_enabled?, #fully_endorsed?, #render_endorsement_identity, #render_endorsements_button_card_part, #render_endorsements_count_card_part, #show_endorsements_card?

Methods included from ProposalVotesHelper

#can_accumulate_supports_beyond_threshold?, #current_user_can_vote?, #remaining_votes_count_for, #threshold_per_proposal, #threshold_per_proposal_enabled?, #vote_button_classes, #vote_limit, #vote_limit_enabled?, #votes_blocked?, #votes_count_classes, #votes_enabled?

Instance Method Details

#authors_for(collaborative_draft) ⇒ Object



114
115
116
# File 'app/helpers/decidim/proposals/application_helper.rb', line 114

def authors_for(collaborative_draft)
  collaborative_draft.identities.map { |identity| present(identity) }
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.



62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/decidim/proposals/application_helper.rb', line 62

def collaborative_draft_state_badge_css_class(state)
  case state
  when "open"
    "success"
  when "withdrawn"
    "alert"
  when "published"
    "secondary"
  end
end

#endorsers_for(proposal) ⇒ Object



106
107
108
# File 'app/helpers/decidim/proposals/application_helper.rb', line 106

def endorsers_for(proposal)
  proposal.endorsements.for_listing.map { |identity| present(identity.normalized_author) }
end

#filter_origin_valuesObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'app/helpers/decidim/proposals/application_helper.rb', line 128

def filter_origin_values
  base = if component_settings.official_proposals_enabled
           [
             ["all", t("decidim.proposals.application_helper.filter_origin_values.all")],
             ["official", t("decidim.proposals.application_helper.filter_origin_values.official")]
           ]
         else
           [["all", t("decidim.proposals.application_helper.filter_origin_values.all")]]
         end

  base += [["citizens", t("decidim.proposals.application_helper.filter_origin_values.citizens")]]
  base += [["user_group", t("decidim.proposals.application_helper.filter_origin_values.user_groups")]] if current_organization.user_groups_enabled?
  base + [["meeting", t("decidim.proposals.application_helper.filter_origin_values.meetings")]]
end

#filter_state_valuesObject



143
144
145
146
147
148
149
150
151
# File 'app/helpers/decidim/proposals/application_helper.rb', line 143

def filter_state_values
  [
    ["except_rejected", t("decidim.proposals.application_helper.filter_state_values.except_rejected")],
    ["accepted", t("decidim.proposals.application_helper.filter_state_values.accepted")],
    ["evaluating", t("decidim.proposals.application_helper.filter_state_values.evaluating")],
    ["rejected", t("decidim.proposals.application_helper.filter_state_values.rejected")],
    ["all", t("decidim.proposals.application_helper.filter_state_values.all")]
  ]
end

#filter_type_valuesObject



153
154
155
156
157
158
159
# File '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

#follow_button_for(model, large = nil) ⇒ Object



94
95
96
# File 'app/helpers/decidim/proposals/application_helper.rb', line 94

def follow_button_for(model, large = nil)
  render partial: "decidim/shared/follow_button.html", locals: { followable: model, large: large }
end

#form_has_address?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'app/helpers/decidim/proposals/application_helper.rb', line 110

def form_has_address?
  @form.address.present? || @form.has_address
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.



53
54
55
# File 'app/helpers/decidim/proposals/application_helper.rb', line 53

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.



24
25
26
# File 'app/helpers/decidim/proposals/application_helper.rb', line 24

def humanize_proposal_state(state)
  I18n.t(state, scope: "decidim.proposals.answers", default: :not_answered)
end

#minimum_votes_per_user_enabled?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/helpers/decidim/proposals/application_helper.rb', line 77

def minimum_votes_per_user_enabled?
  minimum_votes_per_user.positive?
end

#proposal_limitObject



81
82
83
84
85
# File 'app/helpers/decidim/proposals/application_helper.rb', line 81

def proposal_limit
  return if component_settings.proposal_limit.zero?

  component_settings.proposal_limit
end

#proposal_limit_enabled?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/helpers/decidim/proposals/application_helper.rb', line 73

def proposal_limit_enabled?
  proposal_limit.present?
end

#proposal_state_css_class(state) ⇒ Object

Public: The css class applied based on the proposal state.

state - The String state of the proposal.

Returns a String.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/decidim/proposals/application_helper.rb', line 33

def proposal_state_css_class(state)
  case state
  when "accepted"
    "text-success"
  when "rejected"
    "text-alert"
  when "evaluating"
    "text-warning"
  when "withdrawn"
    "text-alert"
  else
    "text-info"
  end
end

#show_voting_rules?Boolean

Returns:

  • (Boolean)


118
119
120
121
122
123
124
125
126
# File 'app/helpers/decidim/proposals/application_helper.rb', line 118

def show_voting_rules?
  return false unless votes_enabled?

  return true if vote_limit_enabled?
  return true if threshold_per_proposal_enabled?
  return true if proposal_limit_enabled?
  return true if can_accumulate_supports_beyond_threshold?
  return true if minimum_votes_per_user_enabled?
end

#vote_button_for(model, from_proposals_list) ⇒ Object



102
103
104
# File 'app/helpers/decidim/proposals/application_helper.rb', line 102

def vote_button_for(model, from_proposals_list)
  render partial: "decidim/proposals/proposals/participatory_texts/proposal_vote_button.html", locals: { proposal: model, from_proposals_list: from_proposals_list }
end

#votes_count_for(model, from_proposals_list) ⇒ Object



98
99
100
# File 'app/helpers/decidim/proposals/application_helper.rb', line 98

def votes_count_for(model, from_proposals_list)
  render partial: "decidim/proposals/proposals/participatory_texts/proposal_votes_count.html", locals: { proposal: model, from_proposals_list: from_proposals_list }
end

#votes_givenObject



87
88
89
90
91
92
# File 'app/helpers/decidim/proposals/application_helper.rb', line 87

def votes_given
  @votes_given ||= ProposalVote.where(
    proposal: Proposal.where(component: current_component),
    author: current_user
  ).count
end