Sha256: 75807a30a65e09338e074b9873e2e5a972ddcf2b899ce93acc3c168bef3e769c

Contents?: true

Size: 1.54 KB

Versions: 7

Compression:

Stored size: 1.54 KB

Contents

module Workarea
  module Admin
    class CatalogCategoriesController < Admin::ApplicationController
      required_permissions :catalog

      before_action :check_publishing_authorization
      before_action :find_category, except: :index
      after_action :track_index_filters, only: :index

      def index
        search = Search::AdminCategories.new(
          params.merge(autocomplete: request.xhr?)
        )

        @search = SearchViewModel.new(search, view_model_options)
      end

      def show
      end

      def edit
      end

      def update
        set_range_facets
        @category.save

        if @category.update_attributes(params[:category])
          flash[:success] = t('workarea.admin.catalog_categories.flash_messages.saved')
          redirect_to catalog_category_path(@category)
        else
          render :edit, status: :unprocessable_entity
        end
      end

      def insights
      end

      def destroy
        @category.destroy
        flash[:success] = t('workarea.admin.catalog_categories.flash_messages.removed')
        redirect_to catalog_categories_path
      end

      private

      def find_category
        if params[:id].present?
          @category = Catalog::Category.find_by(slug: params[:id])
        else
          @category = Catalog::Category.new(params[:category])
        end

        @category = CategoryViewModel.new(@category, view_model_options)
      end

      def set_range_facets
        @category.range_facets = CleanRangeFacets.new(params[:range_facets]).result
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
workarea-admin-3.4.18 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.17 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.16 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.15 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.14 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.13 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.12 app/controllers/workarea/admin/catalog_categories_controller.rb