Class: Decidim::Elections::Admin::ElectionsController
- Inherits:
-
ApplicationController
- Object
- Admin::Components::BaseController
- ApplicationController
- Decidim::Elections::Admin::ElectionsController
- Includes:
- Admin::HasTrashableResources, ApplicationHelper, Filterable
- Defined in:
- app/controllers/decidim/elections/admin/elections_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #dashboard ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #publish ⇒ Object
- #unpublish ⇒ Object
- #update ⇒ Object
- #update_status ⇒ Object
Instance Method Details
#create ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 25 def create :create, :election @form = form(Decidim::Elections::Admin::ElectionForm).from_params(params, current_component:) CreateElection.call(@form) do on(:ok) do |election| flash[:notice] = I18n.t("elections.create.success", scope: "decidim.elections.admin") redirect_to edit_questions_election_path(election) end on(:invalid) do flash.now[:alert] = I18n.t("elections.create.invalid", scope: "decidim.elections.admin") render action: "new", status: :unprocessable_entity end end end |
#dashboard ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 98 def dashboard :dashboard, :election, election: election respond_to do |format| format.html { render :dashboard } format.json do render json: election.presenter.to_json(admin: true) # Admins see all votes, not just the published results end end end |
#edit ⇒ Object
43 44 45 46 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 43 def edit :update, :election, election: @form = form(Decidim::Elections::Admin::ElectionForm).from_model(election) end |
#index ⇒ Object
14 15 16 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 14 def index :read, :election end |
#new ⇒ Object
18 19 20 21 22 23 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 18 def new :create, :election @form = form(Decidim::Elections::Admin::ElectionForm).from_params( attachment: form(AttachmentForm).from_params({}) ) end |
#publish ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 66 def publish :publish, :election, election: election PublishElection.call(election, current_user) do on(:ok) do flash[:notice] = I18n.t("elections.publish.success", scope: "decidim.elections.admin") redirect_to dashboard_election_path(election) end on(:invalid) do flash.now[:alert] = I18n.t("elections.publish.invalid", scope: "decidim.elections.admin") render action: "index", status: :unprocessable_entity end end end |
#unpublish ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 82 def unpublish :unpublish, :election, election: election Decidim::Elections::Admin::UnpublishElection.call(election, current_user) do on(:ok) do flash[:notice] = I18n.t("elections.unpublish.success", scope: "decidim.elections.admin") redirect_to elections_path end on(:invalid) do flash.now[:alert] = I18n.t("elections.unpublish.invalid", scope: "decidim.elections.admin") render action: "index", status: :unprocessable_entity end end end |
#update ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 48 def update :update, :election, election: election @form = form(Decidim::Elections::Admin::ElectionForm).from_params(params, current_component:, election:) UpdateElection.call(@form, election) do on(:ok) do flash[:notice] = I18n.t("elections.update.success", scope: "decidim.elections.admin") redirect_to election.published? ? dashboard_election_path(election) : edit_questions_election_path(election) end on(:invalid) do flash.now[:alert] = I18n.t("elections.update.invalid", scope: "decidim.elections.admin") render action: "edit", status: :unprocessable_entity end end end |
#update_status ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 109 def update_status :update, :election, election: election status_action = params[:status_action] UpdateElectionStatus.call(status_action, election) do on(:ok) do flash[:notice] = I18n.t("statuses.#{status_action}.success", scope: "decidim.elections.admin") end on(:invalid) do flash[:alert] = I18n.t("statuses.unknown", scope: "decidim.elections.admin") end end redirect_to dashboard_election_path(election) end |