Class: Decidim::Elections::Admin::SetupForm

Inherits:
Form
  • Object
show all
Defined in:
decidim-elections/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

Instance Method Details

#bulletin_boardObject


56
57
58
# File 'decidim-elections/app/forms/decidim/elections/admin/setup_form.rb', line 56

def bulletin_board
  @bulletin_board ||= context[:bulletin_board] || Decidim::Elections.bulletin_board
end

#current_stepObject


18
# File 'decidim-elections/app/forms/decidim/elections/admin/setup_form.rb', line 18

def current_step; end

#electionObject


52
53
54
# File 'decidim-elections/app/forms/decidim/elections/admin/setup_form.rb', line 52

def election
  @election ||= context[:election]
end

#messagesObject


42
43
44
45
46
# File 'decidim-elections/app/forms/decidim/elections/admin/setup_form.rb', line 42

def messages
  @messages ||= validations.map do |message, t_args, _valid|
    [message, I18n.t("steps.create_election.requirements.#{message}", **t_args, scope: "decidim.elections.admin")]
  end.to_h
end

#participatory_space_trusteesObject


48
49
50
# File 'decidim-elections/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_actionObject


20
# File 'decidim-elections/app/forms/decidim/elections/admin/setup_form.rb', line 20

def pending_action; end

#trustee_idsObject


22
23
24
# File 'decidim-elections/app/forms/decidim/elections/admin/setup_form.rb', line 22

def trustee_ids
  choose_random_trustees
end

#trusteesObject


26
27
28
29
# File 'decidim-elections/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

#validationsObject


31
32
33
34
35
36
37
38
39
40
# File 'decidim-elections/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