Module: Decidim::EnhancedTextwork::ParagraphVotesHelper
- Included in:
- ApplicationHelper, ParagraphVotesController
- Defined in:
- app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb
Overview
Simple helpers to handle markup variations for paragraph votes partials
Instance Method Summary collapse
-
#can_accumulate_supports_beyond_threshold? ⇒ Boolean
Public: Checks if can accumulate more than maxium is enabled.
-
#current_user_can_vote? ⇒ Boolean
Public: Checks if the current user is allowed to vote in this step.
-
#remaining_votes_count_for(user) ⇒ Object
Return the remaining votes for a user if the current component has a vote limit.
-
#threshold_per_paragraph ⇒ Object
Public: Fetches the maximum amount of votes per paragraph.
-
#threshold_per_paragraph_enabled? ⇒ Boolean
Public: Checks if threshold per paragraph are set.
-
#vote_button_classes(from_paragraphs_list) ⇒ Object
Returns the css classes used for paragraph vote button in both paragraphs list and show pages.
-
#vote_limit ⇒ Object
Public: Gets the vote limit for each user, if 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_count_classes(from_paragraphs_list) ⇒ Object
Returns the css classes used for paragraph votes count in both paragraphs list and show pages.
-
#votes_enabled? ⇒ Boolean
Public: Checks if voting is enabled in this step.
Instance Method Details
#can_accumulate_supports_beyond_threshold? ⇒ Boolean
Public: Checks if can accumulate more than maxium is enabled
Returns true if enabled, false otherwise.
64 65 66 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 64 def can_accumulate_supports_beyond_threshold? component_settings.can_accumulate_supports_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.
85 86 87 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 85 def current_user_can_vote? current_user && votes_enabled? && vote_limit_enabled? && !votes_blocked? 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
94 95 96 97 98 99 100 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 94 def remaining_votes_count_for(user) return 0 unless vote_limit_enabled? paragraphs = Paragraph.where(component: current_component) votes_count = ParagraphVote.where(author: user, paragraph: paragraphs).size component_settings.vote_limit - votes_count end |
#threshold_per_paragraph ⇒ Object
Public: Fetches the maximum amount of votes per paragraph.
Returns an Integer with the maximum amount of votes, nil otherwise.
55 56 57 58 59 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 55 def threshold_per_paragraph return nil unless component_settings.threshold_per_paragraph.positive? component_settings.threshold_per_paragraph end |
#threshold_per_paragraph_enabled? ⇒ Boolean
Public: Checks if threshold per paragraph are set.
Returns true if set, false otherwise.
48 49 50 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 48 def threshold_per_paragraph_enabled? threshold_per_paragraph.present? end |
#vote_button_classes(from_paragraphs_list) ⇒ Object
Returns the css classes used for paragraph vote button in both paragraphs list and show pages
from_paragraphs_list - A boolean to indicate if the template is rendered from the paragraphs list page
Returns a string with the value of the css classes.
23 24 25 26 27 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 23 def (from_paragraphs_list) return "card__button" if from_paragraphs_list "expanded" end |
#vote_limit ⇒ Object
Public: Gets the vote limit for each user, if set.
Returns an Integer if set, nil otherwise.
32 33 34 35 36 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 32 def vote_limit return nil if component_settings.vote_limit.zero? component_settings.vote_limit end |
#vote_limit_enabled? ⇒ Boolean
Check if the vote limit is enabled for the current component
Returns true if the vote limit is enabled
41 42 43 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 41 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.
78 79 80 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 78 def votes_blocked? current_settings.votes_blocked end |
#votes_count_classes(from_paragraphs_list) ⇒ Object
Returns the css classes used for paragraph votes count in both paragraphs list and show pages
from_paragraphs_list - A boolean to indicate if the template is rendered from the paragraphs list page
Returns a hash with the css classes for the count number and label
12 13 14 15 16 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 12 def votes_count_classes(from_paragraphs_list) return { number: "card__support__number", label: "" } if from_paragraphs_list { number: "extra__suport-number", label: "extra__suport-text" } end |
#votes_enabled? ⇒ Boolean
Public: Checks if voting is enabled in this step.
Returns true if enabled, false otherwise.
71 72 73 |
# File 'app/helpers/decidim/enhanced_textwork/paragraph_votes_helper.rb', line 71 def votes_enabled? current_settings.votes_enabled end |