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

Instance Method Details

#remaining_votes_count_for(user) ⇒ Object

Return the remaining votes for a user if the current feature has a vote limit

user - A User object

Returns a number with the remaining votes for that user



38
39
40
41
42
43
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 38

def remaining_votes_count_for(user)
  return 0 unless vote_limit_enabled?
  proposals = Proposal.where(feature: current_feature)
  votes_count = ProposalVote.where(author: user, proposal: proposals).size
  feature_settings.vote_limit - votes_count
end

#vote_button_classes(from_proposals_list) ⇒ Object

Returns the css classes used for proposal vote button in both proposals list and show pages

from_proposals_list - A boolean to indicate if the template is rendered from the proposals list page

Returns a string with the value of the css classes.



21
22
23
24
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 21

def vote_button_classes(from_proposals_list)
  return "small" if from_proposals_list
  "expanded button--sc"
end

#vote_limit_enabled?Boolean

Check if the vote limit is enabled for the current feature

Returns true if the vote limit is enabled

Returns:

  • (Boolean)


29
30
31
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 29

def vote_limit_enabled?
  current_user && feature_settings.vote_limit.present? && feature_settings.vote_limit.positive?
end

#votes_count_classes(from_proposals_list) ⇒ Object

Returns the css classes used for proposal votes count in both proposals list and show pages

from_proposals_list - A boolean to indicate if the template is rendered from the proposals list page

Returns a hash with the css classes for the count number and label



11
12
13
14
# File 'app/helpers/decidim/proposals/proposal_votes_helper.rb', line 11

def votes_count_classes(from_proposals_list)
  return { number: "card__support__number", label: "" } if from_proposals_list
  { number: "extra__suport-number", label: "extra__suport-text" }
end