app/forms/decidim/elections/admin/setup_form.rb in decidim-elections-0.26.2 vs app/forms/decidim/elections/admin/setup_form.rb in decidim-elections-0.26.3

- old
+ new

@@ -11,10 +11,16 @@ validate do validations.each do |message, t_args, valid| errors.add(message, I18n.t("steps.create_election.errors.#{message}", **t_args, scope: "decidim.elections.admin")) unless valid end + + if needs_census? + census_validations.each do |message, t_args, valid| + errors.add(message, I18n.t("steps.create_election.errors.#{message}", **t_args, scope: "decidim.elections.admin")) unless valid + end + end end def current_step; end def pending_action; end @@ -32,30 +38,67 @@ @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: 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 + 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 + 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 + def census_messages + @census_messages ||= census_validations.to_h do |message, t_args, _valid| + [message, I18n.t("steps.create_election.requirements.#{message}", **t_args, scope: "decidim.elections.admin")] + end + end + def participatory_space_trustees @participatory_space_trustees ||= Decidim::Elections::Trustees::ByParticipatorySpace.new(election.component.participatory_space).to_a end def election @election ||= context[:election] end def bulletin_board @bulletin_board ||= context[:bulletin_board] || Decidim::Elections.bulletin_board + end + + def needs_census? + vote_flow.is_a?(Decidim::Votings::CensusVoteFlow) + end + + def vote_flow + @vote_flow ||= election.participatory_space.try(:vote_flow_for, election) + end + + def census_codes_generated? + return unless needs_census? + + census&.codes_generated? || census&.exporting_codes? || census&.freeze? + end + + def census + return unless needs_census? + + @census ||= election.component.participatory_space.dataset end def main_button? true end