app/controllers/decidim/plans/admin/plans_controller.rb in decidim-plans-0.16.6 vs app/controllers/decidim/plans/admin/plans_controller.rb in decidim-plans-0.16.7
- old
+ new
@@ -9,11 +9,11 @@
include Plans::AttachedProposalsHelper
helper Plans::ApplicationHelper
helper Plans::AttachmentsHelper
helper Plans::RemainingCharactersHelper
- helper_method :plans, :query, :form_presenter, :attached_proposals_picker_field
+ helper_method :plans, :plan, :query, :counts, :form_presenter, :attached_proposals_picker_field
def new
enforce_permission_to :create, :plans
@form = form(Admin::PlanForm).from_model(Plan.new(component: current_component))
end
@@ -87,17 +87,47 @@
redirect_to plans_path
end
end
end
+ def taggings
+ enforce_permission_to :edit_taggings, :plan, plan: plan
+
+ @form = form(Admin::TaggingsForm).from_model(plan)
+ end
+
+ def update_taggings
+ enforce_permission_to :edit_taggings, :plan, plan: plan
+
+ @form = form(Admin::TaggingsForm).from_params(params)
+ Admin::UpdatePlanTaggings.call(@form, plan) do
+ on(:ok) do
+ flash[:notice] = I18n.t("plans.update_taggings.success", scope: "decidim.plans.admin")
+ redirect_to plans_path
+ end
+
+ on(:invalid) do
+ flash.now[:alert] = I18n.t("plans.update_taggings.invalid", scope: "decidim.plans.admin")
+ render :taggings
+ end
+ end
+ end
+
private
def query
- @query ||= Plan.where(component: current_component).ransack(params[:q])
+ @query ||= Plan.published.where(component: current_component).ransack(params[:q])
end
def plans
@plans ||= query.result.page(params[:page]).per(15)
+ end
+
+ def counts
+ @counts ||= {
+ published: Plan.published.where(component: current_component).count,
+ drafts: Plan.drafts.where(component: current_component).count
+ }
end
def plan
@plan ||= Plan.where(component: current_component).find(params[:id])
end