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

pulibrary / orangelight / ee1de450-1266-4e8a-8cf8-b03ae9b71f85

05 Sep 2023 06:53PM UTC coverage: 95.31% (-0.07%) from 95.382%
ee1de450-1266-4e8a-8cf8-b03ae9b71f85

push

circleci

sandbergja
Remove advanced search controller

- Per @kevinreiss, this behavior is no longer needed, either with or without the BlacklightAdvancedSearch gem

5568 of 5842 relevant lines covered (95.31%)

1415.9 hits per line

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

88.04
/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
178✔
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?
165✔
29
        display_on_shelf(requestable, mfhd_id)
83✔
30
      else
31
        display_requestable_list(requestable)
80✔
32
      end
33
    end
34

35
    def show_service_options(requestable, _mfhd_id)
3✔
36
      if requestable.no_services?
4✔
37
        content_tag(:div, "#{requestable.title} #{enum_copy_display(requestable.item)} #{sanitize(I18n.t('requests.no_services.brief_msg'))}", class: 'sr-only') +
2✔
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
148✔
48
      hidden = output_request_input(requestable)
133✔
49
      return hidden if hidden.present?
133✔
50

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

58
    def output_request_input(requestable)
3✔
59
      output = ""
133✔
60
      ['annex', 'pres', 'ppl', 'lewis', 'paging', 'on_order', 'trace', 'on_shelf'].each do |type|
133✔
61
        next unless requestable.services.include?(type)
1,001✔
62
        output = request_input(type)
80✔
63
        break
80✔
64
      end
65
      output
133✔
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?
15✔
71
        request_input('annex')
2✔
72
      elsif requestable.services.include? 'recap_no_items'
13✔
73
        request_input('recap_no_items')
1✔
74
      else
75
        request_input('paging')
12✔
76
      end
77
    end
78

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

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

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

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

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

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

120
    def preferred_request_content_tag(requestable, default_pick_ups)
3✔
121
      (show_pick_up_service_options(requestable, nil) || "".html_safe) +
162✔
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)
160✔
124
          # temporary changes issue 438
125
          name = 'requestable[][pick_up]'
160✔
126
          id = "requestable__pick_up_#{requestable.preferred_request_id}"
160✔
127
          if locs.size > 1
160✔
128
            select_tag name.to_s, options_for_select(locs.map { |loc| [loc[:label], { 'pick_up' => loc[:gfa_pickup], 'pick_up_location_code' => loc[:pick_up_location_code] }.to_json] }), prompt: I18n.t("requests.default.pick_up_placeholder"), id: id
550✔
129
          else
130
            single_pickup(requestable.charged?, name, id, locs[0])
101✔
131
          end
132
        end
133
    end
134

135
    def available_pick_ups(requestable, default_pick_ups)
3✔
136
      idx = (default_pick_ups.pluck(:label)).index(requestable.location["library"]["label"]) # || 0
149✔
137
      if idx.present?
149✔
138
        [default_pick_ups[idx]]
52✔
139
      elsif requestable.recap? || requestable.annex?
97✔
140
        locations = requestable.pick_up_locations || default_pick_ups
61✔
141
        # open libraries
142
        pick_ups = locations.select { |loc| ['PJ', 'PA', 'PL', 'PK', 'PM', 'QX', 'PW', 'PN', 'QA', 'QT', 'QC'].include?(loc[:gfa_pickup]) }
756✔
143
        pick_ups << default_pick_ups[0] if pick_ups.empty?
61✔
144
        pick_ups
61✔
145
      else
146
        [default_pick_ups[0]]
36✔
147
      end
148
      # return
149
      # temporary only deliver to holding library or firestone
150
      # locs = []
151
      # if requestable.services.include? 'trace'
152
      #   locs = default_pick_ups
153
      # elsif requestable.pick_up_locations.nil?
154
      #   locs = default_pick_ups
155
      # else
156
      #   requestable.pick_up_locations.each do |location|
157
      #     locs << { label: location[:label], gfa_pickup: location[:gfa_pickup], staff_only: location[:staff_only] }
158
      #   end
159
      # end
160
      # locs
161
    end
162

163
    # rubocop:disable Rails/OutputSafety
164
    def hidden_fields_mfhd(mfhd)
3✔
165
      hidden = ""
85✔
166
      return hidden if mfhd.nil?
85✔
167
      hidden += hidden_field_tag "mfhd[][call_number]", "", value: (mfhd['call_number']).to_s unless mfhd["call_number"].nil?
84✔
168
      hidden += hidden_field_tag "mfhd[][location]", "", value: (mfhd['location']).to_s unless mfhd["location"].nil?
84✔
169
      hidden += hidden_field_tag "mfhd[][library]", "", value: (mfhd['library']).to_s
84✔
170
      hidden.html_safe
84✔
171
    end
172
    # rubocop:enable Rails/OutputSafety
173

174
    def hidden_fields_item(requestable)
3✔
175
      request_id = requestable.preferred_request_id
211✔
176
      hidden = hidden_field_tag "requestable[][bibid]", "", value: requestable.bib[:id].to_s, id: "requestable_bibid_#{request_id}"
211✔
177
      hidden += hidden_field_tag "requestable[][mfhd]", "", value: requestable.holding.keys[0].to_s, id: "requestable_mfhd_#{request_id}"
211✔
178
      hidden += hidden_field_tag "requestable[][call_number]", "", value: (requestable.holding.first[1]['call_number']).to_s, id: "requestable_call_number_#{request_id}" unless requestable.holding.first[1]["call_number"].nil?
211✔
179
      hidden += hidden_field_tag "requestable[][location_code]", "", value: requestable.item_location_code.to_s, id: "requestable_location_#{request_id}"
211✔
180
      hidden += if requestable.item?
211✔
181
                  hidden_fields_for_item(item: requestable.item, preferred_request_id: requestable.preferred_request_id)
194✔
182
                else
183
                  hidden_field_tag("requestable[][item_id]", "", value: requestable.preferred_request_id, id: "requestable_item_id_#{requestable.preferred_request_id}")
17✔
184
                end
185
      hidden += hidden_fields_for_scsb(item: requestable.item) if requestable.partner_holding?
211✔
186
      hidden
211✔
187
    end
188

189
    def hidden_fields_holding(requestable)
3✔
190
      hidden = hidden_field_tag "requestable[][mfhd]", "", value: requestable.holding.keys[0].to_s, id: "requestable_mfhd_#{requestable.holding.keys[0]}"
×
191
      hidden += hidden_field_tag "requestable[][call_number]", "", value: (requestable.holding.first[1]['call_number']).to_s, id: "requestable_call_number_#{requestable.holding.keys[0]}" unless requestable.holding.first[1]["call_number"].nil?
×
192
      hidden += hidden_field_tag "requestable[][location_code]", "", value: (requestable.holding.first[1]['location_code']).to_s, id: "requestable_location_code_#{requestable.holding.keys[0]}"
×
193
      hidden += hidden_field_tag "requestable[][location]", "", value: (requestable.holding.first[1]['location']).to_s, id: "requestable_location_#{requestable.holding.keys[0]}"
×
194
      sanitize(hidden, tags: input)
×
195
    end
196

197
    def isbn_string(array_of_isbns)
3✔
198
      array_of_isbns.join(',')
1✔
199
    end
200

201
    def suppress_login(request)
3✔
202
      request.only_aeon?
91✔
203
    end
204

205
    def item_checkbox(requestable, single_item_form)
3✔
206
      disabled = !requestable.will_submit_via_form?
187✔
207
      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}"
187✔
208
    end
209

210
    ## If any requestable items have a temp location assume everything at the holding is in a temp loc?
211
    def current_location_label(mfhd_label, requestable_list)
3✔
212
      location_label = requestable_list.first.location['label'].blank? ? "" : "- #{requestable_list.first.location['label']}"
167✔
213
      label = if requestable_list.first.temp_loc?.present? && !requestable_list.first.in_resource_sharing?
167✔
214
                "#{requestable_list.first.location['library']['label']}#{location_label}"
8✔
215
              else
216
                mfhd_label
159✔
217
              end
218
      "#{label} #{requestable_list.first.call_number}"
167✔
219
    end
220

221
    def check_box_selected(disabled, single_item_form)
3✔
222
      if single_item_form
187✔
223
        !disabled
45✔
224
      else
225
        false
142✔
226
      end
227
    end
228

229
    def submit_button_disabled(requestable_list)
3✔
230
      # temporary chane issue 438 guest can no longer check out materials
231
      return true if @user.blank? || @user.guest
64✔
232
      return unsubmittable? requestable_list unless requestable_list.size == 1
62✔
233
      # temporary changes issue 438 do not disable the button for circulating items
234
      # requestable_list.first.services.empty? || requestable_list.first.on_reserve? || (requestable_list.first.services.include? 'on_shelf') || requestable_list.first.ask_me?
235
      requestable_list.first.services.empty? || requestable_list.first.on_reserve?
50✔
236
    end
237

238
    def unsubmittable?(requestable_list)
3✔
239
      !requestable_list.any? { |requestable| (requestable.services | submitable_services).present? }
24✔
240
    end
241

242
    def submitable_services
3✔
243
      ['on_shelf', 'in_process', 'on_order', 'annex', 'recap', 'recap_edd', 'paging', 'recap_no_items', 'ppl', 'lewis']
12✔
244
    end
245

246
    def submit_message(requestable_list)
3✔
247
      single_item = "Request this Item"
60✔
248
      multi_item = "Request Selected Items"
60✔
249
      no_item = "No Items Available"
60✔
250
      return multi_item unless requestable_list.size == 1
60✔
251
      if requestable_list.first.services.empty?
48✔
252
        no_item
×
253
      elsif requestable_list.first.charged?
48✔
254
        return multi_item if requestable_list.first.annex? || requestable_list.first.pageable_loc?
5✔
255
        single_item # no_item
5✔
256
      else
257
        submit_message_for_requestable_items(requestable_list)
43✔
258
      end
259
    end
260

261
    def submit_message_for_requestable_items(requestable_list)
3✔
262
      single_item = "Request this Item"
43✔
263
      multi_item = "Request Selected Items"
43✔
264
      trace = "Trace this item"
43✔
265
      if requestable_list.first.annex? || requestable_list.first.pageable_loc?
43✔
266
        multi_item
3✔
267
      elsif requestable_list.first.traceable?
40✔
268
        trace
×
269
      else
270
        single_item
40✔
271
      end
272
    end
273

274
    # only show the table sort if there are enough items
275
    # to make it worthwhile
276
    def show_tablesorter(requestable_list)
3✔
277
      return "tablesorter" if table_sorter_present?(requestable_list)
84✔
278
      ""
75✔
279
    end
280

281
    def table_sorter_present?(requestable_list)
3✔
282
      requestable_list.size > 5
129✔
283
    end
284

285
    def display_label
3✔
286
      {
445✔
287
        author: "Author/Artist",
288
        title: "Title",
289
        date: "Published/Created",
290
        id: "Bibliographic ID",
291
        mfhd: "Holding ID (mfhd)"
292
      }.with_indifferent_access
293
    end
294

295
    # def display_language
296
    #   {
297
    #     language: "Language:"
298
    #   }.with_indifferent_access
299
    # end
300

301
    def display_status(requestable)
3✔
302
      content_tag(:span, requestable.item['status']) unless requestable.item.nil?
×
303
    end
304

305
    def system_status_label(requestable)
3✔
306
      return "" if requestable.item.blank?
×
307
      content_tag(:div, requestable.item[:status], class: 'system-status')
×
308
    end
309

310
    def display_urls(requestable)
3✔
311
      content_tag :ol do
×
312
        requestable.urls.each do |key, value|
×
313
          unless key == 'iiif_manifest_paths'
×
314
            value.reverse!
×
315
            concat content_tag(:li, link_to(value.join(": "), key), class: 'link')
×
316
          end
317
        end
318
      end
319
    end
320

321
    private
3✔
322

323
      def display_requestable_list(requestable)
3✔
324
        return if requestable.no_services?
164✔
325
        content_tag(:ul, class: "service-list") do
155✔
326
          if requestable.ill_eligible?
155✔
327
            concat content_tag(:li, sanitize(I18n.t("requests.ill.brief_msg")), class: "service-item")
1✔
328
          else
329
            # 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
330
            filtered_services = if requestable.services.size == 1 && requestable.services.first.include?("edd")
154✔
331
                                  requestable.services
×
332
                                else
333
                                  requestable.services.reject { |service_name| service_name.include?("edd") }
438✔
334
                                end
335
            brief_msg = I18n.t("requests.#{filtered_services.first}.brief_msg")
154✔
336
            concat content_tag(:li, sanitize(brief_msg), class: "service-item")
154✔
337
          end
338
        end
339
      end
340

341
      def display_on_shelf(requestable, _mfhd_id)
3✔
342
        content_tag(:div) do
83✔
343
          display_requestable_list(requestable)
83✔
344
          # temporary changes issue 438
345
          # concat link_to 'Where to find it', requestable.map_url(mfhd_id)
346
          # concat content_tag(:div, sanitize(I18n.t("requests.trace.brief_msg")), class: 'service-item') if requestable.traceable?
347
        end
348
      end
349

350
      def pick_up_locations(requestable, default_pick_ups)
3✔
351
        return [default_pick_ups[0]] if requestable.ill_eligible?
160✔
352
        return available_pick_ups(requestable, default_pick_ups) unless requestable.pending?
158✔
353
        if requestable.delivery_location_label.present?
9✔
354
          [{ label: requestable.delivery_location_label, gfa_pickup: requestable.delivery_location_code, pick_up_location_code: requestable.pick_up_location_code, staff_only: false }]
7✔
355
        else
356
          # TODO: Why is this option here
357
          [{ label: requestable.location[:library][:label], gfa_pickup: gfa_lookup(requestable.location[:library][:code]), staff_only: false }]
2✔
358
        end
359
      end
360

361
      def hidden_fields_for_item(item:, preferred_request_id:)
3✔
362
        hidden = hidden_field_tag("requestable[][item_id]", "", value: preferred_request_id.to_s, id: "requestable_item_id_#{preferred_request_id}")
194✔
363
        hidden += hidden_field_tag("requestable[][barcode]", "", value: item['barcode'].to_s, id: "requestable_barcode_#{preferred_request_id}") unless item["barcode"].nil?
194✔
364
        hidden += hidden_field_tag("requestable[][enum]", "", value: item.enum_value.to_s, id: "requestable_enum_#{preferred_request_id}") if item.enum_value.present?
194✔
365
        hidden += hidden_field_tag("requestable[][copy_number]", "", value: item.copy_number.to_s, id: "requestable_copy_number_#{preferred_request_id}")
194✔
366
        hidden + hidden_field_tag("requestable[][status]", "", value: item['status'].to_s, id: "requestable_status_#{preferred_request_id}")
194✔
367
      end
368

369
      def hidden_fields_for_scsb(item:)
3✔
370
        hidden = hidden_field_tag("requestable[][cgd]", "", value: item['cgd'].to_s, id: "requestable_cgd_#{item['id']}")
8✔
371
        hidden += hidden_field_tag("requestable[][cc]", "", value: item['collection_code'].to_s, id: "requestable_collection_code_#{item['id']}")
8✔
372
        hidden + hidden_field_tag("requestable[][use_statement]", "", value: item['use_statement'].to_s, id: "requestable_use_statement_#{item['id']}")
8✔
373
      end
374

375
      def single_pickup(is_charged, name, id, location)
3✔
376
        style = if is_charged
101✔
377
                  'margin-top:10px;'
1✔
378
                else
379
                  ''
100✔
380
                end
381
        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
101✔
382
        label = label_tag id, "Pick-up location: #{location[:label]}", class: 'single-pick-up', style: style.to_s
101✔
383
        hidden + label
101✔
384
      end
385

386
      def aeon_base
3✔
387
        Flipflop.deprecated_aeon_base? ? Requests::Config[:aeon_base_deprecated] : Requests::Config[:aeon_base]
1✔
388
      end
389
  end
390
end
391
# 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