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

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

Overview

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

Constant Summary

Constants included from Decidim::AmendmentsHelper

Decidim::AmendmentsHelper::TOTAL_STEPS

Instance Method Summary collapse

Methods included from SanitizeHelper

#decidim_escape_translated, #decidim_html_escape, #decidim_rich_text, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included

Methods included from Decidim::ApplicationHelper

#add_body_classes, #cell, #edit_link, #extra_admin_link, #html_truncate, #present, #prevent_timeout_seconds, #resolve_presenter_class, #text_initials

Methods included from CacheHelper

#cache

Methods included from Decidim::AmendmentsHelper

#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amendments_enabled?, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #current_step, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body, #total_steps, #wizard_aside_back_url, #wizard_header_title

Methods included from RichTextEditorHelper

included, #text_editor_for

Methods included from ContextualHelpHelper

#floating_help

Methods included from ScopesHelper

#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_select_field, #scopes_select_tag

Methods included from TranslatableAttributes

#default_locale?

Methods included from DecidimFormHelper

#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #ordered_scopes_descendants, #ordered_scopes_descendants_for_select, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag

Methods included from OmniauthHelper

#normalize_provider_name, #oauth_icon, #provider_name

Methods inherited from Decidim::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 Decidim::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

#collectionObject



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

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

#createObject



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

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

#editObject



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

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

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

#newObject



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

def new
  enforce_permission_to :create, :result

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

#updateObject



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

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