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
- #census ⇒ Object
- #census_codes_generated? ⇒ Boolean
- #census_messages ⇒ Object
- #census_validations ⇒ Object
- #current_step ⇒ Object
- #election ⇒ Object
- #main_button? ⇒ Boolean
- #messages ⇒ Object
- #needs_census? ⇒ Boolean
- #participatory_space_trustees ⇒ Object
- #pending_action ⇒ Object
- #trustee_ids ⇒ Object
- #trustees ⇒ Object
- #validations ⇒ Object
- #vote_flow ⇒ Object
Instance Method Details
#bulletin_board ⇒ Object
80 81 82 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 80 def bulletin_board @bulletin_board ||= context[:bulletin_board] || Decidim::Elections.bulletin_board end |
#census ⇒ Object
98 99 100 101 102 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 98 def census return unless needs_census? @census ||= election.component.participatory_space.dataset end |
#census_codes_generated? ⇒ Boolean
92 93 94 95 96 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 92 def census_codes_generated? return unless needs_census? census&.codes_generated? || census&.exporting_codes? || census&.freeze? end |
#census_messages ⇒ Object
66 67 68 69 70 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 66 def @census_messages ||= census_validations.to_h do |, t_args, _valid| [, I18n.t("steps.create_election.requirements.#{}", **t_args, scope: "decidim.elections.admin")] end end |
#census_validations ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 50 def census_validations return [] unless needs_census? @census_validations ||= [ [:census_uploaded, {}, census.present? && census.data.exists?], [:census_codes_generated, {}, census_codes_generated?], [:census_frozen, {}, census&.freeze?] ].freeze end |
#current_step ⇒ Object
24 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 24 def current_step; end |
#election ⇒ Object
76 77 78 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 76 def election @election ||= context[:election] end |
#main_button? ⇒ Boolean
104 105 106 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 104 def true end |
#messages ⇒ Object
60 61 62 63 64 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 60 def @messages ||= validations.to_h do |, t_args, _valid| [, I18n.t("steps.create_election.requirements.#{}", **t_args, scope: "decidim.elections.admin")] end end |
#needs_census? ⇒ Boolean
84 85 86 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 84 def needs_census? vote_flow.is_a?(Decidim::Votings::CensusVoteFlow) end |
#participatory_space_trustees ⇒ Object
72 73 74 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 72 def participatory_space_trustees @participatory_space_trustees ||= Decidim::Elections::Trustees::ByParticipatorySpace.new(election.component.participatory_space).to_a end |
#pending_action ⇒ Object
26 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 26 def pending_action; end |
#trustee_ids ⇒ Object
28 29 30 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 28 def trustee_ids choose_random_trustees end |
#trustees ⇒ Object
32 33 34 35 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 32 def trustees ids = trustee_ids @trustees ||= Decidim::Elections::Trustees::ByParticipatorySpaceTrusteeIds.new(ids).to_a.sort_by(&:id) end |
#validations ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 37 def validations @validations ||= [ [:minimum_questions, {}, election.questions.any?], [:minimum_answers, {}, election.minimum_answers?], [:max_selections, {}, election.valid_questions?], [:published, {}, election.published_at.present?], [:component_published, {}, election.component.published?], [:time_before, { hours: I18n.t("datetime.distance_in_words.x_hours", count: 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 |
#vote_flow ⇒ Object
88 89 90 |
# File 'app/forms/decidim/elections/admin/setup_form.rb', line 88 def vote_flow @vote_flow ||= election.participatory_space.try(:vote_flow_for, election) end |