• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / orangelight / 4c391e0e-519a-40cb-8ad3-354445f4ce03

12 Aug 2025 08:47PM UTC coverage: 85.348% (-10.0%) from 95.335%
4c391e0e-519a-40cb-8ad3-354445f4ce03

push

circleci

web-flow
[#5143] Use access restriction note as Aeon ItemInfo1 if available (#5173)

With this commit, if a user visits a record with an access
restrictions note and presses the Reading Room Request
button, they will get to an Aeon form with the 'Restrictions'
field pre-filled with the restriction note.

If the record does not have an access restrictions note,
the field will be pre-filled with 'Reading Room Access Only',
as it has been previously.

Closes #5143

5493 of 6436 relevant lines covered (85.35%)

251.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.07
/app/helpers/application_helper.rb
1
# frozen_string_literal: false
2

3
module ApplicationHelper
1✔
4
  require './lib/orangelight/string_functions'
1✔
5

6
  # Check the Rails Environment. Currently used for Matomo to support production.
7
  def rails_env?
1✔
8
    Rails.env.production?
196✔
9
  end
10

11
  def show_regular_search?
1✔
12
    !((%w[generate numismatics advanced_search].include? params[:action]) || (%w[advanced].include? params[:controller]))
392✔
13
  end
14

15
  # Generate the markup for the block containing links for requests to item holdings
16
  # holding record fields: 'location', 'library', 'location_code', 'call_number', 'call_number_browse',
17
  # 'shelving_title', 'location_note', 'electronic_access_1display', 'location_has', 'location_has_current',
18
  # 'indexes', 'supplements'
19
  # process online and physical holding information at the same time
20
  # @param [SolrDocument] document - record display fields
21
  # @return [String] online - online holding info html
22
  # @return [String] physical - physical holding info html
23
  def holding_request_block(document)
1✔
24
    adapter = HoldingRequestsAdapter.new(document, Bibdata)
29✔
25
    markup_builder = HoldingRequestsBuilder.new(adapter:,
29✔
26
                                                online_markup_builder: OnlineHoldingsMarkupBuilder,
27
                                                physical_markup_builder: PhysicalHoldingsMarkupBuilder,
28
                                                params:)
29
    online_markup, physical_markup = markup_builder.build
29✔
30
    [online_markup, physical_markup]
29✔
31
  end
32

33
  # Determine whether or not a ReCAP holding has items restricted to supervised use
34
  # @param holding [Hash] holding values
35
  # @return [TrueClass, FalseClass]
36
  def scsb_supervised_items?(holding)
1✔
37
    if holding.key? 'items'
15✔
38
      restricted_items = holding['items'].select { |item| item['use_statement'] == 'Supervised Use' }
33✔
39
      restricted_items.count == holding['items'].count
15✔
40
    else
41
      false
×
42
    end
43
  end
44

45
  # Blacklight index field helper for the facet "series_display"
46
  # @param args [Hash]
47
  def series_results(args)
1✔
48
    series_display =
49
      if params[:f1] == 'in_series'
1✔
50
        same_series_result(params[:q1], args[:document][args[:field]])
×
51
      else
52
        args[:document][args[:field]]
1✔
53
      end
54
    series_display.join(', ')
1✔
55
  end
56

57
  # Retrieve the same series for that one being displayed
58
  # @param series [String] series name
59
  # @param series_display [Array<String>] series being displayed
60
  # @param [Array<String>] similarly named series
61
  def same_series_result(series, series_display)
1✔
62
    series_display.select { |t| t.start_with?(series) }
×
63
  end
64

65
  # Determines whether or not this is an aeon location (for an item holding)
66
  # @param location [Hash] location values
67
  # @return [TrueClass, FalseClass]
68
  def aeon_location?(location)
1✔
69
    location.nil? ? false : location[:aeon_location]
322✔
70
  end
71

72
  # Retrieve the location information for a given item holding
73
  # @param [Hash] holding values
74
  def holding_location(holding)
1✔
75
    location_code = holding.fetch('location_code', '').to_sym
636✔
76
    resolved_location = Bibdata.holding_locations[location_code]
636✔
77
    resolved_location ? resolved_location : {}
636✔
78
  end
79

80
  def title_hierarchy(args)
1✔
81
    titles = JSON.parse(args[:document][args[:field]])
6✔
82
    all_links = []
6✔
83
    dirtags = []
6✔
84

85
    titles.each do |title|
6✔
86
      title_links = []
6✔
87
      title.each_with_index do |part, index|
6✔
88
        link_accum = StringFunctions.trim_punctuation(title[0..index].join(' '))
21✔
89
        title_links << link_to(part, "/?search_field=left_anchor&q=#{CGI.escape link_accum}", class: 'search-title', 'data-original-title' => "Search: #{link_accum}", title: "Search: #{link_accum}")
21✔
90
      end
91
      full_title = title.join(' ')
6✔
92
      dirtags << StringFunctions.trim_punctuation(full_title.dir.to_s)
6✔
93
      all_links << title_links.join('<span> </span>').html_safe
6✔
94
    end
95

96
    if all_links.length == 1
6✔
97
      all_links = content_tag(:div, all_links[0], dir: dirtags[0])
6✔
98
    else
99
      all_links = all_links.map.with_index { |l, i| content_tag(:li, l, dir: dirtags[i]) }
×
100
      all_links = content_tag(:ul, all_links.join.html_safe)
×
101
    end
102
    all_links
6✔
103
  end
104

105
  def action_notes_display(args)
1✔
106
    action_notes = JSON.parse(args[:document][args[:field]])
3✔
107
    lines = action_notes.map do |note|
3✔
108
      if note["uri"].present?
4✔
109
        link_to(note["description"], note["uri"])
1✔
110
      else
111
        note["description"]
3✔
112
      end
113
    end
114

115
    if lines.length == 1
3✔
116
      lines = content_tag(:div, lines[0])
2✔
117
    else
118
      lines = lines.map.with_index { |l| content_tag(:li, l) }
3✔
119
      lines = content_tag(:ul, lines.join.html_safe)
1✔
120
    end
121
    lines
3✔
122
  end
123

124
  def name_title_hierarchy(args)
1✔
125
    name_titles = JSON.parse(args[:document][args[:field]])
2✔
126
    all_links = []
2✔
127
    dirtags = []
2✔
128
    name_titles.each do |name_t|
2✔
129
      name_title_links = []
2✔
130
      name_t.each_with_index do |part, i|
2✔
131
        link_accum = StringFunctions.trim_punctuation(name_t[0..i].join(' '))
6✔
132
        if i.zero?
6✔
133
          next if args[:field] == 'name_uniform_title_1display'
2✔
134
          name_title_links << link_to(part, "/?f[author_s][]=#{CGI.escape link_accum}", class: 'search-name-title', 'data-original-title' => "Search: #{link_accum}")
×
135
        else
136
          name_title_links << link_to(part, "/?f[name_title_browse_s][]=#{CGI.escape link_accum}", class: 'search-name-title', 'data-original-title' => "Search: #{link_accum}")
4✔
137
        end
138
      end
139
      full_name_title = name_t.join(' ')
2✔
140
      dirtags << StringFunctions.trim_punctuation(full_name_title.dir.to_s)
2✔
141
      name_title_links << link_to('[Browse]', "/browse/name_titles?q=#{CGI.escape full_name_title}", class: 'browse-name-title', 'data-original-title' => "Browse: #{full_name_title}", dir: full_name_title.dir.to_s)
2✔
142
      all_links << name_title_links.join('<span> </span>').html_safe
2✔
143
    end
144

145
    if all_links.length == 1
2✔
146
      all_links = content_tag(:div, all_links[0], dir: dirtags[0])
2✔
147
    else
148
      all_links = all_links.map.with_index { |l, i| content_tag(:li, l, dir: dirtags[i]) }
×
149
      all_links = content_tag(:ul, all_links.join.html_safe)
×
150
    end
151
    all_links
2✔
152
  end
153

154
  def format_render(args)
1✔
155
    args[:document][args[:field]].join(', ')
27✔
156
  end
157

158
  def location_has(args)
1✔
159
    location_notes = JSON.parse(args[:document][:holdings_1display]).collect { |_k, v| v['location_has'] }.flatten
×
160
    if location_notes.length > 1
×
161
      content_tag(:ul) do
×
162
        location_notes.map { |note| content_tag(:li, note) }.join.html_safe
×
163
      end
164
    else
165
      location_notes
×
166
    end
167
  end
168

169
  def bibdata_location_code_to_sym(value)
1✔
170
    Bibdata.holding_locations[value.to_sym]
318✔
171
  end
172

173
  def render_location_code(value)
1✔
174
    values = normalize_location_code(value).map do |loc|
2,964✔
175
      location = Bibdata.holding_locations[loc.to_sym]
2,967✔
176
      location.nil? ? loc : "#{loc}: #{location_full_display(location)}"
2,967✔
177
    end
178
    values.one? ? values.first : values
2,964✔
179
  end
180

181
  # Depending on the url, we sometimes get strings, arrays, or hashes
182
  # Returns Array of locations
183
  def normalize_location_code(value)
1✔
184
    case value
2,964✔
185
    when String
186
      Array(value)
2,960✔
187
    when Array
188
      value
2✔
189
    when Hash, ActiveSupport::HashWithIndifferentAccess
190
      value.values
2✔
191
    else
192
      value
×
193
    end
194
  end
195

196
  def holding_location_label(holding)
1✔
197
    location_code = holding['location_code']
5✔
198
    bibdata_location = bibdata_location_code_to_sym(location_code) unless location_code.nil?
5✔
199
    # If the Bibdata location is nil, use the location value from the solr document.
200
    alma_location_display(holding, bibdata_location) unless bibdata_location.blank? && holding.blank?
5✔
201
  end
202

203
  def holding_library_label(holding)
1✔
204
    location_code = holding['location_code']
314✔
205

206
    bibdata_location = bibdata_location_code_to_sym(location_code) unless location_code.nil?
314✔
207
    return holding['library'] if bibdata_location.nil?
314✔
208

209
    alma_library_display(holding, bibdata_location) unless bibdata_location.blank? && holding.blank?
310✔
210
  end
211

212
  # Alma location display on search results
213
  def alma_location_display(holding, location)
1✔
214
    if location.nil?
4✔
215
      [holding['library'], holding['location']].select(&:present?).join(' - ')
3✔
216
    else
217
      [location['library']['label'], location['label']].select(&:present?).join(' - ')
1✔
218
    end
219
  end
220

221
  def alma_library_display(holding, bibdata_location)
1✔
222
    return holding['library'] if bibdata_location.nil?
310✔
223
    bibdata_location['library']['label']
310✔
224
  end
225

226
  # location = Bibdata.holding_locations[value.to_sym]
227
  def location_full_display(loc)
1✔
228
    loc['label'] == '' ? loc['library']['label'] : loc['library']['label'] + ' - ' + loc['label']
2,451✔
229
  end
230

231
  def html_safe(args)
1✔
232
    args[:document][args[:field]].each_with_index { |v, i| args[:document][args[:field]][i] = v.html_safe }
×
233
  end
234

235
  def current_year
1✔
236
    DateTime.now.year
1✔
237
  end
238

239
  # Construct an adapter for Solr Documents and the bib. data service
240
  # @return [HoldingRequestsAdapter]
241
  def holding_requests_adapter
1✔
242
    HoldingRequestsAdapter.new(@document, Bibdata)
37✔
243
  end
244

245
  # Returns true for locations with remote storage.
246
  # Remote storage locations have a value of 'recap_rmt' in Alma.
247
  def remote_storage?(location_code)
1✔
248
    Bibdata.holding_locations[location_code]["remote_storage"] == 'recap_rmt'
×
249
  end
250

251
  # Returns true for locations where the user can walk and fetch an item.
252
  # Currently this logic is duplicated in Javascript code in availability.es6
253
  def find_it_location?(location_code)
1✔
254
    return false if remote_storage?(location_code)
×
255
    return false if (location_code || "").start_with?("plasma$", "marquand$")
×
256

257
    return false if StackmapService::Url.missing_stackmap_reserves.include?(location_code)
×
258

259
    true
×
260
  end
261

262
  # Testing this feature with Voice Over - reading the Web content
263
  # If language defaults to english 'en' when no language_iana_primary_s exists then:
264
  # for cyrilic: for example russian, voice over will read each character as: cyrilic <character1>, cyrilic <character2>
265
  # for japanese it announces <character> ideograph
266
  # If there is no lang attribute it announces the same as having lang='en'
267
  def language_iana
1✔
268
    @document[:language_iana_s].present? ? @document[:language_iana_s].first : 'en'
31✔
269
  end
270

271
  def should_show_viewer?
1✔
272
    request.human? && controller.action_name != "librarian_view"
29✔
273
  end
274
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc