Class: Spotlight::Resources::UploadController

Inherits:
ApplicationController show all
Defined in:
app/controllers/spotlight/resources/upload_controller.rb

Overview

Creating new exhibit items from single-item entry forms or batch CSV upload

Instance Method Summary collapse

Methods included from Controller

#blacklight_config, #current_exhibit, #current_masthead, #current_masthead=, #default_masthead?, #exhibit_masthead?, #exhibit_search_action_url, #exhibit_search_facet_url, #search_action_url, #search_facet_url

Methods included from Config

#exhibit_specific_blacklight_config

Instance Method Details

#createObject

rubocop:disable Metrics/MethodLength



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/spotlight/resources/upload_controller.rb', line 26

def create
  @resource.attributes = resource_params

  if @resource.save_and_index
    flash[:notice] = t('spotlight.resources.upload.success')
    if params['add-and-continue']
      redirect_to new_exhibit_resources_upload_path(@resource.exhibit)
    else
      redirect_to admin_exhibit_catalog_index_path(@resource.exhibit, sort: :timestamp)
    end
  else
    flash[:error] = t('spotlight.resources.upload.error')
    redirect_to admin_exhibit_catalog_index_path(@resource.exhibit, sort: :timestamp)
  end
end

#csv_uploadObject

rubocop:enable Metrics/MethodLength



43
44
45
46
47
48
49
# File 'app/controllers/spotlight/resources/upload_controller.rb', line 43

def csv_upload
  file = csv_params[:url]
  csv = CSV.parse(file.read, headers: true, return_headers: false, encoding: 'utf-8').map(&:to_hash)
  Spotlight::AddUploadsFromCSV.perform_later(csv, current_exhibit, current_user)
  flash[:notice] = t('spotlight.resources.upload.csv.success', file_name: file.original_filename)
  redirect_to :back
end

#newObject



18
19
20
21
22
23
# File 'app/controllers/spotlight/resources/upload_controller.rb', line 18

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_index_path(@exhibit)
  add_breadcrumb t(:'spotlight.resources.upload.new.header'), new_exhibit_resources_upload_path(@exhibit)
end

#templateObject



51
52
53
# File 'app/controllers/spotlight/resources/upload_controller.rb', line 51

def template
  render text: CSV.generate { |csv| csv << data_param_keys.unshift(:url) }, content_type: 'text/csv'
end