Skip to content

Commit

Permalink
Merge pull request #1515 from sul-dlss/1372-hoover-links
Browse files Browse the repository at this point in the history
Change request links for Hoover Library Links to use Aeon/OpenURL
  • Loading branch information
Darren Hardy authored Oct 11, 2017
2 parents edad2f0 + 112ec0a commit 36fe4e0
Show file tree
Hide file tree
Showing 11 changed files with 508 additions and 36 deletions.
34 changes: 28 additions & 6 deletions app/helpers/request_link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ module RequestLinkHelper
def link_to_request_link(options = {})
url = request_link(options[:document], options[:callnumber], options[:barcode])
return unless url
link_text = if Constants::REQUEST_ON_SITE_ACCESS_LIBS.include?(options[:library].try(:code))
'Request on-site access'
else
'Request'
end
link_to(link_text, url, rel: 'nofollow', class: options[:class], data: { behavior: 'requests-modal' })
link_text = t(
"searchworks.request_link.#{options[:library].try(:code) || 'default'}",
default: :'searchworks.request_link.default'
)
link_to(
link_text,
url,
target: request_link_target(options[:callnumber]),
rel: 'nofollow',
class: options[:class],
data: link_data_attributes(options[:callnumber])
)
end

def request_link(document, callnumber, barcode = nil)
return unless callnumber
return hoover_request_url(document, callnumber) if Constants::HOOVER_LIBS.include?(callnumber.library)
if callnumber.home_location == 'SSRC-DATA'
base_url = Settings.SSRC_REQUESTS_URL
request_params = ssrc_params(document, callnumber)
Expand All @@ -24,6 +31,21 @@ def request_link(document, callnumber, barcode = nil)

private

def request_link_target(callnumber)
return unless callnumber && Constants::HOOVER_LIBS.include?(callnumber.library)
'_blank'
end

def link_data_attributes(callnumber)
return { behavior: 'requests-modal' } unless callnumber && Constants::HOOVER_LIBS.include?(callnumber.library)

{ toggle: 'tooltip', html: 'true', title: t('searchworks.request_link.aeon_note') }
end

def hoover_request_url(document, callnumber)
HooverOpenUrlRequest.new(callnumber.library, document, self).to_url
end

def process_request_params(document, callnumber, barcode)
request_params = request_options(document, callnumber)
request_params[:barcode] = barcode if barcode
Expand Down
116 changes: 116 additions & 0 deletions app/models/hoover_open_url_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
class HooverOpenUrlRequest
delegate :to_param, to: :as_params
delegate :safe_join, :solr_document_url, to: :view_context
def initialize(library, document, view_context)
@library = library
@document = document
@view_context = view_context
end

def to_url
"#{base_url}&#{to_param}"
end

def as_params
{
'ItemInfo5' => record_url, 'ReferenceNumber' => ckey,
'ItemTitle' => item_title, 'ItemAuthor' => item_author,
'ItemDate' => item_date, 'ItemPublisher' => item_publisher,
'ItemPlace' => item_place, 'ItemEdition' => item_edition,
'ItemInfo2' => item_restrictions, 'ItemInfo3' => item_conditions,
'Value' => request_type
}.reject { |_, v| v.blank? }
end

def request_type
return 'GenericRequestManuscript' if archive?
'GenericRequestMonograph'
end

def record_url
solr_document_url(document)
end

def ckey
document[:id]
end

def item_title
marc_data(field_codes: '245', subfield_codes: %w[a b n p])
end

def item_author
author_fields = {
'100' => %w[a b c d q], '110' => %w[a b c d],
'111' => %w[a c d], '130' => %w[a d f n p]
}

author_fields.each do |field_codes, subfield_codes|
data = marc_data(field_codes: field_codes, subfield_codes: subfield_codes)
return data if data.present?
end
nil # return nil if none of the fields matched
end

def item_date
return unless archive?
marc_data(field_codes: '245', subfield_codes: ['f'])
end

def item_publisher
return if archive?
marc_260 = marc_data(field_codes: '260', subfield_codes: %w[a b c])
marc_264 = marc_data(field_codes: '264', subfield_codes: %w[a b c])
safe_join([marc_260, marc_264], ' ')
end

def item_place
marc_data(field_codes: '300', subfield_codes: %w[a b c f])
end

def item_edition
return if archive?
marc_data(field_codes: '250', subfield_codes: ['a'])
end

def item_restrictions
marc_data(field_codes: '506', subfield_codes: %w[3 a])
end

def item_conditions
return unless archive?
marc_data(field_codes: '540', subfield_codes: %w[3 a])
end

private

attr_reader :library, :document, :view_context

def archive?
library == 'HV-ARCHIVE'
end

def marc
document.to_marc
end

def marc_data(field_codes:, subfield_codes:)
field_code = marc_field_code_for_present_data(field_codes: field_codes, subfield_codes: subfield_codes)
return unless field_code

safe_join(marc[field_code].subfields.map do |subfield|
next unless subfield_codes.include?(subfield.code)
subfield.value
end.compact, ' ')
end

def marc_field_code_for_present_data(field_codes:, subfield_codes:)
Array.wrap(field_codes).find do |code|
marc[code].present? && marc[code].subfields.any? { |subfield| subfield_codes.include?(subfield.code) }
end
end

def base_url
Settings.HOOVER_REQUESTS_URL
end
end
54 changes: 30 additions & 24 deletions app/views/catalog/_index_location.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,43 @@
<% end %>
<% end %>
<% if location.items.present? && !location.bound_with? %>
<% if location_level_request_link?(library, location) %>
<% if location_level_request_link?(library, location) && !Constants::HOOVER_LIBS.include?(library.code) %>
<%= link_to_request_link(document: document, library: library, callnumber: location.items.first, class: 'btn btn-default btn-xs request-button') %>
<% end %>
<% end %>
</td>
</tr>
<% location.items.each do |item| %>
<% if Constants::HOOVER_LIBS.include?(library.code) %>
<tr>
<td class='indent-callnumber'>
<%= item.callnumber %>
</td>
<td data-live-lookup-id="<%= document[:id] %>" data-status-target=".availability-icon" data-barcode="<%= item.barcode if item.live_status? %>" <%= "data-request-url='#{request_link(document, item, item.barcode)}'".html_safe if item.requestable? && !item.must_request? && !location_level_request_link?(library, location) %>>
<i class="availability-icon <%= item.status.availability_class %>"></i>
<span data-available-text="<%= Constants::TRANSLATE_STATUS['available'] %>" data-unavailable-text="<%= Constants::TRANSLATE_STATUS['unavailable'] %>" class='status-text'>
<%= item.status.status_text %>
</span>
<span class="current-location">
<% unless item.treat_current_location_as_home_location? %>
<%= item.current_location.name %>
<% end %>
</span>
<% if item.on_reserve? %>
<%= item.loan_period %>
<% end %>
<span class="request-link">
<% if item.must_request? %>
<%= link_to_request_link(document: document, library: library, callnumber: item, barcode: item.barcode, class: 'btn btn-default request-button btn-xs') %>
<% end %>
</span>
</td>
<td colspan='2' class='indent-callnumber'><%= link_to('See full record for details', solr_document_path(document)) %></td>
</tr>
<% else %>
<% location.items.each do |item| %>
<tr>
<td class='indent-callnumber'>
<%= item.callnumber %>
</td>
<td data-live-lookup-id="<%= document[:id] %>" data-status-target=".availability-icon" data-barcode="<%= item.barcode if item.live_status? %>" <%= "data-request-url='#{request_link(document, item, item.barcode)}'".html_safe if item.requestable? && !item.must_request? && !location_level_request_link?(library, location) %>>
<i class="availability-icon <%= item.status.availability_class %>"></i>
<span data-available-text="<%= Constants::TRANSLATE_STATUS['available'] %>" data-unavailable-text="<%= Constants::TRANSLATE_STATUS['unavailable'] %>" class='status-text'>
<%= item.status.status_text %>
</span>
<span class="current-location">
<% unless item.treat_current_location_as_home_location? %>
<%= item.current_location.name %>
<% end %>
</span>
<% if item.on_reserve? %>
<%= item.loan_period %>
<% end %>
<span class="request-link">
<% if item.must_request? %>
<%= link_to_request_link(document: document, library: library, callnumber: item, barcode: item.barcode, class: 'btn btn-default request-button btn-xs') %>
<% end %>
</span>
</td>
</tr>
<% end %>
<% end %>
<% end %>
</tbody>
Expand Down
7 changes: 7 additions & 0 deletions config/locales/searchworks.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ en:
label: Series
default:
label: 'Field'
request_link:
aeon_note: Requires Aeon signup/login<br/>Opens in new tab
default: Request
HOOVER: Request on-site access
HV-ARCHIVE: Request on-site access
RUMSEYMAP: Request on-site access
SPEC-COLL: Request on-site access
blacklight:
course_reserves:
page_title: "Course reserves in %{application_name}"
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ HOSTNAME: <%= (`echo $HOSTNAME`).gsub('.stanford.edu', '') %>
STACKS_URL: "https://stacks.stanford.edu/image"
REQUESTS_URL: "https://host.example.com/requests/new"
SSRC_REQUESTS_URL: "http://host.example.com/link.ssds_request_form"
HOOVER_REQUESTS_URL: 'https://hoover.aeon.atlas-sys.com/aeon.dll?Action=10&Form=20'
LIVE_LOOKUP_URL: "http://host.example.com/lookup.pl"
STACKMAP_API_URL: "https://stanford.stackmap.com/json/"
WHEN_TO_PRUNE_DATA: '12:30am'
Expand Down
12 changes: 6 additions & 6 deletions lib/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,11 @@ module Constants
'TECH-SERV',
'TEMP-LL']

REQUEST_LIBS = ['MEDIA-MTXT', 'RUMSEYMAP', 'SAL', 'SAL3', 'SAL-NEWARK', 'SPEC-COLL'].freeze
REQUEST_LIBS = ['HOOVER', 'MEDIA-MTXT', 'RUMSEYMAP', 'SAL', 'SAL3', 'SAL-NEWARK', 'SPEC-COLL'].freeze

LOCATION_LEVEL_REQUEST_LOCS = ['SSRC-DATA']

REQUEST_ON_SITE_ACCESS_LIBS = [
'HV-ARCHIVE',
'RUMSEYMAP',
'SPEC-COLL'
].freeze
HOOVER_LIBS = %w[HOOVER].freeze

REQUEST_LOCS = ['GUNST-30',
'FELTON-30',
Expand Down Expand Up @@ -1222,6 +1218,10 @@ module Constants
BROWSABLE_CALLNUMBERS = %w(LC DEWEY ALPHANUM)

LIBRARY_INSTRUCTIONS = {
'HOOVER' => {
heading: 'All items must be requested in advance',
text: 'Stanford ID holders may be able to check out some monographs marked "Available" next to the call number. "In-library use" call numbers are for reading-room use only.'
},
'RUMSEYMAP' => {
heading: 'All items must be viewed on site',
text: 'Request items by Noon (12p) the day before your visit to allow for retrieval by staff. You can request at most 5 items per day.'
Expand Down
25 changes: 25 additions & 0 deletions spec/features/request_link_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

describe 'Request Links', type: :feature do
describe 'Hoover links' do
context 'in search results' do
it 'renders a link to the detail/record view instead of holdings' do
visit search_catalog_path(q: '56')

within 'table.availability' do
expect(page).not_to have_content 'ABC 123'

expect(page).to have_link 'See full record for details'
end
end
end

context 'on the record view' do
it 'renders a request button at the location level' do
visit solr_document_path '56'

expect(page).to have_css('.request-button', text: 'Request on-site access')
end
end
end
end
32 changes: 32 additions & 0 deletions spec/fixtures/marc_records/marc_metadata_fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1182,4 +1182,36 @@ def linked_related_works_fixture
</record>
xml
end

def hoover_request_fixture
<<-xml
<record>
<datafield tag="100" ind1=" " ind2=" ">
<subfield code="a">100 Subfield $a</subfield>
</datafield>
<datafield tag="245" ind1=" " ind2=" ">
<subfield code="f">245 Subfield $f</subfield>
</datafield>
<datafield tag="250" ind1=" " ind2=" ">
<subfield code="a">250 Subfield $a</subfield>
</datafield>
<datafield tag="260" ind1=" " ind2=" ">
<subfield code="a">260 Subfield $a</subfield>
<subfield code="b">260 Subfield $b</subfield>
<subfield code="c">260 Subfield $c</subfield>
</datafield>
<datafield tag="264" ind1=" " ind2=" ">
<subfield code="c">264 Subfield $c</subfield>
</datafield>
<datafield tag="506" ind1=" " ind2=" ">
<subfield code="3">506 Subfield $3</subfield>
<subfield code="a">506 Subfield $a</subfield>
</datafield>
<datafield tag="540" ind1=" " ind2=" ">
<subfield code="3">540 Subfield $3</subfield>
<subfield code="a">540 Subfield $a</subfield>
</datafield>
</record>
xml
end
end
7 changes: 7 additions & 0 deletions spec/fixtures/solr_documents/56.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:id: 56
:title_display: Hoover Item
:format_main_ssim: Map
:marcxml: <%= hoover_request_fixture %>
:marcbib_xml: <%= hoover_request_fixture %>
:item_display:
- "123 -|- HOOVER -|- STACKS -|- -|- -|- -|- -|- -|- ABC 123"
Loading

0 comments on commit 36fe4e0

Please sign in to comment.