Class: Spotlight::BulkUpdatesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/spotlight/bulk_updates_controller.rb

Overview

Controller enabling bulk functionality for items defined in a spreadsheet.

Instance Method Summary collapse

Instance Method Details

#download_template ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/spotlight/bulk_updates_controller.rb', line 19

def download_template
  # Set Last-Modified as a work-around for https://github.com/rack/rack/issues/1619
  headers['Last-Modified'] = ''
  headers['Cache-Control'] = 'no-cache'
  headers['Content-Type'] = 'text/csv'
  headers['Content-Disposition'] = "attachment; filename=\"#{current_exhibit.slug}-bulk-update-template.csv\""
  headers.delete('Content-Length')

  stream_csv_template
end

#edit ⇒ Object



13
14
15
16
17
# File 'app/controllers/spotlight/bulk_updates_controller.rb', line 13

def edit
  add_breadcrumb(t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), @exhibit)
  add_breadcrumb(t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit))
  add_breadcrumb(t(:'spotlight.pages.index.bulk_updates.header'), edit_exhibit_bulk_updates_path(@exhibit))
end

#monitor ⇒ Object



40
41
42
# File 'app/controllers/spotlight/bulk_updates_controller.rb', line 40

def monitor
  render json: BackgroundJobProgress.new(current_exhibit, job_class: Spotlight::ProcessBulkUpdatesCsvJob)
end

#update ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'app/controllers/spotlight/bulk_updates_controller.rb', line 30

def update
  bulk_update = Spotlight::BulkUpdate.new(exhibit: current_exhibit, file: file_params)
  if bulk_update.save
    ProcessBulkUpdatesCsvJob.perform_later(current_exhibit, bulk_update)
    redirect_back_or_to(spotlight.edit_exhibit_bulk_updates_path(current_exhibit), notice: t(:'spotlight.bulk_updates.update.submitted'))
  else
    redirect_back_or_to(spotlight.edit_exhibit_bulk_updates_path(current_exhibit), alert: t(:'spotlight.bulk_updates.update.error'))
  end
end