-
Notifications
You must be signed in to change notification settings - Fork 49
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 #2206 from samvera/i205-upload-collection-thumbnails
🚧 i205 - add ability to upload collection thumbnails
- Loading branch information
Showing
19 changed files
with
520 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//= require hyrax/uploader | ||
// This file is the default initialization of the fileupload. If you want to call | ||
// hyraxUploader with other options (like afterSubmit), then override this file. | ||
Blacklight.onLoad(function() { | ||
var options = {}; | ||
$('#fileupload').hyraxUploader(options); | ||
$('#fileuploadlogo').hyraxUploader({downloadTemplateId: 'logo-template-download'}); | ||
$('#fileuploadthumbnail').hyraxUploader({downloadTemplateId: 'thumbnail-template-download'}); | ||
}); |
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
app/controllers/concerns/hyku/collection_branding_behavior.rb
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 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hyku | ||
module CollectionBrandingBehavior | ||
# This is used for saving the CollectionBrandingInfo files to 'public/uploads' directory. | ||
# | ||
# Originally, when `f.file_url` is called, there's a string sub that happens in | ||
# CarrierWave that puts it into the 'uploads' dir instead. We want it in the 'public/uploads' dir instead | ||
# @see https://github.com/carrierwaveuploader/carrierwave/blob/master/lib/carrierwave/uploader/url.rb#L24 | ||
def process_file_location(f) | ||
if /^http/.match?(f.file_url) | ||
f.file.download!(f.file_url) | ||
f.file_url | ||
elsif %r{^\/}.match?(f.file_url) | ||
f.file.path | ||
else | ||
f.file_url | ||
end | ||
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
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,7 +1,25 @@ | ||
# frozen_string_literal: true | ||
# OVERRIDE Hyraxv5.0.0 to add the ability to upload a collection thumbnail | ||
|
||
Hyrax::Forms::PcdmCollectionForm.class_eval do | ||
include Hyrax::FormFields(:basic_metadata) | ||
include Hyrax::FormFields(:bulkrax_metadata) | ||
include CollectionAccessFiltering | ||
|
||
ThumbnailInfoPrepopulator = lambda do |_options = nil| | ||
self.thumbnail_info ||= begin | ||
thumbnail_info = CollectionBrandingInfo.where(collection_id: id.to_s, role: "thumbnail").first | ||
if thumbnail_info | ||
thumbnail_file = File.split(thumbnail_info.local_path).last | ||
alttext = thumbnail_info.alt_text | ||
file_location = thumbnail_info.local_path | ||
relative_path = "/" + thumbnail_info.local_path.split("/")[-4..-1].join("/") | ||
{ file: thumbnail_file, full_path: file_location, relative_path:, alttext: } | ||
else | ||
{} # Always return at least an empty hash | ||
end | ||
end | ||
end | ||
|
||
property :thumbnail_info, virtual: true, prepopulator: ThumbnailInfoPrepopulator | ||
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
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
Oops, something went wrong.