diff --git a/app/controllers/hyrax/dashboard/collections_controller_decorator.rb b/app/controllers/hyrax/dashboard/collections_controller_decorator.rb index cc2246a90..a4891ed86 100644 --- a/app/controllers/hyrax/dashboard/collections_controller_decorator.rb +++ b/app/controllers/hyrax/dashboard/collections_controller_decorator.rb @@ -5,6 +5,7 @@ # - ensure user is allowed to change visibility # - add the ability to upload a collection thumbnail # - add altext to collection banner +# @TODO clean up of unnecessary methods now that we are using Valkyrie transactions to set branding module Hyrax module Dashboard @@ -45,7 +46,7 @@ def update_valkyrie_collection def edit form # Gets original filename of an uploaded thumbnail. See #update - return unless ::SolrDocument.find(@collection.id).thumbnail_path.include?("uploaded_collection_thumbnails") && uploaded_thumbnail? + return unless ::SolrDocument.find(@collection.id).thumbnail_path&.include?("uploaded_collection_thumbnails") && uploaded_thumbnail? @thumbnail_filename = File.basename(uploaded_thumbnail_files.reject { |f| File.basename(f).include? @collection.id }.first) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3d5147577..63605958c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -12,17 +12,33 @@ def group_navigation_presenter @group_navigation_presenter ||= Hyku::Admin::Group::NavigationPresenter.new(params:) end - 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? + # Return collection thumbnail formatted for display: + # - use collection's branding thumbnail if it exists + # - use site's default collection image if one exists + # - fallback to Hyrax's default image + def collection_thumbnail(document, _image_options = {}, url_options = {}) + view_class = url_options[:class] + # The correct thumbnail SHOULD be indexed on the object + return image_tag(document['thumbnail_path_ss'], class: view_class, alt: alttext_for(document)) if document['thumbnail_path_ss'].present? - image_tag(Site.instance.default_collection_image&.url) + # If nothing is indexed, we just fall back to site default + return image_tag(Site.instance.default_collection_image&.url, alt: alttext_for(document), class: view_class) unless Site.instance.default_collection_image.blank? + + # fall back to Hyrax default if no site default + tag.span("", class: [Hyrax::ModelIcon.css_class_for(::Collection), view_class], + alt: alttext_for(document)) end def label_for(term:, record_class: nil) locale_for(type: 'labels', term:, record_class:) end + def alttext_for(collection) + thumbnail = CollectionBrandingInfo.where(collection_id: collection.id, role: "thumbnail")&.first + return thumbnail.alt_text if thumbnail + block_for(name: 'default_collection_image_text') || "#{collection.title_or_label} #{t('hyrax.dashboard.my.sr.thumbnail')}" + end + def hint_for(term:, record_class: nil) hint = locale_for(type: 'hints', term:, record_class:) diff --git a/app/presenters/hyrax/collection_presenter_decorator.rb b/app/presenters/hyrax/collection_presenter_decorator.rb index faf1e2fdb..64f010e09 100644 --- a/app/presenters/hyrax/collection_presenter_decorator.rb +++ b/app/presenters/hyrax/collection_presenter_decorator.rb @@ -81,14 +81,9 @@ def banner_file end end + # use either the indexed thumbnail or find the branding for the collection 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 + @thumbnail_file ||= collection_thumbnail(solr_document) end # Begin Featured Collections Methods diff --git a/app/services/hyrax/thumbnail_path_service_decorator.rb b/app/services/hyrax/thumbnail_path_service_decorator.rb index 2f44abbff..5c07588c2 100644 --- a/app/services/hyrax/thumbnail_path_service_decorator.rb +++ b/app/services/hyrax/thumbnail_path_service_decorator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# OVERRIDE Hyrax v5.0.0rc2 - use site defaults instead of app wide defaults +# OVERRIDE Hyrax v5.0.0rc2 - index using site defaults instead of app wide defaults module Hyrax module ThumbnailPathServiceDecorator @@ -10,7 +10,11 @@ def call(object) 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 + default_collection_image + end + + def default_collection_image + Site.instance.default_collection_image&.url || ActionController::Base.helpers.image_path('default.png') end def default_image diff --git a/app/views/hyrax/collections/_media_display.html.erb b/app/views/hyrax/collections/_media_display.html.erb index 9dbeb6cbb..1af484ff4 100644 --- a/app/views/hyrax/collections/_media_display.html.erb +++ b/app/views/hyrax/collections/_media_display.html.erb @@ -1,8 +1,3 @@ -<% if presenter.thumbnail_path %> - <%= image_tag presenter.thumbnail_path, - class: "representative-media", - alt: block_for(name: 'default_collection_image_text'), - role: "presentation" %> -<% else %> - <%= image_tag(Site.instance.default_collection_image) %> -<% end %> +<%# OVERRIDE Hyrax 6.0: %> +<%# show uploaded thumbnail or default with alttext %> +<%= collection_thumbnail(presenter.solr_document, "", {class: "representative-media"}) %> diff --git a/app/views/hyrax/dashboard/collections/_list_collections.html.erb b/app/views/hyrax/dashboard/collections/_list_collections.html.erb index 61fd4a3da..7d0f5bfcc 100644 --- a/app/views/hyrax/dashboard/collections/_list_collections.html.erb +++ b/app/views/hyrax/dashboard/collections/_list_collections.html.erb @@ -22,19 +22,14 @@