Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for downloading the original file #958

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/controllers/bulkrax/importers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ImportersController < ::Bulkrax::ApplicationController
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, :entry_table, :edit, :update, :destroy]
before_action :set_importer, only: [:show, :entry_table, :edit, :update, :destroy, :original_file]
with_themed_layout 'dashboard' if defined?(::Hyrax)

# GET /importers
Expand Down Expand Up @@ -201,6 +201,14 @@ def external_sets
end
end

def original_file
if @importer.original_file?
send_file @importer.original_file
else
redirect_to @importer, alert: 'Importer does not support file re-download or the imported file is not found on the server.'
end
end

# GET /importers/1/export_errors
def export_errors
@importer = Importer.find(params[:importer_id])
Expand Down
8 changes: 8 additions & 0 deletions app/models/bulkrax/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def seen
@seen ||= {}
end

def original_file?
File.exist?(self.parser_fields['import_file_path'])
end

def original_file
self.parser_fields['import_file_path'] if original_file?
end

def replace_files
self.parser_fields['replace_files']
end
Expand Down
10 changes: 5 additions & 5 deletions app/views/bulkrax/importers/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="col-xs-12 main-header">
<h1><span class="fa fa-cloud-upload" aria-hidden="true"></span> Importer: <%= @importer.name %></h1>

<% if @importer.failed_entries? %>
<div class="pull-right">
<div class="pull-right">
<%= link_to 'Download Original File', importer_original_file_path(@importer.id), class: 'btn btn-primary', data: { turbolinks: false } if @importer.original_file %>
<% if @importer.failed_entries? %>
<%= link_to 'Export Errored Entries', importer_export_errors_path(@importer.id), class: 'btn btn-primary', data: { turbolinks: false }%>
<%= link_to 'Upload Corrected Entries', importer_upload_corrected_entries_path(@importer.id), class: 'btn btn-primary' if @importer.parser.is_a?(Bulkrax::CsvParser) %>
</div>
<% end %>
<% end %>
</div>
</div>
<div class="panel panel-default bulkrax-align-text">
<div class="panel-body">
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
end
resources :importers do
put :continue
get :original_file
get :entry_table
get :export_errors
collection do
Expand Down
Loading