Skip to content

Commit

Permalink
Merge pull request #429 from trln/TD-1336-duke-availability
Browse files Browse the repository at this point in the history
Display holdings-level availability status (if present) on item …
  • Loading branch information
kazymovae authored Sep 16, 2024
2 parents 2009645 + 2304158 commit 07faee4
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 37 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.3
2.4.4
3 changes: 2 additions & 1 deletion app/views/catalog/_items_section.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
locals: { document: document,
loc_b: loc_b,
loc_n: loc_n,
loc_b_header_level: loc_b_header_level } %>
loc_b_header_level: loc_b_header_level,
location_holdings: item_data['holdings']&.first } %>
</div>

<% # --- HOLDINGS SUMMARIES WRAPPER --- %>
Expand Down
32 changes: 17 additions & 15 deletions app/views/catalog/_items_section_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
</dl>
</div>
<div class="<%= status_wrapper_class(action: action_name) %> status-wrapper" <%= assign_item_id_as_id(item) %>>
<dl>
<dt><span class='status-badge badge badge-info'><%= t('trln_argon.show.badge.status') %></span></dt>
<dd>
<% available_class = item_availability_display(item) %>
<% due_date = item_due_date(item) %>
<span class="<%= available_class %>">
<%= render partial: 'items_section_item_status', locals: { document: document, loc_b: loc_b, loc_n: loc_n, item: item } %>
<% if !due_date.empty? %>
<span class='due-date'><%= due_date %></span>
<% end %>
</span>
</dd>
</dl>
</div>
<% if display_item_availability?(item) %>
<div class="<%= status_wrapper_class(action: action_name) %> status-wrapper" <%= assign_item_id_as_id(item) %>>
<dl>
<dt><span class='status-badge badge badge-info'><%= t('trln_argon.show.badge.status') %></span></dt>
<dd>
<% available_class = item_availability_display(item) %>
<% due_date = item_due_date(item) %>
<span class="<%= available_class %>">
<%= render partial: 'items_section_item_status', locals: { document: document, loc_b: loc_b, loc_n: loc_n, item: item } %>
<% if !due_date.empty? %>
<span class='due-date'><%= due_date %></span>
<% end %>
</span>
</dd>
</dl>
</div>
<% end %>
<% if item_notes_display(item).present? %>
Expand Down
56 changes: 40 additions & 16 deletions app/views/catalog/_items_section_location.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
<%= content_tag(loc_b_header_level) do %>
<% # --- display broad location --- %>
<% if loc_b.present? %>
<% broad_location_display = map_argon_code(document.record_owner, 'loc_b', loc_b) %>
<span class='location loc-broad loc_b__<%= loc_b %>'>
<%= broad_location_display %>
</span>
<% end %>

<% # --- display narrow location --- %>
<% if loc_n.present? %>
<% narrow_loc = map_argon_code(document.record_owner, 'loc_n', loc_n) %>
<% if narrow_loc.nil? %>
<% narrow_loc = loc_n %>
<div class="col flex-grow-1">
<%= content_tag(loc_b_header_level) do %>
<% # --- display broad location --- %>
<% if loc_b.present? %>
<% broad_location_display = map_argon_code(document.record_owner, 'loc_b', loc_b) %>
<span class='location loc-broad loc_b__<%= loc_b %>'>
<%= broad_location_display %>
</span>
<% end %>
<% # is loc_n different and not empty? %>
<% if narrow_loc != broad_location_display && narrow_loc != '' %>
<span class='location loc-narrow loc_n__<%= loc_n %>'> &mdash; <%= narrow_loc %></span>
<% # --- display narrow location --- %>
<% if loc_n.present? %>
<% narrow_loc = map_argon_code(document.record_owner, 'loc_n', loc_n) %>
<% if narrow_loc.nil? %>
<% narrow_loc = loc_n %>
<% end %>
<% # is loc_n different and not empty? %>
<% if narrow_loc != broad_location_display && narrow_loc != '' %>
<span class='location loc-narrow loc_n__<%= loc_n %>'> &mdash; <%= narrow_loc %></span>
<% end %>
<% end %>
<% end %>
</div>
<%# If present, holdings availability status for a *location* will display aligned with and %>
<%# styled like item availability. If not, the location will use the entire width of the row. %>
<% if display_holdings_availability?(location_holdings) %>
<% available_class = item_availability_display(location_holdings) %>
<div class="<%= status_wrapper_class(action: action_name) %> status-wrapper">
<dl>
<dt>
<span class='status-badge badge badge-info'><%= t('trln_argon.show.badge.status') %></span>
</dt>
<dd>
<span class="<%= available_class %>">
<%= render 'items_section_location_status', { document: document,
loc_b: loc_b,
loc_n: loc_n,
location_holdings: location_holdings } %>
</span>
</dd>
</dl>
</div>
<% end %>
3 changes: 3 additions & 0 deletions app/views/catalog/_items_section_location_status.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%# Allows local institutions to customize display of location availability status %>
<%# Override in local institution codebase %>
<%= location_holdings['status'] %>
12 changes: 10 additions & 2 deletions lib/trln_argon/view_helpers/items_section_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def availability_class
end

def location_header_class
'location-header col-lg-12'
'location-header col d-lg-flex flex-grow-1 no-gutters'
end

def institution_location_header_class
Expand All @@ -45,7 +45,7 @@ def item_availability_display(item)
case item['status']
when /^available/i
'item-available'
when /^checked out/i, /\blost\b/i, /^missing/i
when /^checked out/i, /^unavailable/i, /\blost\b/i, /^missing/i
'item-not-available'
when /(?:in-)?library use only/i
'item-library-only'
Expand Down Expand Up @@ -83,6 +83,10 @@ def latest_received_wrapper_class(_opts = {})
'col-lg-5 col-sm-12 latest-received-wrapper'
end

def display_holdings_availability?(location_holdings)
location_holdings['status'].present?
end

def display_holdings_summaries?(options = {})
holdings = options.fetch('holdings', [])
displayable_holdings = holdings.find do |h|
Expand Down Expand Up @@ -129,6 +133,10 @@ def suppress_item?(options = {})
no_items_holdings_no_summary?(loc_b: loc_b, loc_n: loc_n, item_data: item_data)
end

def display_item_availability?(item)
item['status'].present?
end

def online_only_items?(options = {})
loc_b = options.fetch(:loc_b, '')
%w[ONLINE DUKIR].include?(loc_b)
Expand Down
69 changes: 67 additions & 2 deletions spec/lib/trln_argon/view_helpers/trln_argon_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
describe '#location_header_class' do
it 'returns the HTML class attribute values' do
expect(helper.location_header_class).to(
eq('location-header col-lg-12')
eq('location-header col d-lg-flex flex-grow-1 no-gutters')
)
end
end
Expand Down Expand Up @@ -373,6 +373,16 @@
end

context 'item is NOT available' do
let(:item) { { 'status' => 'Unavailable' } }

it 'returns the HTML class attribute values' do
expect(helper.item_availability_display(item)).to(
eq('item-not-available')
)
end
end

context 'item is checked out' do
let(:item) { { 'status' => 'Checked Out' } }

it 'returns the HTML class attribute values' do
Expand All @@ -382,7 +392,7 @@
end
end

context 'item is NOT available' do
context 'item is library use only' do
let(:item) { { 'status' => 'Library Use Only' } }

it 'returns the HTML class attribute values' do
Expand Down Expand Up @@ -532,6 +542,36 @@
end
end

describe '#display_item_availability?' do
context 'item has a status' do
let(:item) do
{
'call_no' => 'E909 .O24 A3 2018',
'type' => 'BOOK',
'status' => 'Available'
}
end

it 'returns true' do
expect(helper.display_item_availability?(item)).to be true
end
end

context 'item has a blank status' do
let(:item) do
{
'call_no' => 'E909 .O24 A3 2018',
'type' => 'BOOK',
'status' => ''
}
end

it 'returns false' do
expect(helper.display_item_availability?(item)).to be false
end
end
end

describe '#online_only_items?' do
context 'location codes are online' do
let(:holdings) do
Expand Down Expand Up @@ -739,6 +779,31 @@
end
end

describe '#display_holdings_availability?' do
context 'location holdings have a status' do
let(:location_holdings) do
{
'call_no' => 'E909.O24 A3 2018',
'status' => 'Unavailable'
}
end

it 'returns true' do
expect(helper.display_holdings_availability?(location_holdings)).to be true
end
end

context 'location holdings do not have a status' do
let(:location_holdings) do
{ 'call_no' => 'E909.O24 A3' }
end

it 'returns false' do
expect(helper.display_holdings_availability?(location_holdings)).to be false
end
end
end

describe '#display_holdings_summaries?' do
context 'holdings have summaries' do
let(:options) do
Expand Down

0 comments on commit 07faee4

Please sign in to comment.