Class: Decidim::Proposals::ProposalsController
- Inherits:
-
ApplicationController
- Object
- Components::BaseController
- ApplicationController
- Decidim::Proposals::ProposalsController
- Includes:
- Orderable, FilterResource, FormFactory, Paginable
- Defined in:
- app/controllers/decidim/proposals/proposals_controller.rb
Overview
Exposes the proposal resource so users can view and create them.
Instance Method Summary collapse
- #compare ⇒ Object
- #complete ⇒ Object
- #create ⇒ Object
- #destroy_draft ⇒ Object
- #edit ⇒ Object
- #edit_draft ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #publish ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #update_draft ⇒ Object
- #withdraw ⇒ Object
Instance Method Details
#compare ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 74 def compare @step = :step_2 @similar_proposals ||= Decidim::Proposals::SimilarProposals .for(current_component, params[:proposal]) .all @form = form(ProposalForm).from_params(params) if @similar_proposals.blank? flash[:notice] = I18n.t("proposals.proposals.compare.no_similars_found", scope: "decidim") redirect_to complete_proposals_path(proposal: { title: @form.title, body: @form.body }) end end |
#complete ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 87 def complete :create, Proposal @step = :step_3 if params[:proposal].present? params[:proposal][:attachment] = form(AttachmentForm).from_params({}) @form = form(ProposalForm).from_params(params) else @form = form(ProposalForm).from_params( attachment: form(AttachmentForm).from_params({}) ) end end |
#create ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 55 def create :create, Proposal @step = :step_3 @form = form(ProposalForm).from_params(params) CreateProposal.call(@form, current_user) do on(:ok) do |proposal| flash[:notice] = I18n.t("proposals.create.success", scope: "decidim") redirect_to Decidim::ResourceLocatorPresenter.new(proposal).path + "/preview" end on(:invalid) do flash.now[:alert] = I18n.t("proposals.create.error", scope: "decidim") render :complete end end end |
#destroy_draft ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 144 def destroy_draft :edit, Proposal DestroyProposal.call(@proposal, current_user) do on(:ok) do flash[:notice] = I18n.t("proposals.destroy_draft.success", scope: "decidim") redirect_to new_proposal_path end on(:invalid) do flash.now[:alert] = I18n.t("proposals.destroy_draft.error", scope: "decidim") render :edit_draft end end end |
#edit ⇒ Object
160 161 162 163 164 165 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 160 def edit @proposal = Proposal.published.not_hidden.where(component: current_component).find(params[:id]) :edit, @proposal @form = form(ProposalForm).from_model(@proposal) end |
#edit_draft ⇒ Object
119 120 121 122 123 124 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 119 def edit_draft @step = :step_3 :edit, Proposal @form = form(ProposalForm).from_model(@proposal) end |
#index ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 18 def index @proposals = search .results .published .not_hidden .includes(:author) .includes(:category) .includes(:scope) @voted_proposals = if current_user ProposalVote.where( author: current_user, proposal: @proposals.pluck(:id) ).pluck(:decidim_proposal_id) else [] end @proposals = paginate(@proposals) @proposals = reorder(@proposals) end |
#new ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 45 def new :create, Proposal @step = :step_1 if proposal_draft.present? redirect_to edit_draft_proposal_path(proposal_draft, component_id: proposal_draft.component.id, question_slug: proposal_draft.component.participatory_space.slug) else @form = form(ProposalForm).from_params(params) end end |
#preview ⇒ Object
100 101 102 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 100 def preview @step = :step_4 end |
#publish ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 104 def publish @step = :step_4 PublishProposal.call(@proposal, current_user) do on(:ok) do flash[:notice] = I18n.t("proposals.publish.success", scope: "decidim") redirect_to proposal_path(@proposal) end on(:invalid) do flash.now[:alert] = I18n.t("proposals.publish.error", scope: "decidim") render :edit_draft end end end |
#show ⇒ Object
40 41 42 43 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 40 def show @proposal = Proposal.published.not_hidden.where(component: current_component).find(params[:id]) @report_form = form(Decidim::ReportForm).from_params(reason: "spam") end |
#update ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 167 def update @proposal = Proposal.not_hidden.where(component: current_component).find(params[:id]) :edit, @proposal @form = form(ProposalForm).from_params(params) UpdateProposal.call(@form, current_user, @proposal) do on(:ok) do |proposal| flash[:notice] = I18n.t("proposals.update.success", scope: "decidim") redirect_to Decidim::ResourceLocatorPresenter.new(proposal).path end on(:invalid) do flash.now[:alert] = I18n.t("proposals.update.error", scope: "decidim") render :edit end end end |
#update_draft ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 126 def update_draft @step = :step_1 :edit, @proposal @form = form(ProposalForm).from_params(params) UpdateProposal.call(@form, current_user, @proposal) do on(:ok) do |proposal| flash[:notice] = I18n.t("proposals.update_draft.success", scope: "decidim") redirect_to Decidim::ResourceLocatorPresenter.new(proposal).path + "/preview" end on(:invalid) do flash.now[:alert] = I18n.t("proposals.update_draft.error", scope: "decidim") render :edit_draft end end end |
#withdraw ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'app/controllers/decidim/proposals/proposals_controller.rb', line 185 def withdraw @proposal = Proposal.published.not_hidden.where(component: current_component).find(params[:id]) :withdraw, @proposal WithdrawProposal.call(@proposal, current_user) do on(:ok) do |_proposal| flash[:notice] = I18n.t("proposals.update.success", scope: "decidim") redirect_to Decidim::ResourceLocatorPresenter.new(@proposal).path end on(:invalid) do flash[:alert] = I18n.t("proposals.update.error", scope: "decidim") redirect_to Decidim::ResourceLocatorPresenter.new(@proposal).path end end end |