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

pulibrary / orangelight / 4c1ca333-f82e-4fd4-9725-5e0848874e8b

28 Jul 2025 09:06PM UTC coverage: 95.17% (-0.2%) from 95.407%
4c1ca333-f82e-4fd4-9725-5e0848874e8b

Pull #4962

circleci

web-flow
[#5065] Add padding in holdings-card (#5085)
Pull Request #4962: Orangelight pos workcycle 07-07-2025

151 of 154 new or added lines in 17 files covered. (98.05%)

16 existing lines in 5 files now uncovered.

6088 of 6397 relevant lines covered (95.17%)

1512.14 hits per line

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

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

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

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

11
  def show_regular_search?
3✔
12
    !((%w[generate numismatics advanced_search].include? params[:action]) || (%w[advanced].include? params[:controller]))
964✔
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)
3✔
24
    adapter = HoldingRequestsAdapter.new(document, Bibdata)
107✔
25
    markup_builder = HoldingRequestsBuilder.new(adapter:,
107✔
26
                                                online_markup_builder: OnlineHoldingsMarkupBuilder,
27
                                                physical_markup_builder: PhysicalHoldingsMarkupBuilder,
28
                                                params:)
29
    online_markup, physical_markup = markup_builder.build
107✔
30
    [online_markup, physical_markup]
107✔
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)
3✔
37
    if holding.key? 'items'
19✔
38
      restricted_items = holding['items'].select { |item| item['use_statement'] == 'Supervised Use' }
43✔
39
      restricted_items.count == holding['items'].count
19✔
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)
3✔
48
    series_display =
49
      if params[:f1] == 'in_series'
3✔
50
        same_series_result(params[:q1], args[:document][args[:field]])
×
51
      else
52
        args[:document][args[:field]]
3✔
53
      end
54
    series_display.join(', ')
3✔
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)
3✔
62
    series_display.select { |t| t.start_with?(series) }
8✔
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)
3✔
69
    location.nil? ? false : location[:aeon_location]
1,630✔
70
  end
71

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

80
  # Location display in the search results page
81
  def search_location_display(holding)
3✔
82
    location = holding_library_label(holding)
1,626✔
83
    pin = content_tag(:span, "", class: 'icon icon-location')
1,626✔
84
    location_display = content_tag(:div, pin.html_safe + location, class: 'results_location row') + " " +
1,626✔
85
                       content_tag(:div, CallNumber.new(holding['call_number']).with_line_break_suggestions, class: 'call-number')
86
    location_display.html_safe
1,626✔
87
  end
88

89
  def title_hierarchy(args)
3✔
90
    titles = JSON.parse(args[:document][args[:field]])
6✔
91
    all_links = []
6✔
92
    dirtags = []
6✔
93

94
    titles.each do |title|
6✔
95
      title_links = []
6✔
96
      title.each_with_index do |part, index|
6✔
97
        link_accum = StringFunctions.trim_punctuation(title[0..index].join(' '))
21✔
98
        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✔
99
      end
100
      full_title = title.join(' ')
6✔
101
      dirtags << StringFunctions.trim_punctuation(full_title.dir.to_s)
6✔
102
      all_links << title_links.join('<span> </span>').html_safe
6✔
103
    end
104

105
    if all_links.length == 1
6✔
106
      all_links = content_tag(:div, all_links[0], dir: dirtags[0])
6✔
107
    else
108
      all_links = all_links.map.with_index { |l, i| content_tag(:li, l, dir: dirtags[i]) }
×
109
      all_links = content_tag(:ul, all_links.join.html_safe)
×
110
    end
111
    all_links
6✔
112
  end
113

114
  def action_notes_display(args)
3✔
115
    action_notes = JSON.parse(args[:document][args[:field]])
3✔
116
    lines = action_notes.map do |note|
3✔
117
      if note["uri"].present?
4✔
118
        link_to(note["description"], note["uri"])
1✔
119
      else
120
        note["description"]
3✔
121
      end
122
    end
123

124
    if lines.length == 1
3✔
125
      lines = content_tag(:div, lines[0])
2✔
126
    else
127
      lines = lines.map.with_index { |l| content_tag(:li, l) }
3✔
128
      lines = content_tag(:ul, lines.join.html_safe)
1✔
129
    end
130
    lines
3✔
131
  end
132

133
  def name_title_hierarchy(args)
3✔
134
    name_titles = JSON.parse(args[:document][args[:field]])
23✔
135
    all_links = []
23✔
136
    dirtags = []
23✔
137
    name_titles.each do |name_t|
23✔
138
      name_title_links = []
116✔
139
      name_t.each_with_index do |part, i|
116✔
140
        link_accum = StringFunctions.trim_punctuation(name_t[0..i].join(' '))
344✔
141
        if i.zero?
344✔
142
          next if args[:field] == 'name_uniform_title_1display'
116✔
143
          name_title_links << link_to(part, "/?f[author_s][]=#{CGI.escape link_accum}", class: 'search-name-title', 'data-original-title' => "Search: #{link_accum}")
103✔
144
        else
145
          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}")
228✔
146
        end
147
      end
148
      full_name_title = name_t.join(' ')
116✔
149
      dirtags << StringFunctions.trim_punctuation(full_name_title.dir.to_s)
116✔
150
      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)
116✔
151
      all_links << name_title_links.join('<span> </span>').html_safe
116✔
152
    end
153

154
    if all_links.length == 1
23✔
155
      all_links = content_tag(:div, all_links[0], dir: dirtags[0])
8✔
156
    else
157
      all_links = all_links.map.with_index { |l, i| content_tag(:li, l, dir: dirtags[i]) }
123✔
158
      all_links = content_tag(:ul, all_links.join.html_safe)
15✔
159
    end
160
    all_links
23✔
161
  end
162

163
  def format_render(args)
3✔
164
    args[:document][args[:field]].join(', ')
106✔
165
  end
166

167
  def location_has(args)
3✔
168
    location_notes = JSON.parse(args[:document][:holdings_1display]).collect { |_k, v| v['location_has'] }.flatten
4✔
169
    if location_notes.length > 1
2✔
170
      content_tag(:ul) do
1✔
171
        location_notes.map { |note| content_tag(:li, note) }.join.html_safe
3✔
172
      end
173
    else
174
      location_notes
1✔
175
    end
176
  end
177

178
  def bibdata_location_code_to_sym(value)
3✔
179
    Bibdata.holding_locations[value.to_sym]
1,651✔
180
  end
181

182
  def render_location_code(value)
3✔
183
    values = normalize_location_code(value).map do |loc|
4,662✔
184
      location = Bibdata.holding_locations[loc.to_sym]
4,665✔
185
      location.nil? ? loc : "#{loc}: #{location_full_display(location)}"
4,665✔
186
    end
187
    values.one? ? values.first : values
4,662✔
188
  end
189

190
  # Depending on the url, we sometimes get strings, arrays, or hashes
191
  # Returns Array of locations
192
  def normalize_location_code(value)
3✔
193
    case value
4,662✔
194
    when String
195
      Array(value)
4,658✔
196
    when Array
197
      value
2✔
198
    when Hash, ActiveSupport::HashWithIndifferentAccess
199
      value.values
2✔
200
    else
201
      value
×
202
    end
203
  end
204

205
  def holding_location_label(holding)
3✔
206
    location_code = holding['location_code']
24✔
207
    bibdata_location = bibdata_location_code_to_sym(location_code) unless location_code.nil?
24✔
208
    # If the Bibdata location is nil, use the location value from the solr document.
209
    alma_location_display(holding, bibdata_location) unless bibdata_location.blank? && holding.blank?
24✔
210
  end
211

212
  def holding_library_label(holding)
3✔
213
    location_code = holding['location_code']
1,628✔
214

215
    bibdata_location = bibdata_location_code_to_sym(location_code) unless location_code.nil?
1,628✔
216
    return holding['library'] if bibdata_location.nil?
1,628✔
217

218
    alma_library_display(holding, bibdata_location) unless bibdata_location.blank? && holding.blank?
1,618✔
219
  end
220

221
  # Alma location display on search results
222
  def alma_location_display(holding, location)
3✔
223
    if location.nil?
23✔
224
      [holding['library'], holding['location']].select(&:present?).join(' - ')
3✔
225
    else
226
      [location['library']['label'], location['label']].select(&:present?).join(' - ')
20✔
227
    end
228
  end
229

230
  def alma_library_display(holding, bibdata_location)
3✔
231
    return holding['library'] if bibdata_location.nil?
1,618✔
232
    bibdata_location['library']['label']
1,618✔
233
  end
234

235
  # location = Bibdata.holding_locations[value.to_sym]
236
  def location_full_display(loc)
3✔
237
    loc['label'] == '' ? loc['library']['label'] : loc['library']['label'] + ' - ' + loc['label']
3,837✔
238
  end
239

240
  def html_safe(args)
3✔
241
    args[:document][args[:field]].each_with_index { |v, i| args[:document][args[:field]][i] = v.html_safe }
×
242
  end
243

244
  def current_year
3✔
245
    DateTime.now.year
1✔
246
  end
247

248
  # Construct an adapter for Solr Documents and the bib. data service
249
  # @return [HoldingRequestsAdapter]
250
  def holding_requests_adapter
3✔
251
    HoldingRequestsAdapter.new(@document, Bibdata)
120✔
252
  end
253

254
  # Returns true for locations with remote storage.
255
  # Remote storage locations have a value of 'recap_rmt' in Alma.
256
  def remote_storage?(location_code)
3✔
UNCOV
257
    Bibdata.holding_locations[location_code]["remote_storage"] == 'recap_rmt'
×
258
  end
259

260
  # Returns true for locations where the user can walk and fetch an item.
261
  # Currently this logic is duplicated in Javascript code in availability.es6
262
  def find_it_location?(location_code)
3✔
UNCOV
263
    return false if remote_storage?(location_code)
×
UNCOV
264
    return false if (location_code || "").start_with?("plasma$", "marquand$")
×
265

UNCOV
266
    return false if StackmapService::Url.missing_stackmap_reserves.include?(location_code)
×
267

UNCOV
268
    true
×
269
  end
270

271
  # Testing this feature with Voice Over - reading the Web content
272
  # If language defaults to english 'en' when no language_iana_primary_s exists then:
273
  # for cyrilic: for example russian, voice over will read each character as: cyrilic <character1>, cyrilic <character2>
274
  # for japanese it announces <character> ideograph
275
  # If there is no lang attribute it announces the same as having lang='en'
276
  def language_iana
3✔
277
    @document[:language_iana_s].present? ? @document[:language_iana_s].first : 'en'
128✔
278
  end
279

280
  def should_show_viewer?
3✔
281
    request.human? && controller.action_name != "librarian_view"
109✔
282
  end
283
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