Sha256: 1419b886780f87e7398b34fce30d70d9d10802a0a404a6c9fc8c08eaad4e614e

Contents?: true

Size: 1.72 KB

Versions: 10

Compression:

Stored size: 1.72 KB

Contents

module Spotlight
  ##
  # CRUD actions for exhibit resources
  class ResourcesController < Spotlight::ApplicationController
    before_action :authenticate_user!, except: [:show]

    load_and_authorize_resource :exhibit, class: Spotlight::Exhibit

    # explicit options support better subclassing
    load_and_authorize_resource through: :exhibit, instance_name: :resource, through_association: :resources

    helper_method :resource_class

    def new
      add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), exhibit_root_path(@exhibit)
      add_breadcrumb t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit)
      add_breadcrumb t(:'spotlight.curation.sidebar.items'), admin_exhibit_catalog_path(@exhibit)
      add_breadcrumb t(:'spotlight.resources.new.header'), new_exhibit_resource_path(@exhibit)

      render
    end

    def create
      if @resource.save_and_index
        redirect_to spotlight.admin_exhibit_catalog_path(@resource.exhibit, sort: :timestamp)
      else
        flash[:error] = @resource.errors.full_messages.to_sentence if @resource.errors.present?
        render action: 'new'
      end
    end
    alias update create

    def monitor
      render json: current_exhibit.reindex_progress
    end

    def reindex_all
      @exhibit.reindex_later

      redirect_to admin_exhibit_catalog_path(@exhibit), notice: t(:'spotlight.resources.reindexing_in_progress')
    end

    protected

    def resource_class
      Spotlight::Resource
    end

    def resource_params
      params.require(:resource).tap { |x| x['type'] ||= resource_class.name }
            .permit(:url, :type, *resource_class.stored_attributes[:data], data: params[:resource][:data].try(:keys))
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
blacklight-spotlight-0.31.0 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.30.0 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.29.1 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.29.0 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.28.3 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.28.2 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.28.1 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.28.0 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.27.0 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.26.1 app/controllers/spotlight/resources_controller.rb