app/controllers/bulkrax/importers_controller.rb in bulkrax-6.0.1 vs app/controllers/bulkrax/importers_controller.rb in bulkrax-7.0.0
- old
+ new
@@ -1,49 +1,61 @@
# frozen_string_literal: true
-require_dependency 'bulkrax/application_controller'
-require_dependency 'oai'
-
module Bulkrax
# rubocop:disable Metrics/ClassLength
- class ImportersController < ApplicationController
+ class ImportersController < ::Bulkrax::ApplicationController
include Hyrax::ThemedLayoutController if defined?(::Hyrax)
include Bulkrax::DownloadBehavior
include Bulkrax::API
+ include Bulkrax::DatatablesBehavior
include Bulkrax::ValidationHelper
protect_from_forgery unless: -> { api_request? }
before_action :token_authenticate!, if: -> { api_request? }, only: [:create, :update, :delete]
before_action :authenticate_user!, unless: -> { api_request? }
before_action :check_permissions
- before_action :set_importer, only: [:show, :edit, :update, :destroy]
+ before_action :set_importer, only: [:show, :entry_table, :edit, :update, :destroy]
with_themed_layout 'dashboard' if defined?(::Hyrax)
# GET /importers
def index
# NOTE: We're paginating this in the browser.
- @importers = Importer.order(created_at: :desc).all
if api_request?
+ @importers = Importer.order(created_at: :desc).all
json_response('index')
elsif defined?(::Hyrax)
add_importer_breadcrumbs
end
end
+ def importer_table
+ @importers = Importer.order(table_order).page(table_page).per(table_per_page)
+ @importers = @importers.where(importer_table_search) if importer_table_search.present?
+ respond_to do |format|
+ format.json { render json: format_importers(@importers) }
+ end
+ end
+
# GET /importers/1
def show
if api_request?
json_response('show')
elsif defined?(::Hyrax)
add_importer_breadcrumbs
add_breadcrumb @importer.name
end
- @work_entries = @importer.entries.where(type: @importer.parser.entry_class.to_s).page(params[:work_entries_page]).per(30)
- @collection_entries = @importer.entries.where(type: @importer.parser.collection_entry_class.to_s).page(params[:collections_entries_page]).per(30)
- @file_set_entries = @importer.entries.where(type: @importer.parser.file_set_entry_class.to_s).page(params[:file_set_entries_page]).per(30)
+ @first_entry = @importer.entries.first
end
+ def entry_table
+ @entries = @importer.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, @importer) }
+ end
+ end
+
# GET /importers/new
def new
@importer = Importer.new
if api_request?
json_response('new')
@@ -211,19 +223,19 @@
@importer.save
end
# Use callbacks to share common setup or constraints between actions.
def set_importer
- @importer = Importer.find(params[:id])
+ @importer = Importer.find(params[:id] || params[:importer_id])
end
def importable_params
params.except(:selected_files)
end
def importable_parser_fields
- params&.[](:importer)&.[](:parser_fields)&.except(:file)&.keys
+ params&.[](:importer)&.[](:parser_fields)&.except(:file, :entry_statuses)&.keys&. + [{ "entry_statuses" => [] }]
end
# Only allow a trusted parameters through.
def importer_params
importable_params.require(:importer).permit(
@@ -308,13 +320,19 @@
# OAI-only - selective re-harvest
params[:commit] == 'Update and Harvest Updated Items'
end
def set_files_parser_fields
+ @importer.parser_fields['update_files'] =
+ @importer.parser_fields['replace_files'] =
+ @importer.parser_fields['remove_and_rerun'] =
+ @importer.parser_fields['metadata_only'] = false
if params[:commit] == 'Update Metadata and Files'
@importer.parser_fields['update_files'] = true
elsif params[:commit] == ('Update and Replace Files' || 'Update and Re-Harvest All Items')
@importer.parser_fields['replace_files'] = true
+ elsif params[:commit] == 'Remove and Rerun'
+ @importer.parser_fields['remove_and_rerun'] = true
elsif params[:commit] == 'Update and Harvest Updated Items'
return
else
@importer.parser_fields['metadata_only'] = true
end