-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add an access_panels component for linking to the same object in other user facing systems #4357
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= render @layout.new do |component| %> | ||
<% component.with_title { 'Also listed in' } %> | ||
<% component.with_body do %> | ||
<% if earthworks_url.present? %> | ||
<p><%= link_to('Earthworks', earthworks_url) %></p> | ||
<% end %> | ||
<% purl_links.each do |purl_link| %> | ||
<p><%= purl_link %></p> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module AccessPanels | ||
class OtherListingsComponent < AccessPanels::Base | ||
def render? | ||
earthworks_url.present? || purls.present? | ||
end | ||
|
||
def earthworks_url | ||
@earthworks_url ||= construct_earthworks_url | ||
end | ||
|
||
# @return [Array<String>] a tags representing PURL links | ||
def purl_links | ||
@purl_links ||= | ||
if purls.size > 1 # text of the link is the actual URL if there is more than one unique URL, so there aren't multiple links with the same title | ||
purls.map { |purl| link_to(purl, purl) } | ||
elsif purls.size == 1 | ||
Array(link_to('Stanford Digital Repository', purls.first)) | ||
else | ||
[] | ||
end | ||
end | ||
|
||
private | ||
|
||
# @return [Array<String>] URLs representing links to PURL, whether specified in MARC or MODS, and de-duped, e.g. ["https://purl.stanford.edu/hj948rn6493"] | ||
def purls | ||
@purls ||= (mods_purls + marc_managed_purls).uniq | ||
end | ||
|
||
# @return [Array<String>] URLs representing links to other locations, extracted from MODS metadata, e.g. ["https://purl.stanford.edu/hj948rn6493"] | ||
def mods_purls | ||
Array(document['url_fulltext']).find_all { |str| str.start_with?(Settings.PURL_EMBED_RESOURCE) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i wasn't sure if
|
||
end | ||
|
||
# @return [Array<String>] URLs representing links to other locations, extracted from MARC metadata, e.g. ["https://purl.stanford.edu/hj948rn6493"] | ||
def marc_managed_purls | ||
document.marc_links.managed_purls.filter_map(&:href) # filter_map because href can be nil, at least in fixture data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seemed safe to me based on looking at similar calls elsewhere in the app, but i can add more safeguards if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mentioning this specifically because i would love for my first searchworks PR to not cause a bunch of unexpected 500 errors 😅 |
||
end | ||
|
||
def construct_earthworks_url | ||
return nil unless document['dor_content_type_ssi'] == 'geo' | ||
|
||
# * Hardcoding this simple URL format because it should work for all things it'd apply to (anything released to both SW and EW should be a Stanford object) | ||
# * Using Kernel.format because there's a clashing ViewComponent::Base#format, so the namespacing is needed | ||
Kernel.format('https://%<hostname>s/catalog/stanford-%<bare_druid>s', hostname: Settings.earthworks.hostname, bare_druid: document.druid) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe AccessPanels::OtherListingsComponent, type: :component do | ||
include MarcMetadataFixtures | ||
|
||
let(:component) { described_class.new(document:) } | ||
|
||
let(:document_hash) { { id: '123', dor_content_type_ssi: 'notgeo' } } | ||
let(:document) { SolrDocument.new(document_hash) } | ||
|
||
subject(:page) { render_inline(component) } | ||
|
||
it 'does not render if the item neither is released to Earthworks nor has a PURL' do | ||
page | ||
expect(rendered_content).to eq "" | ||
end | ||
|
||
context 'there is a PURL specified in the MARC' do | ||
let(:document_hash) do | ||
{ | ||
id: 'hj948rn6493', | ||
marc_links_struct: [ | ||
{ href: 'https://purl.stanford.edu/hj948rn6493', managed_purl: true } | ||
] | ||
} | ||
end | ||
|
||
it 'displays a link to the PURL' do | ||
expect(page).to have_link('Stanford Digital Repository', href: 'https://purl.stanford.edu/hj948rn6493') | ||
end | ||
end | ||
|
||
context 'there is a PURL specified in the MODS' do | ||
let(:document_hash) { { id: 'bd285ct9109', url_fulltext: 'https://purl.stanford.edu/hj948rn6493' } } | ||
|
||
it 'displays a link to the PURL' do | ||
expect(page).to have_link('Stanford Digital Repository', href: 'https://purl.stanford.edu/hj948rn6493') | ||
end | ||
end | ||
|
||
context 'the same PURL is specified in both MARC and MODS' do | ||
let(:document_hash) do | ||
{ | ||
id: 'hj948rn6493', | ||
url_fulltext: 'https://purl.stanford.edu/hj948rn6493', | ||
marc_links_struct: [ | ||
{ href: 'https://purl.stanford.edu/hj948rn6493', managed_purl: true } | ||
] | ||
} | ||
end | ||
|
||
it 'displays a single link to the PURL' do | ||
expect(page).to have_link('Stanford Digital Repository', href: 'https://purl.stanford.edu/hj948rn6493') | ||
expect(page).to have_css('a', count: 1) | ||
end | ||
end | ||
|
||
context 'MODS and MARC specify different PURLs' do | ||
let(:document_hash) do | ||
{ | ||
id: '123', | ||
url_fulltext: 'https://purl.stanford.edu/bc123df4567', | ||
marc_links_struct: [ | ||
{ href: 'https://purl.stanford.edu/gh890jk9876', managed_purl: true } | ||
] | ||
} | ||
end | ||
|
||
it 'displays a single link to the PURL' do | ||
expect(page).to have_link('https://purl.stanford.edu/bc123df4567', href: 'https://purl.stanford.edu/bc123df4567') | ||
expect(page).to have_link('https://purl.stanford.edu/gh890jk9876', href: 'https://purl.stanford.edu/gh890jk9876') | ||
expect(page).to have_css('a', count: 2) | ||
end | ||
end | ||
|
||
context 'the object has been released to Earthworks' do | ||
let(:document_hash) { { id: 'bd285ct9109', druid: 'bd285ct9109', dor_content_type_ssi: 'geo' } } | ||
|
||
it 'displays a link to Earthworks' do | ||
expect(page).to have_link('Earthworks', href: "https://#{Settings.earthworks.hostname}/catalog/stanford-bd285ct9109") | ||
end | ||
end | ||
|
||
context 'the object has been released to Earthworks and it has a PURL' do | ||
let(:document_hash) { { druid: 'bd285ct9109', url_fulltext: 'https://purl.stanford.edu/bd285ct9109', dor_content_type_ssi: 'geo' } } | ||
|
||
it 'displays a link to the PURL and a link to Earthworks' do | ||
expect(page).to have_link('Stanford Digital Repository', href: 'https://purl.stanford.edu/bd285ct9109') | ||
expect(page).to have_link('Earthworks', href: "https://#{Settings.earthworks.hostname}/catalog/stanford-bd285ct9109") | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no idea whether accounting for this possibility is overly complicated, i.e. i have no idea whether we'd ever see multiple PURLs in practice among the MARC and MODS metadata?