Class: Decidim::Accountability::Admin::ResultsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Filterable, Decidim::ApplicationHelper, SanitizeHelper
Defined in:
app/controllers/decidim/accountability/admin/results_controller.rb

Overview

This controller allows an admin to manage results from a Participatory Process

Instance Method Summary collapse

Instance Method Details

#collectionObject



14
15
16
17
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 14

def collection
  parent_id = params[:parent_id].presence
  @collection ||= Result.where(component: current_component, parent_id:).page(params[:page]).per(15)
end

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 26

def create
  enforce_permission_to :create, :result

  @form = form(ResultForm).from_params(params)

  CreateResult.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("results.create.success", scope: "decidim.accountability.admin")
      redirect_to results_path(parent_id: result.parent_id)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("results.create.invalid", scope: "decidim.accountability.admin")
      render action: "new"
    end
  end
end

#destroyObject



68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 68

def destroy
  enforce_permission_to(:destroy, :result, result:)

  Decidim::Commands::DestroyResource.call(result, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("results.destroy.success", scope: "decidim.accountability.admin")

      redirect_to results_path(parent_id: result.parent_id)
    end
  end
end

#editObject



44
45
46
47
48
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 44

def edit
  enforce_permission_to(:update, :result, result:)

  @form = form(ResultForm).from_model(result)
end

#newObject



19
20
21
22
23
24
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 19

def new
  enforce_permission_to :create, :result

  @form = form(ResultForm).instance
  @form.parent_id = params[:parent_id]
end

#updateObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 50

def update
  enforce_permission_to(:update, :result, result:)

  @form = form(ResultForm).from_params(params)

  UpdateResult.call(@form, result) do
    on(:ok) do
      flash[:notice] = I18n.t("results.update.success", scope: "decidim.accountability.admin")
      redirect_to results_path(parent_id: result.parent_id)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("results.update.invalid", scope: "decidim.accountability.admin")
      render action: "edit"
    end
  end
end