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

pulibrary / orangelight / 00dbc10b-d747-4ad7-b211-7b26d753abbb

14 Aug 2025 01:25PM UTC coverage: 0.483% (-94.9%) from 95.343%
00dbc10b-d747-4ad7-b211-7b26d753abbb

push

circleci

web-flow
Merge pull request #5181 from pulibrary/dependabot/bundler/activestorage-7.2.2.2

Bump activestorage from 7.2.2.1 to 7.2.2.2

47 of 9721 relevant lines covered (0.48%)

0.01 hits per line

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

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

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

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

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

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

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

85
    titles.each do |title|
×
86
      title_links = []
×
87
      title.each_with_index do |part, index|
×
88
        link_accum = StringFunctions.trim_punctuation(title[0..index].join(' '))
×
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}")
×
90
      end
×
91
      full_title = title.join(' ')
×
92
      dirtags << StringFunctions.trim_punctuation(full_title.dir.to_s)
×
93
      all_links << title_links.join('<span> </span>').html_safe
×
94
    end
×
95

96
    if all_links.length == 1
×
97
      all_links = content_tag(:div, all_links[0], dir: dirtags[0])
×
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
×
103
  end
×
104

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

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

124
  def name_title_hierarchy(args)
×
125
    name_titles = JSON.parse(args[:document][args[:field]])
×
126
    all_links = []
×
127
    dirtags = []
×
128
    name_titles.each do |name_t|
×
129
      name_title_links = []
×
130
      name_t.each_with_index do |part, i|
×
131
        link_accum = StringFunctions.trim_punctuation(name_t[0..i].join(' '))
×
132
        if i.zero?
×
133
          next if args[:field] == 'name_uniform_title_1display'
×
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}")
×
137
        end
×
138
      end
×
139
      full_name_title = name_t.join(' ')
×
140
      dirtags << StringFunctions.trim_punctuation(full_name_title.dir.to_s)
×
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)
×
142
      all_links << name_title_links.join('<span> </span>').html_safe
×
143
    end
×
144

145
    if all_links.length == 1
×
146
      all_links = content_tag(:div, all_links[0], dir: dirtags[0])
×
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
×
152
  end
×
153

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

158
  def location_has(args)
×
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)
×
170
    Bibdata.holding_locations[value.to_sym]
×
171
  end
×
172

173
  def render_location_code(value)
×
174
    values = normalize_location_code(value).map do |loc|
×
175
      location = Bibdata.holding_locations[loc.to_sym]
×
176
      location.nil? ? loc : "#{loc}: #{location_full_display(location)}"
×
177
    end
×
178
    values.one? ? values.first : values
×
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)
×
184
    case value
×
185
    when String
×
186
      Array(value)
×
187
    when Array
×
188
      value
×
189
    when Hash, ActiveSupport::HashWithIndifferentAccess
×
190
      value.values
×
191
    else
×
192
      value
×
193
    end
×
194
  end
×
195

196
  def holding_location_label(holding)
×
197
    location_code = holding['location_code']
×
198
    bibdata_location = bibdata_location_code_to_sym(location_code) unless location_code.nil?
×
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?
×
201
  end
×
202

203
  def holding_library_label(holding)
×
204
    location_code = holding['location_code']
×
205

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

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

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

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

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

231
  def html_safe(args)
×
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
×
236
    DateTime.now.year
×
237
  end
×
238

239
  # Construct an adapter for Solr Documents and the bib. data service
240
  # @return [HoldingRequestsAdapter]
241
  def holding_requests_adapter
×
242
    HoldingRequestsAdapter.new(@document, Bibdata)
×
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)
×
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)
×
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
×
268
    @document[:language_iana_s].present? ? @document[:language_iana_s].first : 'en'
×
269
  end
×
270

271
  def should_show_viewer?
×
272
    request.human? && controller.action_name != "librarian_view"
×
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