Sha256: 2d4dd3fa3b2b57806a41feb6ab36042f97523ca0eb505eec6795649579bb5a25

Contents?: true

Size: 1.79 KB

Versions: 55

Compression:

Stored size: 1.79 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?,
            exclude_ids: exclude_ids
          )
        )

        @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 exclude_ids
        if params[:exclude_ids].blank?
          []
        else
          Catalog::Category.in(id: params[:exclude_ids]).map { |c| Search::Admin.for(c).id }
        end
      end

      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

55 entries across 55 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.5.26 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.45 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.5.25 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.5.23 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.44 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.5.22 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.43 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.5.21 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.42 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.5.20 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.41 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.5.19 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.40 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.5.18 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.39 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.5.17 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.38 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.5.16 app/controllers/workarea/admin/catalog_categories_controller.rb
workarea-admin-3.4.37 app/controllers/workarea/admin/catalog_categories_controller.rb