Sha256: 373afc11cc0035df2ac2d51415b9acc96251f2b0e78d329bf6f50944f6aab277

Contents?: true

Size: 1.89 KB

Versions: 40

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

module Spotlight
  ##
  # CRUD actions for exhibit resources
  class ResourcesController < Spotlight::ApplicationController
    before_action :authenticate_user!, except: [:show]
    before_action :set_tab, only: %i[new create]

    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 current_user

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

    protected

    def set_tab
      @tab = params[:tab] || 'external_resources_form'
    end

    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

40 entries across 40 versions & 1 rubygems

Version Path
blacklight-spotlight-3.5.0.4 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.6.0.beta7 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.5.0.3 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.6.0.beta6 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.6.0.beta5 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.6.0.beta4 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.6.0.beta3 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.6.0.beta1 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.5.0.2 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.5.0.1 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.5.0 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.4.4.1 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.4.4 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.4.3 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.4.2.2 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.4.2.1 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.4.2 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.4.1 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.4.0 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-3.3.0 app/controllers/spotlight/resources_controller.rb