diff --git a/app/assets/javascripts/hyrax/fileupload.js b/app/assets/javascripts/hyrax/fileupload.js
new file mode 100644
index 0000000000..bda9f4c911
--- /dev/null
+++ b/app/assets/javascripts/hyrax/fileupload.js
@@ -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'});
+});
diff --git a/app/assets/stylesheets/hyku.scss b/app/assets/stylesheets/hyku.scss
index 603a47c6d0..6b1fdd996d 100644
--- a/app/assets/stylesheets/hyku.scss
+++ b/app/assets/stylesheets/hyku.scss
@@ -645,3 +645,27 @@ span.constraint-value p, .facet-values p {
tr[data-feature="use-iiif-print"] {
display: none;
}
+
+// collection branding thumbnail
+.branding-thumbnail-row {
+ border-top: solid 1px #dddddd;
+ padding-top: 10px;
+}
+
+.branding-thumbnail-input {
+ text-align: right;
+ width: 250px;
+
+ input {
+ text-align: left;
+ }
+}
+
+.branding-thumbnail-remove,
+.branding-thumbnail-remove:hover {
+ background-color: #ffffff;
+ border-color: #ffffff;
+ color: $brand-danger;
+ font-weight: normal;
+ text-decoration: underline;
+}
diff --git a/app/controllers/concerns/hyku/collection_branding_behavior.rb b/app/controllers/concerns/hyku/collection_branding_behavior.rb
new file mode 100644
index 0000000000..2c540dbc46
--- /dev/null
+++ b/app/controllers/concerns/hyku/collection_branding_behavior.rb
@@ -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
diff --git a/app/controllers/hyrax/dashboard/collections_controller_decorator.rb b/app/controllers/hyrax/dashboard/collections_controller_decorator.rb
index e7dc0e7f7c..4056376c6e 100644
--- a/app/controllers/hyrax/dashboard/collections_controller_decorator.rb
+++ b/app/controllers/hyrax/dashboard/collections_controller_decorator.rb
@@ -3,27 +3,52 @@
# OVERRIDE Hyrax v5.0.0rc2
# - Fix file upload in logo and banner
# - Use work titles for collection thumbnail select & to add an option to reset to the default thumbnail
+
+# OVERRIDE Hyrax v5.0.0 to add the ability to upload a collection thumbnail
+
module Hyrax
module Dashboard
## Shows a list of all collections to the admins
# rubocop:disable Metrics/ModuleLength
module CollectionsControllerDecorator
+ include Hyku::CollectionBrandingBehavior
+
def show
configure_show_sort_fields
super
end
- private
-
- def configure_show_sort_fields
- # In the CollectionsControllerDecorator, we clear the sort fields and add our own to have
- # the ability to sort the index with custom fields. However, this also affects the show page.
- # Here we set the sort fields back to the defaults for the show page.
- blacklight_config.sort_fields = CatalogController.blacklight_config.sort_fields
+ # OVERRIDE Hyrax v5.0.0 to add the ability to upload a collection thumbnail - START
+ def process_branding
+ process_banner_input
+ process_logo_input
+ process_thumbnail_input
end
- public
+ # rubocop:disable Metrics/AbcSize
+ def update_valkyrie_collection
+ return after_update_errors(form_err_msg(form)) unless form.validate(collection_params)
+
+ result = transactions['change_set.update_collection']
+ .with_step_args(
+ 'collection_resource.save_collection_banner' => { update_banner_file_ids: params["banner_files"],
+ banner_unchanged_indicator: params["banner_unchanged"] },
+ 'collection_resource.save_collection_logo' => { update_logo_file_ids: params["logo_files"],
+ alttext_values: params["alttext"],
+ linkurl_values: params["linkurl"] },
+ 'collection_resource.save_collection_thumbnail' => { update_thumbnail_file_ids: params["thumbnail_files"],
+ thumbnail_unchanged_indicator: params["thumbnail_unchanged"],
+ alttext_values: params["thumbnail_text"] }
+ )
+ .call(form)
+ @collection = result.value_or { return after_update_errors(result.failure.first) }
+
+ process_member_changes
+ after_update_response
+ end
+ # rubocop:enable Metrics/AbcSize
+ # OVERRIDE Hyrax v5.0.0 to add the ability to upload a collection thumbnail - END
def edit
form
@@ -47,13 +72,6 @@ def update
super
end
- def process_branding
- super
-
- # TODO: does this still work?
- process_uploaded_thumbnail(params[:collection][:thumbnail_upload]) if params[:collection][:thumbnail_upload]
- end
-
# Deletes any previous thumbnails. The thumbnail indexer (see services/hyrax/indexes_thumbnails)
# checks if an uploaded thumbnail exists in the public folder before indexing the thumbnail path.
def delete_uploaded_thumbnail
@@ -99,6 +117,13 @@ def files
private
+ def configure_show_sort_fields
+ # In the CollectionsControllerDecorator, we clear the sort fields and add our own to have
+ # the ability to sort the index with custom fields. However, this also affects the show page.
+ # Here we set the sort fields back to the defaults for the show page.
+ blacklight_config.sort_fields = CatalogController.blacklight_config.sort_fields
+ end
+
# branding specific methods
def process_banner_input
return update_existing_banner if params["banner_unchanged"] == "true"
@@ -166,19 +191,6 @@ def process_uploaded_thumbnail(uploaded_file)
File.chmod(0o664, "#{dir_name}/#{@collection.id}_card.jpg")
end
# rubocop:enable Metrics/MethodLength
-
- ## OVERRIDE Hyrax v5.0.0rc2 handle file locations
- 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 OVERRIDE
end
end
end
diff --git a/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb b/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb
index d7765a6f5b..ee5e377533 100644
--- a/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb
+++ b/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb
@@ -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
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index fd8844b4d8..3d51475777 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -12,7 +12,8 @@ def group_navigation_presenter
@group_navigation_presenter ||= Hyku::Admin::Group::NavigationPresenter.new(params:)
end
- def collection_thumbnail(_document, _image_options = {}, _url_options = {})
+ def collection_thumbnail(document, _image_options = {}, _url_options = {})
+ return image_tag(document['thumbnail_path_ss']) if document['thumbnail_path_ss'].present?
return super if Site.instance.default_collection_image.blank?
image_tag(Site.instance.default_collection_image&.url)
diff --git a/app/presenters/hyrax/collection_presenter_decorator.rb b/app/presenters/hyrax/collection_presenter_decorator.rb
index 7b3efc0505..faf1e2fdb6 100644
--- a/app/presenters/hyrax/collection_presenter_decorator.rb
+++ b/app/presenters/hyrax/collection_presenter_decorator.rb
@@ -81,6 +81,16 @@ def banner_file
end
end
+ def thumbnail_file
+ @thumbnail_file ||= CollectionBrandingInfo.where(collection_id: id, role: "thumbnail")
+ .select(:local_path, :alt_text, :target_url).map do |thumbnail|
+ { alttext: thumbnail.alt_text,
+ file: File.split(thumbnail.local_path).last,
+ file_location: "/#{thumbnail.local_path.split('/')[-4..-1].join('/')}",
+ linkurl: thumbnail.target_url }
+ end
+ end
+
# Begin Featured Collections Methods
def collection_featurable?
user_can_feature_collection? && solr_document.public?
diff --git a/app/services/hyrax/thumbnail_path_service_decorator.rb b/app/services/hyrax/thumbnail_path_service_decorator.rb
index 4cbc7d8b9a..2f44abbff1 100644
--- a/app/services/hyrax/thumbnail_path_service_decorator.rb
+++ b/app/services/hyrax/thumbnail_path_service_decorator.rb
@@ -4,6 +4,15 @@
module Hyrax
module ThumbnailPathServiceDecorator
+ def call(object)
+ return super unless object.try(:collection?)
+
+ collection_thumbnail = CollectionBrandingInfo.where(collection_id: object.id.to_s, role: "thumbnail").first
+ return collection_thumbnail.local_path.gsub(Rails.public_path.to_s, '') if collection_thumbnail
+
+ default_image
+ end
+
def default_image
Site.instance.default_work_image&.url || super
end
diff --git a/app/views/hyrax/dashboard/collections/_form_branding.html.erb b/app/views/hyrax/dashboard/collections/_form_branding.html.erb
index 14df747e2f..49465c2ee6 100644
--- a/app/views/hyrax/dashboard/collections/_form_branding.html.erb
+++ b/app/views/hyrax/dashboard/collections/_form_branding.html.erb
@@ -163,4 +163,81 @@
+
+
+
<%= t('.thumbnail.description') %>
+
+
+
+
+
+
+
+
+
+
+
+
+ <%= t('.choose_file') %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <%# Where the request to display the branding comes from. %>
+ <% if f.object.thumbnail_info[:file] %>
+