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

pulibrary / orangelight / 7d853838-dd1f-4278-937b-e9d569846cc3

15 Oct 2025 02:21PM UTC coverage: 95.398% (-0.01%) from 95.409%
7d853838-dd1f-4278-937b-e9d569846cc3

Pull #5222

circleci

christinach
When item is in recap request form has the default prompt disabled and selected.
No other library is preselected.

related to [#2926]
Pull Request #5222: Allow standard circulating location materials to be picked up at multiple branches

72 of 73 new or added lines in 3 files covered. (98.63%)

2 existing lines in 1 file now uncovered.

6261 of 6563 relevant lines covered (95.4%)

1486.53 hits per line

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

89.96
/app/helpers/requests/application_helper.rb
1
# frozen_string_literal: true
2
# rubocop:disable Metrics/ModuleLength
3
module Requests
3✔
4
  module ApplicationHelper
3✔
5
    def format_email(email)
3✔
6
      email&.downcase
160✔
7
    end
8

9
    def format_label(key)
3✔
10
      label = key.to_s
×
11
      human_label = label.tr('_', ' ')
×
12
      formatted = human_label.split.map(&:capitalize).join(' ')
×
13
      formatted
×
14
    end
15

16
    def error_key_format(key)
3✔
17
      keys_to_ignore = ['items']
×
18
      format_label(key) unless keys_to_ignore.include? key.to_s
×
19
    end
20

21
    # array of error_keys
22
    def guest_user_error?(error_keys)
3✔
23
      user_errors = [:email, :user_name, :barcode]
×
24
      error_keys.any? { |item| user_errors.include? item }
×
25
    end
26

27
    def show_pick_up_service_options(requestable, mfhd_id)
3✔
28
      if requestable.on_shelf?
142✔
29
        display_on_shelf(requestable, mfhd_id)
70✔
30
      else
31
        display_requestable_list(requestable)
71✔
32
      end
33
    end
34

35
    def show_service_options(requestable, _mfhd_id)
3✔
36
      if requestable.no_services?
2✔
UNCOV
37
        content_tag(:div, "#{requestable.title} #{enum_copy_display(requestable.item)} #{sanitize(I18n.t('requests.no_services.brief_msg'))}", class: 'visually-hidden') +
×
38
          content_tag(:div, sanitize(I18n.t("requests.no_services.brief_msg")), class: 'service-item', aria: { hidden: true })
39
      elsif requestable.charged? && !requestable.aeon? && !requestable.ask_me?
2✔
40
        render partial: 'checked_out_options', locals: { requestable: }
1✔
41
      else
42
        display_requestable_list(requestable)
1✔
43
      end
44
    end
45

46
    def hidden_service_options(requestable, fill_in: false)
3✔
47
      return hidden_service_options_fill_in(requestable) if fill_in
131✔
48
      hidden = output_request_input(requestable)
120✔
49
      return hidden if hidden.present?
120✔
50

51
      if requestable.services.include? 'recap'
49✔
52
        recap_print_only_input requestable
40✔
53
      else
54
        request_input(requestable.services.first)
9✔
55
      end
56
    end
57

58
    def output_request_input(requestable)
3✔
59
      output = ""
120✔
60
      ['annex', 'pres', 'ppl', 'lewis', 'paging', 'on_order', 'on_shelf'].each do |type|
120✔
61
        next unless requestable.services.include?(type)
786✔
62
        output = request_input(type)
71✔
63
        break
71✔
64
      end
65
      output
120✔
66
    end
67

68
    # only requestable services that support "user-supplied volume info"
69
    def hidden_service_options_fill_in(requestable)
3✔
70
      if requestable.annex?
11✔
71
        request_input('annex')
2✔
72
      elsif requestable.services.include? 'recap_no_items'
9✔
73
        request_input('recap_no_items')
1✔
74
      else
75
        request_input('paging')
8✔
76
      end
77
    end
78

79
    def recap_print_only_input(requestable)
3✔
80
      content_tag(:fieldset, class: 'recap--print', id: "recap_group_#{requestable.preferred_request_id}") do
40✔
81
        concat hidden_field_tag "requestable[][type]", "", value: 'recap'
40✔
82
      end
83
    end
84

85
    # rubocop:disable Style/NumericPredicate
86
    def enum_copy_display(item)
3✔
87
      return "" if item.blank?
529✔
88
      [item.description, item.copy_value].join(" ").strip
527✔
89
    end
90
    # rubocop:enable Style/NumericPredicate
91

92
    def request_input(type)
3✔
93
      hidden_field_tag "requestable[][type]", "", value: type
97✔
94
    end
95

96
    def gfa_lookup(lib_code)
3✔
97
      if lib_code == "firestone"
6✔
98
        "PA"
×
99
      else
100
        lib = Requests::BibdataService.delivery_locations.select { |_key, hash| hash["library"]["code"] == lib_code }
144✔
101
        lib.keys.first.to_s
6✔
102
      end
103
    end
104

105
    def pick_up_classlist(requestable, collapse)
3✔
106
      class_list = "collapse request--print"
152✔
107
      class_list += " show" if !requestable.digitize? && !collapse
152✔
108
      class_list
152✔
109
    end
110

111
    # move this to requestable object
112
    # Default pick-ups should be available
113
    def pick_up_choices(requestable, default_pick_ups, collapse = false)
3✔
114
      content_tag(:div, id: "fields-print__#{requestable.preferred_request_id}", class: pick_up_classlist(requestable, collapse)) do
139✔
115
        preferred_request_content_tag(requestable, requestable.pick_up_locations || default_pick_ups)
139✔
116
      end
117
    end
118

119
    # :reek:NilCheck
120
    def preferred_request_content_tag(requestable, default_pick_ups)
3✔
121
      (show_pick_up_service_options(requestable, nil) || "".html_safe) +
145✔
122
        content_tag(:div, id: "fields-print__#{requestable.preferred_request_id}_card", class: "card card-body bg-light") do
123
          locs = pick_up_locations(requestable, default_pick_ups)
144✔
124

125
          name = 'requestable[][pick_up]'
144✔
126
          id = "requestable__pick_up_#{requestable.preferred_request_id}"
144✔
127
          if locs.size > 1
144✔
128
            prompt_text = custom_pickup_prompt(requestable, locs) || I18n.t("requests.default.pick_up_placeholder")
64✔
129
            selected_value = find_selected_pickup_value(requestable, locs)
64✔
130
            # For ReCAP items, select the empty prompt instead of any actual option
131
            selected_value = '' if requestable.recap? && selected_value.nil?
64✔
132
            options = [[prompt_text, '', { disabled: true, selected: false }]] + locs.map { |loc| [loc[:label], { 'pick_up' => loc[:gfa_pickup], 'pick_up_location_code' => loc[:pick_up_location_code] }.to_json] }
563✔
133
            select_tag name.to_s, options_for_select(options, selected_value), id: id
64✔
134
          else
135
            single_pickup(requestable.charged?, name, id, locs[0])
80✔
136
          end
137
        end
138
    end
139

140
    # rubocop:disable Rails/OutputSafety
141
    def hidden_fields_mfhd(mfhd)
3✔
142
      hidden = ""
78✔
143
      return hidden if mfhd.nil?
78✔
144
      hidden += hidden_field_tag "mfhd[][call_number]", "", value: (mfhd['call_number']).to_s unless mfhd["call_number"].nil?
77✔
145
      hidden += hidden_field_tag "mfhd[][location]", "", value: (mfhd['location']).to_s unless mfhd["location"].nil?
77✔
146
      hidden += hidden_field_tag "mfhd[][library]", "", value: (mfhd['library']).to_s
77✔
147
      hidden.html_safe
77✔
148
    end
149
    # rubocop:enable Rails/OutputSafety
150

151
    def hidden_fields_item(requestable)
3✔
152
      request_id = requestable.preferred_request_id
534✔
153
      hidden = hidden_field_tag "requestable[][bibid]", "", value: requestable.bib[:id].to_s, id: "requestable_bibid_#{request_id}"
534✔
154
      hidden += hidden_field_tag "requestable[][mfhd]", "", value: requestable.holding.mfhd_id, id: "requestable_mfhd_#{request_id}"
534✔
155
      hidden += hidden_field_tag "requestable[][call_number]", "", value: requestable.holding.holding_data['call_number'].to_s, id: "requestable_call_number_#{request_id}" unless requestable.holding.holding_data["call_number"].nil?
534✔
156
      hidden += hidden_field_tag "requestable[][location_code]", "", value: requestable.item_location_code.to_s, id: "requestable_location_#{request_id}"
534✔
157
      hidden += if requestable.item?
534✔
158
                  hidden_fields_for_item(item: requestable.item, preferred_request_id: requestable.preferred_request_id)
521✔
159
                else
160
                  hidden_field_tag("requestable[][item_id]", "", value: requestable.preferred_request_id, id: "requestable_item_id_#{requestable.preferred_request_id}")
13✔
161
                end
162
      hidden += hidden_fields_for_scsb(item: requestable.item) if requestable.partner_holding?
534✔
163
      hidden
534✔
164
    end
165

166
    def isbn_string(array_of_isbns)
3✔
167
      array_of_isbns.join(',')
1✔
168
    end
169

170
    def suppress_login?(request)
3✔
171
      request.only_aeon?
82✔
172
    end
173

174
    def item_checkbox(requestable, single_item_form)
3✔
175
      disabled = !requestable.will_submit_via_form?
515✔
176
      check_box_tag "requestable[][selected]", true, check_box_selected?(disabled, single_item_form), class: 'request--select', disabled:, aria: { labelledby: "title enum_#{requestable.preferred_request_id}" }, id: "requestable_selected_#{requestable.preferred_request_id}"
515✔
177
    end
178

179
    ## If any requestable items have a temp location assume everything at the holding is in a temp loc?
180
    def current_location_label(holding_location_label, requestable_list)
3✔
181
      first_location = requestable_list.first.location
153✔
182
      location_label = first_location.short_label.blank? ? "" : "- #{first_location.short_label}"
153✔
183
      label = if requestable_list.first.temp_loc_other_than_resource_sharing?
153✔
184
                "#{first_location.library_label}#{location_label}"
4✔
185
              else
186
                holding_location_label
149✔
187
              end
188
      "#{label} #{requestable_list.first.call_number}"
153✔
189
    end
190

191
    def check_box_selected?(disabled, single_item_form)
3✔
192
      if single_item_form
515✔
193
        !disabled
43✔
194
      else
195
        false
472✔
196
      end
197
    end
198

199
    def submit_button_disabled?(requestable_list)
3✔
200
      # temporary chane issue 438 guest can no longer check out materials
201
      return true if @user.blank? || @user.guest
57✔
202
      return unsubmittable? requestable_list unless requestable_list.size == 1
55✔
203
      # temporary changes issue 438 do not disable the button for circulating items
204
      # requestable_list.first.services.empty? || requestable_list.first.on_reserve? || (requestable_list.first.services.include? 'on_shelf') || requestable_list.first.ask_me?
205
      requestable_list.first.services.empty? || requestable_list.first.on_reserve?
46✔
206
    end
207

208
    def unsubmittable?(requestable_list)
3✔
209
      !requestable_list.any? { |requestable| (requestable.services | submitable_services).present? }
18✔
210
    end
211

212
    def submitable_services
3✔
213
      ['on_shelf', 'in_process', 'on_order', 'annex', 'recap', 'recap_edd', 'paging', 'recap_no_items', 'ppl', 'lewis']
9✔
214
    end
215

216
    def submit_message(requestable_list)
3✔
217
      single_item = "Request this Item"
53✔
218
      multi_item = "Request Selected Items"
53✔
219
      no_item = "No Items Available"
53✔
220
      return multi_item unless requestable_list.size == 1
53✔
221
      if requestable_list.first.services.empty?
44✔
222
        no_item
×
223
      elsif requestable_list.first.annex?
44✔
224
        # Annex items have the potential to display the
225
        # use the fill-in form, where a user could potentially
226
        # request multiple volumes.  For that reason, we show
227
        # the plural form "Request Selected Items" in this case
228
        multi_item
3✔
229
      else
230
        single_item
41✔
231
      end
232
    end
233

234
    # only show the table sort if there are enough items
235
    # to make it worthwhile
236
    def show_tablesorter(requestable_list)
3✔
237
      return "tablesorter" if table_sorter_present?(requestable_list)
77✔
238
      ""
68✔
239
    end
240

241
    def table_sorter_present?(requestable_list)
3✔
242
      requestable_list.size > 5
110✔
243
    end
244

245
    def display_label
3✔
246
      {
×
247
        author: "Author/Artist",
248
        title: "Title",
249
        date: "Published/Created",
250
        id: "Bibliographic ID",
251
        mfhd: "Holding ID (mfhd)"
252
      }.with_indifferent_access
253
    end
254

255
    def display_status(requestable)
3✔
256
      content_tag(:span, requestable.item['status']) unless requestable.item.nil?
×
257
    end
258

259
    def system_status_label(requestable)
3✔
260
      return "" if requestable.item.blank?
×
261
      content_tag(:div, requestable.item[:status], class: 'system-status')
×
262
    end
263

264
    def display_urls(requestable)
3✔
265
      content_tag :ol do
×
266
        requestable.urls.each do |key, value|
×
267
          unless key == 'iiif_manifest_paths'
×
268
            value.reverse!
×
269
            concat content_tag(:li, link_to(value.join(": "), key), class: 'link')
×
270
          end
271
        end
272
      end
273
    end
274

275
    def self.recap_annex_available_pick_ups(requestable, default_pick_ups)
3✔
276
      locations = requestable.pick_up_locations || default_pick_ups
65✔
277
      pick_ups = locations.select { |loc| Requests::Location.valid_recap_annex_pickup?(loc) }
762✔
278
      pick_ups << default_pick_ups[0] if pick_ups.empty?
65✔
279
      pick_ups
65✔
280
    end
281

282
    private
3✔
283

284
      def custom_pickup_prompt(requestable, locs)
3✔
285
        # For ReCAP items, return nil to use default prompt
286
        return nil if requestable.recap?
71✔
287

288
        holding_library = normalize_holding_library(requestable)
24✔
289
        return nil if holding_library.blank?
24✔
290

291
        find_prompt_for_holding_library(holding_library, locs)
24✔
292
      end
293

294
      # :reek:UtilityFunction
295
      def normalize_holding_library(requestable)
3✔
296
        requestable.holding_library&.downcase
41✔
297
      end
298

299
      def find_prompt_for_holding_library(holding_library, locs)
3✔
300
        # Check for special engineering library cases first
301
        engineering_prompt = engineering_library_prompt(holding_library, locs)
24✔
302
        return engineering_prompt if engineering_prompt
24✔
303

304
        # Find matching library by code and suggest it in the prompt
305
        suggested_location = find_matching_location_label(holding_library, locs)
20✔
306
        return unless suggested_location
20✔
307
        "Select a Delivery Location (Recommended: #{suggested_location})"
4✔
308
      end
309

310
      def find_matching_location_label(holding_library, locs)
3✔
311
        matching_loc = find_matching_location_by_code(holding_library, locs)
20✔
312
        matching_loc&.dig(:label)
20✔
313
      end
314

315
      # :reek:UtilityFunction
316
      def find_matching_location_by_code(holding_library, locs)
3✔
317
        locs.find do |loc|
35✔
318
          # Extract library code and compare with holding library
319
          library_code = loc.dig(:library, :code)
173✔
320
          library_code&.downcase == holding_library
173✔
321
        end
322
      end
323

324
      # :reek:UtilityFunction
325
      def engineering_library_prompt(holding_library, locs)
3✔
326
        # Special case: lewis, plasma should default to Engineering Library
327
        if ['lewis', 'plasma'].include?(holding_library)
24✔
328
          engineering_loc = locs.find { |loc| loc[:label] == "Engineering Library" }
16✔
329
          return "Select a Delivery Location (Recommended: #{engineering_loc[:label]})" if engineering_loc
5✔
330
        end
331
        nil
20✔
332
      end
333

334
      # :reek:UtilityFunction
335
      # :reek:TooManyStatements
336
      def find_selected_pickup_value(requestable, locs)
3✔
337
        # For ReCAP items, don't pre-select anything
338
        return nil if requestable.recap?
64✔
339

340
        holding_library = normalize_holding_library(requestable)
17✔
341
        return nil if holding_library.blank?
17✔
342

343
        # Check for special engineering library cases first
344
        if ['lewis', 'plasma'].include?(holding_library)
17✔
345
          engineering_loc = locs.find { |loc| loc[:label] == "Engineering Library" }
6✔
346
          return { 'pick_up' => engineering_loc[:gfa_pickup], 'pick_up_location_code' => engineering_loc[:pick_up_location_code] }.to_json if engineering_loc
2✔
347
        end
348

349
        # Find matching library by code and select it
350
        matching_loc = find_matching_location_by_code(holding_library, locs)
15✔
351
        return nil unless matching_loc
15✔
352

353
        { 'pick_up' => matching_loc[:gfa_pickup], 'pick_up_location_code' => matching_loc[:pick_up_location_code] }.to_json
1✔
354
      end
355

356
      def display_requestable_list(requestable)
3✔
357
        return if requestable.no_services?
142✔
358
        content_tag(:ul, class: "service-list") do
140✔
359
          if requestable.ill_eligible?
140✔
360
            concat content_tag(:li, sanitize(I18n.t("requests.ill.brief_msg")), class: "service-item")
1✔
361
          else
362
            # there are no instances where more than one actual service is available to an item, so we are going to take the first service that is not edd
363
            filtered_services = if requestable.services.size == 1 && requestable.services.first.include?("edd")
139✔
NEW
364
                                  requestable.services
×
365
                                else
366
                                  requestable.services.reject { |service_name| service_name.include?("edd") }
402✔
367
                                end
368
            brief_msg = I18n.t("requests.#{filtered_services.first}.brief_msg")
139✔
369
            concat content_tag(:li, sanitize(brief_msg), class: "service-item")
139✔
370
          end
371
        end
372
      end
373

374
      def display_on_shelf(requestable, _mfhd_id)
3✔
375
        content_tag(:div) do
70✔
376
          display_requestable_list(requestable)
70✔
377
        end
378
      end
379

380
      def pick_up_locations(requestable, default_pick_ups)
3✔
381
        # we don't want to change the ill_eligible rules
382
        return [default_pick_ups[0]] if requestable.ill_eligible?
146✔
383
        return Requests::ApplicationHelper.recap_annex_available_pick_ups(requestable, default_pick_ups) if requestable.recap? || requestable.annex?
144✔
384
        return default_pick_ups if requestable.location&.standard_circ_location?
82✔
385
        if requestable.delivery_location_label.present?
79✔
386
          [{ label: requestable.delivery_location_label, gfa_pickup: requestable.delivery_location_code, pick_up_location_code: requestable.pick_up_location_code, staff_only: false }]
72✔
387
        else
388
          [{ label: requestable.location.library_label, gfa_pickup: gfa_lookup(requestable.location.library_code), staff_only: false }]
7✔
389
        end
390
      end
391

392
      def hidden_fields_for_item(item:, preferred_request_id:)
3✔
393
        hidden = hidden_field_tag("requestable[][item_id]", "", value: preferred_request_id.to_s, id: "requestable_item_id_#{preferred_request_id}")
521✔
394
        hidden += hidden_field_tag("requestable[][barcode]", "", value: item['barcode'].to_s, id: "requestable_barcode_#{preferred_request_id}") unless item["barcode"].nil?
521✔
395
        hidden += hidden_field_tag("requestable[][enum]", "", value: item.enum_value.to_s, id: "requestable_enum_#{preferred_request_id}") if item.enum_value.present?
521✔
396
        hidden += hidden_field_tag("requestable[][copy_number]", "", value: item.copy_number.to_s, id: "requestable_copy_number_#{preferred_request_id}")
521✔
397
        hidden + hidden_field_tag("requestable[][status]", "", value: item['status'].to_s, id: "requestable_status_#{preferred_request_id}")
521✔
398
      end
399

400
      def hidden_fields_for_scsb(item:)
3✔
401
        hidden = hidden_field_tag("requestable[][cgd]", "", value: item['cgd'].to_s, id: "requestable_cgd_#{item['id']}")
6✔
402
        hidden += hidden_field_tag("requestable[][cc]", "", value: item['collection_code'].to_s, id: "requestable_collection_code_#{item['id']}")
6✔
403
        hidden + hidden_field_tag("requestable[][use_statement]", "", value: item['use_statement'].to_s, id: "requestable_use_statement_#{item['id']}")
6✔
404
      end
405

406
      def single_pickup(is_charged, name, id, location)
3✔
407
        style = if is_charged
80✔
UNCOV
408
                  'margin-top:10px;'
×
409
                else
410
                  ''
80✔
411
                end
412
        hidden = hidden_field_tag name.to_s, "", value: { 'pick_up' => location[:gfa_pickup], 'pick_up_location_code' => location[:pick_up_location_code] }.to_json, class: 'single-pick-up-hidden', id: id
80✔
413
        label = label_tag id, "Pick-up location: #{location[:label]}", class: 'single-pick-up', style: style.to_s
80✔
414
        hidden + label
80✔
415
      end
416

417
      def aeon_base
3✔
418
        Requests.config[:aeon_base]
×
419
      end
420
  end
421
end
422
# rubocop:enable Metrics/ModuleLength
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