Skip to content

Commit 78bee5d

Browse files
committed
Adds availablility information to records
Why are these changes being introduced: * This information is useful to users to understand if an item is available for checkout or needs to be requested. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/USE-246 How does this address that need: * Creates a helper method to format availability information * Updates the result partial to display availability information Document any side effects to this change: * Location information is now expected to be an array with three elements instead of a string to allow for more flexibility in formatting.
1 parent 7f83a00 commit 78bee5d

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

app/helpers/results_helper.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,49 @@ module ResultsHelper
22
def results_summary(hits)
33
hits.to_i >= 10_000 ? '10,000+ results' : "#{number_with_delimiter(hits)} results"
44
end
5+
6+
# Formats availability information for display.
7+
# Expects:
8+
# - status: a string indicating availability status
9+
# - location: an array with three elements: [library name, location name, call number]
10+
# - other_availability: a boolean string indicating if there is availability at other locations
11+
def availability(status, location, other_availability)
12+
blurb = case status.downcase
13+
# `available` is a common status used in Alma/Primo VE for items that are not checked out and should be
14+
# on the shelf
15+
when 'available'
16+
"#{icon('check')} Available in #{location(location)}"
17+
# `check_holdings`: unclear when (or if) this is used. Bento handled this so we did too assuming it was
18+
# meaningful
19+
when 'check_holdings'
20+
"#{icon('question')} May be available in #{location(location)}"
21+
# 'unavailable' is used for items that are checked out, missing, or otherwise not on the shelf
22+
when 'unavailable'
23+
"#{icon('times')} Not currently available in #{location(location)}"
24+
# Unclear if there are other statuses we should handle here. For now we log and display a generic message.
25+
else
26+
Rails.logger.error("Unhandled availability status: #{status.inspect}")
27+
"#{icon('question')} Uncertain availability in #{location(location)} #{status}"
28+
end
29+
30+
blurb += ' and other locations.' if other_availability.present?
31+
32+
# We are generating HTML in this helper, so we need to mark it as safe or it will be escaped in the view.
33+
blurb.html_safe
34+
end
35+
36+
# Fontawesome helper. Currently only takes the icon name and assumes solid sharp style.
37+
# Could be extended later to default to these styles but allow overrides if appropriate.
38+
# Also defaults to aria-hidden true, which is probably what we want for icons used
39+
# purely for decoration. If an icon is used in a more meaningful way, we may want to extend this helper
40+
# to allow passing in additional aria attributes.
41+
def icon(fa)
42+
"<i class='fa-sharp fa-solid fa-#{fa} aria-hidden='true''></i>"
43+
end
44+
45+
# Formats location information for availability display.
46+
# Expects an array with three elements: [library name, location name, call number]
47+
def location(loc)
48+
"<strong>#{loc[0]}</strong> #{loc[1]} (#{loc[2]})"
49+
end
550
end

app/models/normalize_primo_record.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def location
280280
return unless @record['delivery']['bestlocation']
281281

282282
loc = @record['delivery']['bestlocation']
283-
["#{loc['mainLocation']} #{loc['subLocation']}", loc['callNumber']]
283+
[loc['mainLocation'], loc['subLocation'], loc['callNumber']]
284284
end
285285

286286
def subjects

app/views/search/_result_primo.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<% if result[:links].present? %>
3939
<% result[:links].each do |link| %>
4040
<%= link_to link['kind'].titleize, link['url'], class: 'button' %>
41+
<% if result[:availability].present? %>
42+
<span class="availability"><%= availability(result[:availability], result[:location], result[:other_availability]) %></span>
43+
<% end %>
4144
<% end %>
4245
<% end %>
4346
</div>

test/helpers/results_helper_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,24 @@ class ResultsHelperTest < ActionView::TestCase
1717
hits = 9000
1818
assert_equal '9,000 results', results_summary(hits)
1919
end
20+
21+
test 'availability helper handles known statuses correctly' do
22+
location = ['Main Library', 'First Floor', 'QA76.73.R83 2023']
23+
24+
available_blurb = availability('available', location, false)
25+
assert_includes available_blurb, 'Available in'
26+
assert_includes available_blurb, location(location)
27+
28+
check_holdings_blurb = availability('check_holdings', location, false)
29+
assert_includes check_holdings_blurb, 'May be available in'
30+
assert_includes check_holdings_blurb, location(location)
31+
32+
unavailable_blurb = availability('unavailable', location, false)
33+
assert_includes unavailable_blurb, 'Not currently available in'
34+
assert_includes unavailable_blurb, location(location)
35+
36+
unknown_blurb = availability('unknown_status', location, false)
37+
assert_includes unknown_blurb, 'Uncertain availability in'
38+
assert_includes unknown_blurb, location(location)
39+
end
2040
end

test/models/normalize_primo_record_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def cdi_record
174174

175175
test 'returns best location with call number' do
176176
normalized = NormalizePrimoRecord.new(full_record, 'test').normalize
177-
expected_location = ['Hayden Library Stacks', 'QA76.73.R83 2023']
177+
expected_location = ['Hayden Library', 'Stacks', 'QA76.73.R83 2023']
178178
assert_equal expected_location, normalized[:location]
179179
end
180180

0 commit comments

Comments
 (0)