Skip to content

Commit

Permalink
SCSB supervised use may have multiple holdings, so need to go to the …
Browse files Browse the repository at this point in the history
…requests form
  • Loading branch information
sandbergja committed May 15, 2023
1 parent a3145f3 commit 2ae7fcb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
11 changes: 9 additions & 2 deletions app/components/request_button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

# ViewComponent that displays a request button on the show page
class RequestButtonComponent < ViewComponent::Base
def initialize(location:, doc_id:, holding_id: nil)
def initialize(location:, doc_id:, holding: nil, holding_id: nil)
@location = location
@doc_id = doc_id
@holding = holding
@holding_id = holding_id
end

Expand All @@ -26,6 +27,12 @@ def url
private

def aeon?
@aeon ||= @location&.dig(:aeon_location)
@aeon ||= (@location&.dig(:aeon_location) || scsb_supervised_items?)
end

def scsb_supervised_items?
return false unless @holding
return false unless @holding['items']
@holding['items'].all? { |item| item['use_statement'] == 'Supervised Use' }
end
end
22 changes: 12 additions & 10 deletions app/services/physical_holdings_markup_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,10 @@ def request_placeholder(adapter, holding_id, location_rules, holding)
# so that it will be "/request/#{doc_id}", where doc_id can be either the record page mms_id or the host id(s) if they exist.
doc_id = doc_id(holding)
view_base = ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil)
link = if aeon_location?(location_rules)
AeonRequestButtonComponent.new(document: adapter.document, location: location_rules).render_in(view_base)
elsif !location_rules.nil? && /^scsb.+/ =~ location_rules['code']
if scsb_supervised_items?(holding)
# All SCSB supervised items go through Aeon
AeonRequestButtonComponent.new(document: adapter.document, location: location_rules).render_in(view_base)
else
RequestButtonComponent.new(doc_id:, location: location_rules).render_in(view_base)
end
elsif !adapter.alma_holding?(holding_id)
link = if display_direct_aeon_link?(location_rules, holding_id)
AeonRequestButtonComponent.new(document: adapter.document, location: location_rules).render_in(view_base)
elsif self.class.scsb_location?(location_rules)
RequestButtonComponent.new(doc_id:, location: location_rules, holding:).render_in(view_base)
elsif self.class.temporary_holding_id?(holding_id)
holding_identifier = self.class.temporary_location_holding_id_first(holding)
RequestButtonComponent.new(doc_id:, holding_id: holding_identifier, location: location_rules).render_in(view_base)
Expand All @@ -299,6 +292,15 @@ def request_placeholder(adapter, holding_id, location_rules, holding)
markup
end

def display_direct_aeon_link?(location_rules, holding_id)
return true if aeon_location?(location_rules)

# If it is not from SCSB or alma, it must be aeon
return true unless self.class.scsb_location?(location_rules) || adapter.alma_holding?(holding_id)

false
end

def request_url(doc_id:, aeon:, holding_id: nil)
query = if holding_id
{ mfhd: holding_id, aeon: aeon.to_s }.to_query
Expand Down
12 changes: 12 additions & 0 deletions spec/components/request_button_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
it 'includes aeon=false in the link url' do
expect(subject.css('a').attribute('href').text).to eq('/requests/123?aeon=false&mfhd=456')
end

context 'when at an aeon location' do
let(:location) do
{ aeon_location: true }
Expand All @@ -33,10 +34,21 @@
expect(subject.css('a').attribute('href').text).to eq('/requests/123?aeon=true&mfhd=456')
end
end

context 'when no holding_id' do
subject { render_inline(described_class.new(location:, doc_id: '123')) }
it 'does not include mfhd param in the link url' do
expect(subject.css('a').attribute('href').text).to eq('/requests/123?aeon=false')
end
end

context 'scsb supervised use' do
let(:holding) do
{ 'items' => [{ 'use_statement' => 'Supervised Use' }] }
end
subject { render_inline(described_class.new(location:, doc_id: '123', holding_id: '456', holding:)) }
it 'includes aeon=true in the link url' do
expect(subject.css('a').attribute('href').text).to eq('/requests/123?aeon=true&mfhd=456')
end
end
end
6 changes: 3 additions & 3 deletions spec/services/physical_holdings_markup_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
allow(holding).to receive(:dig).and_return("SCSB-6593031")
end

it 'generates an aeon link including data from the host and constituent record' do
it 'generates the request link for the host record' do
expect(request_placeholder_markup).to include '<td class="location-services service-always-requestable"'
expect(request_placeholder_markup).to include 'data-open="false"'
expect(request_placeholder_markup).to include 'data-requestable="true"'
Expand All @@ -281,8 +281,8 @@
expect(request_placeholder_markup).to include 'title="Request to view in Reading Room"'
# The general scsbnypl location is *not* an aeon location, but if the holding use_statement is "Supervised Use",
# it goes through aeon.
expect(request_placeholder_markup).to include 'href="https://lib-aeon.princeton.edu/aeon/aeon.dll/OpenURL'
expect(request_placeholder_markup).to include 'ItemNumber=host123'
expect(request_placeholder_markup).to include 'data-aeon="false"'
expect(request_placeholder_markup).to include 'href="/requests/SCSB-6593031?aeon=true"'
end
end

Expand Down

0 comments on commit 2ae7fcb

Please sign in to comment.