Skip to content

Commit

Permalink
Fix shared search links (#1823)
Browse files Browse the repository at this point in the history
* Fix shared search links

Fixes:
* homepage `View All Collections` button
* catalog Collection title links
* catalog Work thumbnail links
Activates:
* catalog Collection thumbnail links

* Fix links

* Appease rubocop

* Fix alignment

* Use decorator instead of module_eval

* Update app/helpers/blacklight/catalog_helper_behavior_decorator.rb

Co-authored-by: Shana Moore <shana@scientist.com>
  • Loading branch information
laritakr and ShanaLMoore authored Jul 13, 2022
1 parent 0a6d047 commit 43f5d94
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 8 deletions.
37 changes: 37 additions & 0 deletions app/helpers/blacklight/catalog_helper_behavior_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

# OVERRIDE blacklight 6 to allow full url for show links for shared search thumbnail
module Blacklight
module CatalogHelperBehaviorDecorator
def render_thumbnail_tag(document, image_options = {}, url_options = {})
value = if blacklight_config.view_config(document_index_view_type).thumbnail_method
send(blacklight_config.view_config(document_index_view_type).thumbnail_method, document, image_options)
elsif blacklight_config.view_config(document_index_view_type).thumbnail_field
url = thumbnail_url(document)
image_tag url, image_options if url.present?
end

# rubocop:disable Style/GuardClause
if value
if url_options == false
# rubocop:disable Metrics/LineLength
Deprecation.warn(self, "passing false as the second argument to render_thumbnail_tag is deprecated. Use suppress_link: true instead. This behavior will be removed in Blacklight 7")
# rubocop:enable Metrics/LineLength
url_options = { suppress_link: true }
end
if url_options[:suppress_link]
value
elsif url_options[:full_url]
link_to generate_work_url(document.to_h, request) do
value
end
else
link_to_document document, value, url_options
end
end
# rubocop:enable Style/GuardClause
end
end
end

Blacklight::CatalogHelperBehavior.prepend(Blacklight::CatalogHelperBehaviorDecorator)
9 changes: 6 additions & 3 deletions app/helpers/shared_search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

module SharedSearchHelper
def generate_work_url(model, request)
return model unless current_account.search_only?

# needed because some attributes eg id is a symbol 7 others are string
model = model.to_h.with_indifferent_access

Expand All @@ -22,7 +20,12 @@ def generate_work_url(model, request)
def get_url(id:, request:, account_cname:, has_model:)
new_url = "#{request[:request_protocol]}#{account_cname || request[:request_host]}"
new_url += ":#{request[:request_port]}" if Rails.env.development? || Rails.env.test?
new_url += "/concern/#{has_model}/#{id}"
new_url += case has_model
when "collections"
"/#{has_model}/#{id}"
else
"/concern/#{has_model}/#{id}"
end
new_url
end
end
10 changes: 5 additions & 5 deletions app/indexers/collection_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class CollectionIndexer < Hyrax::CollectionIndexer
include Hyrax::IndexesBasicMetadata

# Uncomment this block if you want to add custom indexing behavior:
# def generate_solr_document
# super.tap do |solr_doc|
# solr_doc['my_custom_field_ssim'] = object.my_custom_property
# end
# end
def generate_solr_document
super.tap do |solr_doc|
solr_doc["account_cname_tesim"] = Site.instance&.account&.cname
end
end
end
4 changes: 4 additions & 0 deletions app/views/catalog/_index_header_list_collection.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="search-results-title-row">
<h4 class="search-result-title"><%= link_to document.title_or_label, generate_work_url(document.to_h, request) %></h4>
<%= Hyrax::CollectionPresenter.new(document, current_ability).collection_type_badge %>
</div>
3 changes: 3 additions & 0 deletions app/views/catalog/_thumbnail_list_collection.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="col-md-2">
<%= render_thumbnail_tag document, {}, { full_url: true } %>
</div>
5 changes: 5 additions & 0 deletions app/views/catalog/_thumbnail_list_default.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="col-md-2">
<div class="list-thumbnail">
<%= render_thumbnail_tag document, {}, {full_url: true} %>
</div>
</div>
6 changes: 6 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class Application < Rails::Application
end
end

config.to_prepare do
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end

# resolve reloading issue in dev mode
config.paths.add 'app/helpers', eager_load: true

Expand Down

0 comments on commit 43f5d94

Please sign in to comment.