app/helpers/decidim/proposals/application_helper.rb in decidim-proposals-0.14.4 vs app/helpers/decidim/proposals/application_helper.rb in decidim-proposals-0.15.0

- old
+ new

@@ -11,10 +11,12 @@ include ProposalEndorsementsHelper include Decidim::MapHelper include Decidim::Proposals::MapHelper include CollaborativeDraftHelper + delegate :minimum_votes_per_user, to: :component_settings + # Public: The state of a proposal in a way a human can understand. # # state - The String state of the proposal. # # Returns a String. @@ -67,16 +69,27 @@ def proposal_limit_enabled? proposal_limit.present? end + def minimum_votes_per_user_enabled? + minimum_votes_per_user.positive? + end + def proposal_limit return if component_settings.proposal_limit.zero? component_settings.proposal_limit end + def votes_given + @votes_given ||= ProposalVote.where( + proposal: Proposal.where(component: current_component), + author: current_user + ).count + end + def current_user_proposals Proposal.where(component: current_component, author: current_user) end def follow_button_for(model) @@ -99,9 +112,19 @@ @form.address.present? || @form.has_address end def authors_for(collaborative_draft) collaborative_draft.identities.map { |identity| present(identity) } + end + + 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 end end end