-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from pulibrary/browse_everything_pending_uploads
Add PendingUploads
- Loading branch information
Showing
13 changed files
with
130 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,18 @@ | ||
# frozen_string_literal: true | ||
class BrowseEverythingIngestJob < ApplicationJob | ||
def perform(resource_id, controller_scope_string, selected_files) | ||
def perform(resource_id, controller_scope_string, pending_upload_ids) | ||
controller_scope = controller_scope_string.constantize | ||
change_set_persister = controller_scope.change_set_persister | ||
change_set_class = controller_scope.change_set_class | ||
resource = change_set_persister.metadata_adapter.query_service.find_by(id: Valkyrie::ID.new(resource_id)) | ||
|
||
change_set = change_set_class.new(resource) | ||
selected_files = selected_files.values.map do |x| | ||
BrowseEverythingFile.new(x.symbolize_keys) | ||
end | ||
change_set.validate(files: selected_files) | ||
change_set_persister.save(change_set: change_set) | ||
end | ||
|
||
class BrowseEverythingFile | ||
def initialize(file_name:, file_size:, url:) | ||
@file_name = file_name | ||
@file_size = file_size | ||
@url = url | ||
end | ||
|
||
def original_filename | ||
@file_name | ||
end | ||
|
||
def content_type | ||
'text/plain' | ||
end | ||
|
||
def path | ||
copied_file_name | ||
end | ||
|
||
def copied_file_name | ||
return @copied_file_name if @copied_file_name | ||
BrowseEverything::Retriever.new.download("file_name" => @file_name, "file_size" => @file_size, "url" => @url) do |filename, _retrieved, _total| | ||
@copied_file_name = filename | ||
pending_upload_ids = pending_upload_ids.map { |x| Valkyrie::Types::ID[x] } | ||
change_set_persister.buffer_into_index do |buffered_changeset_persister| | ||
resource = buffered_changeset_persister.metadata_adapter.query_service.find_by(id: Valkyrie::ID.new(resource_id)) | ||
change_set = change_set_class.new(resource) | ||
selected_files = resource.pending_uploads.select do |pending_upload| | ||
pending_upload_ids.include?(pending_upload.id) | ||
end | ||
@copied_file_name | ||
change_set.validate(files: selected_files) | ||
buffered_changeset_persister.save(change_set: change_set) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
class PendingUpload < Valkyrie::Resource | ||
attribute :id, Valkyrie::Types::ID.optional | ||
attribute :file_name | ||
attribute :url | ||
attribute :file_size, Valkyrie::Types::Set.member(Valkyrie::Types::Coercible::Int) | ||
|
||
def original_filename | ||
@file_name.first | ||
end | ||
|
||
def content_type | ||
'text/plain' | ||
end | ||
|
||
def path | ||
copied_file_name | ||
end | ||
|
||
private | ||
|
||
def copied_file_name | ||
return @copied_file_name if @copied_file_name | ||
BrowseEverything::Retriever.new.download("file_name" => file_name.first, "file_size" => file_size.first, "url" => url.first) do |filename, _retrieved, _total| | ||
@copied_file_name = filename | ||
end | ||
@copied_file_name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
valhalla/app/views/valhalla/base/_pending_uploads.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<table class="table table-striped"> | ||
<caption>Pending Uploads</caption> | ||
<thead> | ||
<tr> | ||
<th>File Name</th> | ||
<th>Uploaded</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% uploads.map(&:decorate).each do |pending_upload| %> | ||
<tr> | ||
<td> | ||
<%= pending_upload.original_filename %> | ||
</td> | ||
<td> | ||
<%= pending_upload.created_at %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters