-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an access_panels component for linking to the same object in othe…
…r user facing systems remove existing PURL link from MODS bibliographic info, since it's moving to this new panel
- Loading branch information
1 parent
dccfdd4
commit bf11ebe
Showing
6 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
app/components/access_panels/other_listings_component.html.erb
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,11 @@ | ||
<%= render @layout.new(classes: ['panel-in-collection']) 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 %> |
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,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) } | ||
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 | ||
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 |
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
94 changes: 94 additions & 0 deletions
94
spec/components/access_panels/other_listings_component_spec.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,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 |