Module: Decidim::Proposals::ProposalVotesHelper
- Included in:
- ApplicationHelper, ProposalVotesController
- Defined in:
- app/helpers/decidim/proposals/proposal_votes_helper.rb
Overview
Simple helpers to handle markup variations for proposal votes partials
Instance Method Summary collapse
-
#can_accumulate_votes_beyond_threshold? ⇒ Boolean
Public: Checks if can accumulate more than maximum is enabled.
-
#current_user_can_vote? ⇒ Boolean
Public: Checks if the current user is allowed to vote in this step.
- #minimum_votes_per_user_enabled? ⇒ Boolean
- #proposal_voted_by_user?(proposal) ⇒ Boolean
-
#remaining_minimum_votes_count_for_user ⇒ Object
Return the remaining minimum votes for a user if the current component has a vote limit.
-
#remaining_votes_count_for_user ⇒ Object
Return the remaining votes for a user if the current component has a vote limit.
-
#threshold_per_proposal ⇒ Object
Public: Fetches the maximum amount of votes per proposal.
-
#threshold_per_proposal_enabled? ⇒ Boolean
Public: Checks if threshold per proposal are set.
-
#vote_limit_enabled? ⇒ Boolean
Check if the vote limit is enabled for the current component.
-
#votes_blocked? ⇒ Boolean
Public: Checks if voting is blocked in this step.
-
#votes_enabled? ⇒ Boolean
Public: Checks if voting is enabled in this step.
Instance Method Details
#can_accumulate_votes_beyond_threshold? ⇒ Boolean
Public: Checks if can accumulate more than maximum is enabled
Returns true if enabled, false otherwise.
39 40 41 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 39 def can_accumulate_votes_beyond_threshold? component_settings.can_accumulate_votes_beyond_threshold end |
#current_user_can_vote? ⇒ Boolean
Public: Checks if the current user is allowed to vote in this step.
Returns true if the current user can vote, false otherwise.
60 61 62 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 60 def current_user_can_vote? current_user && votes_enabled? && vote_limit_enabled? && !votes_blocked? end |
#minimum_votes_per_user_enabled? ⇒ Boolean
16 17 18 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 16 def minimum_votes_per_user_enabled? minimum_votes_per_user.positive? end |
#proposal_voted_by_user?(proposal) ⇒ Boolean
64 65 66 67 68 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 64 def proposal_voted_by_user?(proposal) return false if current_user.blank? || proposal.blank? all_voted_proposals_by_user.include?(proposal.id) end |
#remaining_minimum_votes_count_for_user ⇒ Object
Return the remaining minimum votes for a user if the current component has a vote limit
user - A User object
Returns a number with the remaining minimum votes for that user
86 87 88 89 90 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 86 def remaining_minimum_votes_count_for_user return 0 unless minimum_votes_per_user_enabled? component_settings.minimum_votes_per_user - votes_given end |
#remaining_votes_count_for_user ⇒ Object
Return the remaining votes for a user if the current component has a vote limit
user - A User object
Returns a number with the remaining votes for that user
75 76 77 78 79 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 75 def remaining_votes_count_for_user return 0 unless vote_limit_enabled? component_settings.vote_limit - votes_given end |
#threshold_per_proposal ⇒ Object
Public: Fetches the maximum amount of votes per proposal.
Returns an Integer with the maximum amount of votes, nil otherwise.
30 31 32 33 34 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 30 def threshold_per_proposal return nil unless component_settings.threshold_per_proposal&.positive? component_settings.threshold_per_proposal end |
#threshold_per_proposal_enabled? ⇒ Boolean
Public: Checks if threshold per proposal are set.
Returns true if set, false otherwise.
23 24 25 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 23 def threshold_per_proposal_enabled? threshold_per_proposal.present? end |
#vote_limit_enabled? ⇒ Boolean
Check if the vote limit is enabled for the current component
Returns true if the vote limit is enabled
12 13 14 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 12 def vote_limit_enabled? vote_limit.present? end |
#votes_blocked? ⇒ Boolean
Public: Checks if voting is blocked in this step.
Returns true if blocked, false otherwise.
53 54 55 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 53 def votes_blocked? current_settings.respond_to?(:votes_blocked) && current_settings.votes_blocked end |
#votes_enabled? ⇒ Boolean
Public: Checks if voting is enabled in this step.
Returns true if enabled, false otherwise.
46 47 48 |
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 46 def votes_enabled? current_settings.respond_to?(:votes_enabled) && current_settings.votes_enabled end |