Class: Decidim::Elections::Admin::StepsController

Inherits:
ApplicationController show all
Defined in:
decidim-elections/app/controllers/decidim/elections/admin/steps_controller.rb

Overview

This controller allows to manage the steps of an election.

Instance Method Summary collapse

Methods inherited from Admin::Components::BaseController

#current_component, #current_participatory_space, #parent_path, #permission_class_chain, #permission_scope, #permissions_context, #set_component_breadcrumb_item, #skip_manage_component_permission

Methods included from RegistersPermissions

register_permissions

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#indexObject



12
13
14
15
16
17
18
19
# File 'decidim-elections/app/controllers/decidim/elections/admin/steps_controller.rb', line 12

def index
  enforce_permission_to(:read, :steps, election:)

  if current_step_form_class
    @form = form(current_step_form_class).instance(election:)
    @form.valid?
  end
end

#statsObject



45
46
47
# File 'decidim-elections/app/controllers/decidim/elections/admin/steps_controller.rb', line 45

def stats
  render "decidim/elections/admin/steps/_vote_stats", layout: false
end

#updateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'decidim-elections/app/controllers/decidim/elections/admin/steps_controller.rb', line 21

def update
  enforce_permission_to(:update, :steps, election:)
  redirect_to election_steps_path(election) && return unless params[:id] == current_step

  @form = form(current_step_form_class).from_params(params, election:)
  Decidim::Elections::Admin::UpdateActionStatus.call(@form.pending_action) if @form.pending_action

  # check pending action status mode
  return render json: { status: @form.pending_action&.status } if params[:check_pending_action]

  return redirect_to election_steps_path(election) if @form.pending_action

  current_step_command_class.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("steps.#{current_step}.success", scope: "decidim.elections.admin")
      return redirect_to election_steps_path(election)
    end
    on(:invalid) do |message|
      flash.now[:alert] = message || I18n.t("steps.#{current_step}.invalid", scope: "decidim.elections.admin")
    end
  end
  render :index
end