Class: Bulkrax::ExportersController

Inherits:
ApplicationController show all
Includes:
DatatablesBehavior, DownloadBehavior, Hyrax::ThemedLayoutController
Defined in:
app/controllers/bulkrax/exporters_controller.rb

Instance Method Summary collapse

Methods included from DatatablesBehavior

#download_zip, #entry_table_search, #entry_util_links, #exporter_table_search, #exporter_util_links, #format_entries, #format_exporters, #format_importers, #importer_table_search, #importer_util_links, #order_value, #status_message_for, #table_order, #table_page, #table_per_page

Methods included from DownloadBehavior

#content_head, #content_options, #download_content_type, #file, #file_name, #prepare_file_headers, #send_content, #send_file_contents

Instance Method Details

#createObject

POST /exporters



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/bulkrax/exporters_controller.rb', line 67

def create
  @exporter = Exporter.new(exporter_params)
  field_mapping_params

  if @exporter.save
    if params[:commit] == 'Create and Export'
      # Use perform now for export
      Bulkrax::ExporterJob.perform_later(@exporter.id)
      message = 'Exporter was successfully created. A download link will appear once it completes.'
    else
      message = 'Exporter was successfully created.'
    end
    redirect_to exporters_path, notice: message
  else
    render :new
  end
end

#destroyObject

DELETE /exporters/1



102
103
104
105
# File 'app/controllers/bulkrax/exporters_controller.rb', line 102

def destroy
  @exporter.destroy
  redirect_to exporters_url, notice: 'Exporter was successfully destroyed.'
end

#downloadObject

GET /exporters/1/download



108
109
110
111
# File 'app/controllers/bulkrax/exporters_controller.rb', line 108

def download
  @exporter = Exporter.find(params[:exporter_id])
  send_content
end

#editObject

GET /exporters/1/edit



55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/bulkrax/exporters_controller.rb', line 55

def edit
  if defined?(::Hyrax)
    add_exporter_breadcrumbs
    add_breadcrumb @exporter.name, bulkrax.exporter_path(@exporter.id)
    add_breadcrumb 'Edit'
  end

  # Correctly populate export_source_collection input
  @collection = Bulkrax.object_factory.find(@exporter.export_source) if @exporter.export_source.present? && @exporter.export_from == 'collection'
end

#entry_tableObject



38
39
40
41
42
43
44
# File 'app/controllers/bulkrax/exporters_controller.rb', line 38

def entry_table
  @entries = @exporter.entries.order(table_order).page(table_page).per(table_per_page)
  @entries = @entries.where(entry_table_search) if entry_table_search.present?
  respond_to do |format|
    format.json { render json: format_entries(@entries, @exporter) }
  end
end

#exporter_tableObject



21
22
23
24
25
26
27
# File 'app/controllers/bulkrax/exporters_controller.rb', line 21

def exporter_table
  @exporters = Exporter.order(table_order).page(table_page).per(table_per_page)
  @exporters = @exporters.where(exporter_table_search) if exporter_table_search.present?
  respond_to do |format|
    format.json { render json: format_exporters(@exporters) }
  end
end

#indexObject

GET /exporters



14
15
16
17
18
19
# File 'app/controllers/bulkrax/exporters_controller.rb', line 14

def index
  # NOTE: We're paginating this in the browser.
  @exporters = Exporter.order(created_at: :desc).all

  add_exporter_breadcrumbs if defined?(::Hyrax)
end

#newObject

GET /exporters/new



47
48
49
50
51
52
# File 'app/controllers/bulkrax/exporters_controller.rb', line 47

def new
  @exporter = Exporter.new
  return unless defined?(::Hyrax)
  add_exporter_breadcrumbs
  add_breadcrumb 'New'
end

#showObject

GET /exporters/1



30
31
32
33
34
35
36
# File 'app/controllers/bulkrax/exporters_controller.rb', line 30

def show
  if defined?(::Hyrax)
    add_exporter_breadcrumbs
    add_breadcrumb @exporter.name
  end
  @first_entry = @exporter.entries.first
end

#updateObject

PATCH/PUT /exporters/1



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/bulkrax/exporters_controller.rb', line 86

def update
  field_mapping_params
  if @exporter.update(exporter_params)
    if params[:commit] == 'Update and Re-Export All Items'
      Bulkrax::ExporterJob.perform_later(@exporter.id)
      message = 'Exporter was successfully updated. A download link will appear once it completes.'
    else
      'Exporter was successfully updated.'
    end
    redirect_to exporters_path, notice: message
  else
    render :edit
  end
end