Sha256: b595106a964448c8dc1aa2c265a4d2ce87d8ef2356101e4734827d4db840cad9

Contents?: true

Size: 1.69 KB

Versions: 18

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

module Spotlight
  module Resources
    ##
    # Creating new exhibit items from single-item entry forms
    # or batch CSV upload
    class UploadController < Spotlight::ApplicationController
      helper :all

      before_action :authenticate_user!
      before_action :set_tab, only: %i[create]

      load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
      before_action :build_resource

      load_and_authorize_resource class: 'Spotlight::Resources::Upload', through_association: 'exhibit.resources', instance_name: 'resource'

      def create
        if @resource.save_and_index
          flash[:notice] = t('spotlight.resources.upload.success')
          return redirect_to new_exhibit_resource_path(@resource.exhibit, tab: :upload) if params['add-and-continue']
        else
          flash[:error] = t('spotlight.resources.upload.error')
        end

        redirect_to admin_exhibit_catalog_path(@resource.exhibit, sort: :timestamp)
      end

      private

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

      def build_resource
        @resource ||= begin
          resource = Spotlight::Resources::Upload.new exhibit: current_exhibit
          resource.attributes = resource_params
          resource.build_upload(image: params[:resources_upload][:url]) if params[:resources_upload][:url]

          resource
        end
      end

      def resource_params
        params.require(:resources_upload).permit(data: data_param_keys)
      end

      def data_param_keys
        Spotlight::Resources::Upload.fields(current_exhibit).map(&:field_name) +
          current_exhibit.custom_fields.as_strong_params
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
blacklight-spotlight-4.3.6 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.3.5 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.3.4 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.3.3 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.3.2 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.3.1 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.3.0 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.2.0 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.1.2 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.1.1 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.1.0 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.0.3 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.0.2 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.0.1 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-4.0.0 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-3.6.0.beta10 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-3.6.0.beta9 app/controllers/spotlight/resources/upload_controller.rb
blacklight-spotlight-3.6.0.beta8 app/controllers/spotlight/resources/upload_controller.rb