Class: Decidim::Plans::Admin::TagsController
- Inherits:
-
ApplicationController
- Object
- Admin::Components::BaseController
- ApplicationController
- Decidim::Plans::Admin::TagsController
- Includes:
- TranslatableAttributes
- Defined in:
- app/controllers/decidim/plans/admin/tags_controller.rb
Overview
This controller allows admins to the tags related to plans.
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/decidim/plans/admin/tags_controller.rb', line 46 def create :create, :plan_tags @form = form(Admin::TagForm).from_params(params) Admin::CreateTag.call(@form) do on(:ok) do flash[:notice] = I18n.t("create.success", scope: i18n_flashes_scope) return redirect_to taggings_plan_path(plan) if @form.back_to_plan == true redirect_to (plan) end on(:invalid) do flash.now[:alert] = I18n.t("create.invalid", scope: i18n_flashes_scope) render action: "new" end end end |
#destroy ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/decidim/plans/admin/tags_controller.rb', line 88 def destroy :destroy, :plan_tags, tag: tag Admin::DestroyTag.call(@tag, current_user) do on(:ok) do flash[:notice] = I18n.t("destroy.success", scope: i18n_flashes_scope) redirect_to (plan) end on(:invalid) do flash.now[:alert] = I18n.t("destroy.error", scope: i18n_flashes_scope) redirect_to (plan) end end end |
#edit ⇒ Object
66 67 68 69 |
# File 'app/controllers/decidim/plans/admin/tags_controller.rb', line 66 def edit :edit, :plan_tags, tag: tag @form = form(Admin::TagForm).from_model(tag) end |
#index ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/decidim/plans/admin/tags_controller.rb', line 12 def index :read, :plan_tag respond_to do |format| format.html do render :index end format.json do return render json: [] unless params.has_key?(:term) = OrganizationTags.new(current_organization).query.where( "name ->> '#{current_locale}' ILIKE ?", "%#{params[:term]}%" ).where.not( id: plan..pluck(:id) ) render json: .map { |t| [t.id, translated_attribute(t.name)] } end end end |
#new ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/decidim/plans/admin/tags_controller.rb', line 33 def new :create, :plan_tags dummy_tag = Tag.new(organization: current_organization) dummy_tag.name = {} current_organization.available_locales.map do |locale| dummy_tag.name[locale] = params[:name] end @form = form(Admin::TagForm).from_model(dummy_tag) @form.back_to_plan = true if params[:back_to_plan].to_i == 1 end |
#update ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/decidim/plans/admin/tags_controller.rb', line 71 def update :edit, :plan_tags, tag: tag @form = form(Admin::TagForm).from_params(params) Admin::UpdateTag.call(@form, @tag) do on(:ok) do flash[:notice] = I18n.t("update.success", scope: i18n_flashes_scope) redirect_to (plan) end on(:invalid) do flash.now[:alert] = I18n.t("update.invalid", scope: i18n_flashes_scope) render :edit end end end |