Class: Decidim::Initiatives::Admin::InitiativesController
- Inherits:
-
ApplicationController
- Object
- DecidimController
- Admin::ApplicationController
- ApplicationController
- Decidim::Initiatives::Admin::InitiativesController
- Includes:
- Admin::ParticipatorySpaceAdminBreadcrumb, Filterable, NeedsInitiative, SingleInitiativeType, TypeSelectorOptions
- Defined in:
- decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb
Overview
Controller used to manage the initiatives
Instance Method Summary collapse
-
#accept ⇒ Object
POST /admin/initiatives/:id/accept.
-
#discard ⇒ Object
DELETE /admin/initiatives/:id/discard.
-
#edit ⇒ Object
GET /admin/initiatives/:id/edit.
-
#export ⇒ Object
GET /admin/initiatives/export.
-
#export_pdf_signatures ⇒ Object
GET /admin/initiatives/:id/export_pdf_signatures.pdf.
-
#export_votes ⇒ Object
GET /admin/initiatives/:id/export_votes.
-
#index ⇒ Object
GET /admin/initiatives.
-
#publish ⇒ Object
POST /admin/initiatives/:id/publish.
-
#reject ⇒ Object
DELETE /admin/initiatives/:id/reject.
-
#send_to_technical_validation ⇒ Object
GET /admin/initiatives/:id/send_to_technical_validation.
-
#unpublish ⇒ Object
DELETE /admin/initiatives/:id/unpublish.
-
#update ⇒ Object
PUT /admin/initiatives/:id.
Methods included from TranslationsHelper
empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?
Methods included from TranslatableAttributes
Methods inherited from ApplicationController
#permission_class_chain, #permissions_context
Methods inherited from Admin::ApplicationController
#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path
Methods included from Headers::HttpCachingDisabler
Methods included from NeedsSnippets
Methods included from RegistersPermissions
Methods included from NeedsOrganization
enhance_controller, extended, included
Instance Method Details
#accept ⇒ Object
POST /admin/initiatives/:id/accept
100 101 102 103 104 105 106 107 108 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 100 def accept :accept, :initiative, initiative: current_initiative AcceptInitiative.call(current_initiative, current_user) do on(:ok) do flash[:notice] = I18n.t("initiatives.accept.success", scope: "decidim.initiatives.admin") redirect_to decidim_admin_initiatives.edit_initiative_path(current_initiative) end end end |
#discard ⇒ Object
DELETE /admin/initiatives/:id/discard
89 90 91 92 93 94 95 96 97 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 89 def discard :discard, :initiative, initiative: current_initiative DiscardInitiative.call(current_initiative, current_user) do on(:ok) do flash[:notice] = I18n.t("initiatives.discard.success", scope: "decidim.initiatives.admin") redirect_to decidim_admin_initiatives.edit_initiative_path(current_initiative) end end end |
#edit ⇒ Object
GET /admin/initiatives/:id/edit
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 29 def edit :edit, :initiative, initiative: current_initiative = form(AttachmentForm).from_model(current_initiative..first) @form = form(Decidim::Initiatives::Admin::InitiativeForm) .from_model( current_initiative, initiative: current_initiative ) @form. = render layout: "decidim/admin/initiative" end |
#export ⇒ Object
GET /admin/initiatives/export
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 138 def export :export, :initiatives Decidim::Initiatives::ExportInitiativesJob.perform_later( current_user, current_organization, params[:format] || default_format, params[:collection_ids].presence&.map(&:to_i) ) flash[:notice] = t("decidim.admin.exports.notice") redirect_back(fallback_location: initiatives_path) end |
#export_pdf_signatures ⇒ Object
GET /admin/initiatives/:id/export_pdf_signatures.pdf
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 170 def export_pdf_signatures :export_pdf_signatures, :initiative, initiative: current_initiative @votes = current_initiative.votes output = render_to_string( pdf: "votes_#{current_initiative.id}", layout: "decidim/admin/initiatives_votes", template: "decidim/initiatives/admin/initiatives/export_pdf_signatures", format: [:pdf] ) output = pdf_signature_service.new(pdf: output).signed_pdf if pdf_signature_service respond_to do |format| format.pdf do send_data(output, filename: "votes_#{current_initiative.id}.pdf", type: "application/pdf") end format.html end end |
#export_votes ⇒ Object
GET /admin/initiatives/:id/export_votes
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 154 def export_votes :export_votes, :initiative, initiative: current_initiative votes = current_initiative.votes.map(&:sha1) csv_data = CSV.generate(headers: false) do |csv| votes.each do |sha1| csv << [sha1] end end respond_to do |format| format.csv { send_data csv_data, file_name: "votes.csv" } end end |
#index ⇒ Object
GET /admin/initiatives
23 24 25 26 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 23 def index :list, :initiative @initiatives = filtered_collection end |
#publish ⇒ Object
POST /admin/initiatives/:id/publish
65 66 67 68 69 70 71 72 73 74 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 65 def publish :publish, :initiative, initiative: current_initiative PublishInitiative.call(current_initiative, current_user) do on(:ok) do flash[:notice] = I18n.t("initiatives.publish.success", scope: "decidim.initiatives.admin") redirect_to decidim_admin_initiatives.edit_initiative_path(current_initiative) end end end |
#reject ⇒ Object
DELETE /admin/initiatives/:id/reject
111 112 113 114 115 116 117 118 119 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 111 def reject :reject, :initiative, initiative: current_initiative RejectInitiative.call(current_initiative, current_user) do on(:ok) do flash[:notice] = I18n.t("initiatives.reject.success", scope: "decidim.initiatives.admin") redirect_to decidim_admin_initiatives.edit_initiative_path(current_initiative) end end end |
#send_to_technical_validation ⇒ Object
GET /admin/initiatives/:id/send_to_technical_validation
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 122 def send_to_technical_validation :send_to_technical_validation, :initiative, initiative: current_initiative SendInitiativeToTechnicalValidation.call(current_initiative, current_user) do on(:ok) do redirect_to EngineRouter.main_proxy(current_initiative).initiatives_path(initiative_slug: nil), flash: { notice: I18n.t( "success", scope: "decidim.initiatives.admin.initiatives.edit" ) } end end end |
#unpublish ⇒ Object
DELETE /admin/initiatives/:id/unpublish
77 78 79 80 81 82 83 84 85 86 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 77 def unpublish :unpublish, :initiative, initiative: current_initiative UnpublishInitiative.call(current_initiative, current_user) do on(:ok) do flash[:notice] = I18n.t("initiatives.unpublish.success", scope: "decidim.initiatives.admin") redirect_to decidim_admin_initiatives.edit_initiative_path(current_initiative) end end end |
#update ⇒ Object
PUT /admin/initiatives/:id
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb', line 44 def update :update, :initiative, initiative: current_initiative params[:id] = params[:slug] @form = form(Decidim::Initiatives::Admin::InitiativeForm) .from_params(params, initiative: current_initiative) Decidim::Initiatives::Admin::UpdateInitiative.call(@form, current_initiative) do on(:ok) do |initiative| flash[:notice] = I18n.t("initiatives.update.success", scope: "decidim.initiatives.admin") redirect_to edit_initiative_path(initiative) end on(:invalid) do flash.now[:alert] = I18n.t("initiatives.update.error", scope: "decidim.initiatives.admin") render :edit, layout: "decidim/admin/initiative" end end end |