Class: Decidim::Elections::Admin::SetupForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Elections::Admin::SetupForm
- Defined in:
- app/forms/decidim/elections/admin/setup_form.rb
Overview
This class holds a form to setup elections from Decidim’s admin panel.
Instance Method Summary collapse
- #bulletin_board ⇒ Object
- #current_step ⇒ Object
- #election ⇒ Object
- #messages ⇒ Object
- #participatory_space_trustees ⇒ Object
- #pending_action ⇒ Object
- #trustee_ids ⇒ Object
- #trustees ⇒ Object
- #validations ⇒ Object
Instance Method Details
#bulletin_board ⇒ Object
56 57 58 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 56 def bulletin_board @bulletin_board ||= context[:bulletin_board] || Decidim::Elections.bulletin_board end |
#current_step ⇒ Object
18 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 18 def current_step; end |
#election ⇒ Object
52 53 54 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 52 def election @election ||= context[:election] end |
#messages ⇒ Object
42 43 44 45 46 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 42 def @messages ||= validations.map do |, t_args, _valid| [, I18n.t("steps.create_election.requirements.#{}", **t_args, scope: "decidim.elections.admin")] end.to_h end |
#participatory_space_trustees ⇒ Object
48 49 50 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 48 def participatory_space_trustees @participatory_space_trustees ||= Decidim::Elections::Trustees::ByParticipatorySpace.new(election.component.participatory_space).to_a end |
#pending_action ⇒ Object
20 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 20 def pending_action; end |
#trustee_ids ⇒ Object
22 23 24 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 22 def trustee_ids choose_random_trustees end |
#trustees ⇒ Object
26 27 28 29 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 26 def trustees ids = trustee_ids @trustees ||= Decidim::Elections::Trustees::ByParticipatorySpaceTrusteeIds.new(ids).to_a.sort_by(&:id) end |
#validations ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 31 def validations @validations ||= [ [:minimum_questions, {}, election.questions.any?], [:minimum_answers, {}, election.minimum_answers?], [:max_selections, {}, election.valid_questions?], [:published, {}, election.published_at.present?], [:time_before, { hours: Decidim::Elections.setup_minimum_hours_before_start }, election.minimum_hours_before_start?], [:trustees_number, { number: bulletin_board.number_of_trustees }, participatory_space_trustees_with_public_key.size >= bulletin_board.number_of_trustees] ].freeze end |