Class: Decidim::DecidimAwesome::Proposals::VotesByProposalStatus
- Inherits:
-
Object
- Object
- Decidim::DecidimAwesome::Proposals::VotesByProposalStatus
- Defined in:
- app/services/decidim/decidim_awesome/proposals/votes_by_proposal_status.rb
Overview
"Votes by proposal status" filter logic, shared by Permissions and view helpers.
Class Method Summary collapse
-
.choices_for(component) ⇒ Object
[label, token] pairs for the admin multiselect: synthetic "not_answered" first, then real states.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #allowed?(proposal) ⇒ Boolean
- #allowed_tokens ⇒ Object
-
#initialize(settings) ⇒ VotesByProposalStatus
constructor
A new instance of VotesByProposalStatus.
Constructor Details
#initialize(settings) ⇒ VotesByProposalStatus
Returns a new instance of VotesByProposalStatus.
8 9 10 |
# File 'app/services/decidim/decidim_awesome/proposals/votes_by_proposal_status.rb', line 8 def initialize(settings) @settings = settings end |
Class Method Details
.choices_for(component) ⇒ Object
[label, token] pairs for the admin multiselect: synthetic "not_answered" first, then real states.
31 32 33 34 35 36 37 38 |
# File 'app/services/decidim/decidim_awesome/proposals/votes_by_proposal_status.rb', line 31 def self.choices_for(component) not_answered = [I18n.t("decidim.proposals.answers.not_answered"), "not_answered"] real_states = Decidim::Proposals::ProposalState .where(component:) .where.not(token: "not_answered") .map { |state| [state.translated_attribute(state.title), state.token] } [not_answered] + real_states end |
Instance Method Details
#active? ⇒ Boolean
12 13 14 15 16 17 18 |
# File 'app/services/decidim/decidim_awesome/proposals/votes_by_proposal_status.rb', line 12 def active? return false unless Decidim::DecidimAwesome.enabled?(:votes_by_proposal_status) return false unless @settings.try(:votes_enabled) return false unless @settings.try(:awesome_votes_enabled_by_status) allowed_tokens.any? end |
#allowed?(proposal) ⇒ Boolean
20 21 22 23 24 |
# File 'app/services/decidim/decidim_awesome/proposals/votes_by_proposal_status.rb', line 20 def allowed?(proposal) return false unless proposal allowed_tokens.include?(proposal.internal_state) end |
#allowed_tokens ⇒ Object
26 27 28 |
# File 'app/services/decidim/decidim_awesome/proposals/votes_by_proposal_status.rb', line 26 def allowed_tokens @allowed_tokens ||= Array(@settings.try(:awesome_votes_enabled_states)).compact_blank.map(&:to_s) end |