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

pulibrary / orangelight / 9b4e80f3-97f9-464d-b38b-43db731a647f

06 Sep 2024 03:21PM UTC coverage: 95.899% (+0.1%) from 95.762%
9b4e80f3-97f9-464d-b38b-43db731a647f

push

circleci

web-flow
Merge pull request #4241 from pulibrary/i4176_remove_unused_methods

I4176 remove unused methods

2 of 2 new or added lines in 2 files covered. (100.0%)

1 existing line in 1 file now uncovered.

5869 of 6120 relevant lines covered (95.9%)

1413.92 hits per line

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

87.98
/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
170✔
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?
158✔
29
        display_on_shelf(requestable, mfhd_id)
78✔
30
      else
31
        display_requestable_list(requestable)
78✔
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
141✔
48
      hidden = output_request_input(requestable)
127✔
49
      return hidden if hidden.present?
127✔
50

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

58
    def output_request_input(requestable)
3✔
59
      output = ""
127✔
60
      ['annex', 'pres', 'ppl', 'lewis', 'paging', 'on_order', 'trace', 'on_shelf'].each do |type|
127✔
61
        next unless requestable.services.include?(type)
953✔
62
        output = request_input(type)
75✔
63
        break
75✔
64
      end
65
      output
127✔
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?
14✔
71
        request_input('annex')
2✔
72
      elsif requestable.services.include? 'recap_no_items'
12✔
73
        request_input('recap_no_items')
1✔
74
      else
75
        request_input('paging')
11✔
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
39✔
81
        concat hidden_field_tag "requestable[][type]", "", value: 'recap'
39✔
82
      end
83
    end
84

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

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

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

105
    def pick_up_classlist(requestable, collapse)
3✔
106
      class_list = "collapse request--print"
160✔
107
      class_list += " show" if !requestable.digitize? && !collapse
160✔
108
      class_list
160✔
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
147✔
115
        preferred_request_content_tag(requestable, requestable.pick_up_locations || default_pick_ups)
147✔
116
      end
117
    end
118

119
    def preferred_request_content_tag(requestable, default_pick_ups)
3✔
120
      (show_pick_up_service_options(requestable, nil) || "".html_safe) +
155✔
121
        content_tag(:div, id: "fields-print__#{requestable.preferred_request_id}_card", class: "card card-body bg-light") do
122
          locs = pick_up_locations(requestable, default_pick_ups)
153✔
123
          # temporary changes issue 438
124
          name = 'requestable[][pick_up]'
153✔
125
          id = "requestable__pick_up_#{requestable.preferred_request_id}"
153✔
126
          if locs.size > 1
153✔
127
            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✔
128
          else
129
            single_pickup(requestable.charged?, name, id, locs[0])
94✔
130
          end
131
        end
132
    end
133

134
    def available_pick_ups(requestable, default_pick_ups)
3✔
135
      idx = (default_pick_ups.pluck(:label)).index(Requests::Location.new(requestable.location).library_label)
142✔
136
      if idx.present?
142✔
137
        [default_pick_ups[idx]]
49✔
138
      elsif requestable.recap? || requestable.annex?
93✔
139
        locations = requestable.pick_up_locations || default_pick_ups
60✔
140
        # open libraries
141
        pick_ups = locations.select { |loc| ['PJ', 'PA', 'PL', 'PK', 'PM', 'QX', 'PW', 'PN', 'QA', 'QT', 'QC'].include?(loc[:gfa_pickup]) }
754✔
142
        pick_ups << default_pick_ups[0] if pick_ups.empty?
60✔
143
        pick_ups
60✔
144
      else
145
        [default_pick_ups[0]]
33✔
146
      end
147
    end
148

149
    # rubocop:disable Rails/OutputSafety
150
    def hidden_fields_mfhd(mfhd)
3✔
151
      hidden = ""
83✔
152
      return hidden if mfhd.nil?
83✔
153
      hidden += hidden_field_tag "mfhd[][call_number]", "", value: (mfhd['call_number']).to_s unless mfhd["call_number"].nil?
82✔
154
      hidden += hidden_field_tag "mfhd[][location]", "", value: (mfhd['location']).to_s unless mfhd["location"].nil?
82✔
155
      hidden += hidden_field_tag "mfhd[][library]", "", value: (mfhd['library']).to_s
82✔
156
      hidden.html_safe
82✔
157
    end
158
    # rubocop:enable Rails/OutputSafety
159

160
    def hidden_fields_item(requestable)
3✔
161
      request_id = requestable.preferred_request_id
567✔
162
      hidden = hidden_field_tag "requestable[][bibid]", "", value: requestable.bib[:id].to_s, id: "requestable_bibid_#{request_id}"
567✔
163
      hidden += hidden_field_tag "requestable[][mfhd]", "", value: requestable.holding.keys[0].to_s, id: "requestable_mfhd_#{request_id}"
567✔
164
      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?
567✔
165
      hidden += hidden_field_tag "requestable[][location_code]", "", value: requestable.item_location_code.to_s, id: "requestable_location_#{request_id}"
567✔
166
      hidden += if requestable.item?
567✔
167
                  hidden_fields_for_item(item: requestable.item, preferred_request_id: requestable.preferred_request_id)
551✔
168
                else
169
                  hidden_field_tag("requestable[][item_id]", "", value: requestable.preferred_request_id, id: "requestable_item_id_#{requestable.preferred_request_id}")
16✔
170
                end
171
      hidden += hidden_fields_for_scsb(item: requestable.item) if requestable.partner_holding?
567✔
172
      hidden
567✔
173
    end
174

175
    def hidden_fields_holding(requestable)
3✔
176
      hidden = hidden_field_tag "requestable[][mfhd]", "", value: requestable.holding.keys[0].to_s, id: "requestable_mfhd_#{requestable.holding.keys[0]}"
×
177
      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?
×
178
      hidden += hidden_field_tag "requestable[][location_code]", "", value: (requestable.holding.first[1]['location_code']).to_s, id: "requestable_location_code_#{requestable.holding.keys[0]}"
×
179
      hidden += hidden_field_tag "requestable[][location]", "", value: (requestable.holding.first[1]['location']).to_s, id: "requestable_location_#{requestable.holding.keys[0]}"
×
180
      sanitize(hidden, tags: input)
×
181
    end
182

183
    def isbn_string(array_of_isbns)
3✔
184
      array_of_isbns.join(',')
1✔
185
    end
186

187
    def suppress_login(request)
3✔
188
      request.only_aeon?
87✔
189
    end
190

191
    def item_checkbox(requestable, single_item_form)
3✔
192
      disabled = !requestable.will_submit_via_form?
544✔
193
      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}"
544✔
194
    end
195

196
    ## If any requestable items have a temp location assume everything at the holding is in a temp loc?
197
    def current_location_label(holding_location_label, requestable_list)
3✔
198
      first_location = Requests::Location.new(requestable_list.first.location)
163✔
199
      location_label = first_location.short_label.blank? ? "" : "- #{first_location.short_label}"
163✔
200
      label = if requestable_list.first.temp_loc_other_than_resource_sharing?
163✔
201
                "#{first_location.library_label}#{location_label}"
8✔
202
              else
203
                holding_location_label
155✔
204
              end
205
      "#{label} #{requestable_list.first.call_number}"
163✔
206
    end
207

208
    def check_box_selected(disabled, single_item_form)
3✔
209
      if single_item_form
544✔
210
        !disabled
45✔
211
      else
212
        false
499✔
213
      end
214
    end
215

216
    def submit_button_disabled(requestable_list)
3✔
217
      # temporary chane issue 438 guest can no longer check out materials
218
      return true if @user.blank? || @user.guest
62✔
219
      return unsubmittable? requestable_list unless requestable_list.size == 1
60✔
220
      # temporary changes issue 438 do not disable the button for circulating items
221
      # requestable_list.first.services.empty? || requestable_list.first.on_reserve? || (requestable_list.first.services.include? 'on_shelf') || requestable_list.first.ask_me?
222
      requestable_list.first.services.empty? || requestable_list.first.on_reserve?
49✔
223
    end
224

225
    def unsubmittable?(requestable_list)
3✔
226
      !requestable_list.any? { |requestable| (requestable.services | submitable_services).present? }
22✔
227
    end
228

229
    def submitable_services
3✔
230
      ['on_shelf', 'in_process', 'on_order', 'annex', 'recap', 'recap_edd', 'paging', 'recap_no_items', 'ppl', 'lewis']
11✔
231
    end
232

233
    def submit_message(requestable_list)
3✔
234
      single_item = "Request this Item"
58✔
235
      multi_item = "Request Selected Items"
58✔
236
      no_item = "No Items Available"
58✔
237
      return multi_item unless requestable_list.size == 1
58✔
238
      if requestable_list.first.services.empty?
47✔
239
        no_item
×
240
      elsif requestable_list.first.charged?
47✔
241
        return multi_item if requestable_list.first.annex? || requestable_list.first.pageable_loc?
4✔
242
        single_item # no_item
4✔
243
      else
244
        submit_message_for_requestable_items(requestable_list)
43✔
245
      end
246
    end
247

248
    def submit_message_for_requestable_items(requestable_list)
3✔
249
      single_item = "Request this Item"
43✔
250
      multi_item = "Request Selected Items"
43✔
251
      if requestable_list.first.annex? || requestable_list.first.pageable_loc?
43✔
252
        multi_item
3✔
253
      else
254
        single_item
40✔
255
      end
256
    end
257

258
    # only show the table sort if there are enough items
259
    # to make it worthwhile
260
    def show_tablesorter(requestable_list)
3✔
261
      return "tablesorter" if table_sorter_present?(requestable_list)
82✔
262
      ""
72✔
263
    end
264

265
    def table_sorter_present?(requestable_list)
3✔
266
      requestable_list.size > 5
124✔
267
    end
268

269
    def display_label
3✔
270
      {
×
271
        author: "Author/Artist",
272
        title: "Title",
273
        date: "Published/Created",
274
        id: "Bibliographic ID",
275
        mfhd: "Holding ID (mfhd)"
276
      }.with_indifferent_access
277
    end
278

279
    def display_status(requestable)
3✔
UNCOV
280
      content_tag(:span, requestable.item['status']) unless requestable.item.nil?
×
281
    end
282

283
    def system_status_label(requestable)
3✔
284
      return "" if requestable.item.blank?
×
285
      content_tag(:div, requestable.item[:status], class: 'system-status')
×
286
    end
287

288
    def display_urls(requestable)
3✔
289
      content_tag :ol do
×
290
        requestable.urls.each do |key, value|
×
291
          unless key == 'iiif_manifest_paths'
×
292
            value.reverse!
×
293
            concat content_tag(:li, link_to(value.join(": "), key), class: 'link')
×
294
          end
295
        end
296
      end
297
    end
298

299
    private
3✔
300

301
      def display_requestable_list(requestable)
3✔
302
        return if requestable.no_services?
157✔
303
        content_tag(:ul, class: "service-list") do
149✔
304
          if requestable.ill_eligible?
149✔
305
            concat content_tag(:li, sanitize(I18n.t("requests.ill.brief_msg")), class: "service-item")
1✔
306
          else
307
            # 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
308
            filtered_services = if requestable.services.size == 1 && requestable.services.first.include?("edd")
148✔
309
                                  requestable.services
×
310
                                else
311
                                  requestable.services.reject { |service_name| service_name.include?("edd") }
420✔
312
                                end
313
            brief_msg = I18n.t("requests.#{filtered_services.first}.brief_msg")
148✔
314
            concat content_tag(:li, sanitize(brief_msg), class: "service-item")
148✔
315
          end
316
        end
317
      end
318

319
      def display_on_shelf(requestable, _mfhd_id)
3✔
320
        content_tag(:div) do
78✔
321
          display_requestable_list(requestable)
78✔
322
          # temporary changes issue 438
323
          # concat link_to 'Where to find it', requestable.map_url(mfhd_id)
324
        end
325
      end
326

327
      def pick_up_locations(requestable, default_pick_ups)
3✔
328
        return [default_pick_ups[0]] if requestable.ill_eligible?
153✔
329
        return available_pick_ups(requestable, default_pick_ups) unless requestable.pending?
151✔
330
        if requestable.delivery_location_label.present?
9✔
331
          [{ label: requestable.delivery_location_label, gfa_pickup: requestable.delivery_location_code, pick_up_location_code: requestable.pick_up_location_code, staff_only: false }]
7✔
332
        else
333
          # TODO: Why is this option here
334
          location_object = Requests::Location.new requestable.location
2✔
335
          [{ label: location_object.library_label, gfa_pickup: gfa_lookup(location_object.library_code), staff_only: false }]
2✔
336
        end
337
      end
338

339
      def hidden_fields_for_item(item:, preferred_request_id:)
3✔
340
        hidden = hidden_field_tag("requestable[][item_id]", "", value: preferred_request_id.to_s, id: "requestable_item_id_#{preferred_request_id}")
551✔
341
        hidden += hidden_field_tag("requestable[][barcode]", "", value: item['barcode'].to_s, id: "requestable_barcode_#{preferred_request_id}") unless item["barcode"].nil?
551✔
342
        hidden += hidden_field_tag("requestable[][enum]", "", value: item.enum_value.to_s, id: "requestable_enum_#{preferred_request_id}") if item.enum_value.present?
551✔
343
        hidden += hidden_field_tag("requestable[][copy_number]", "", value: item.copy_number.to_s, id: "requestable_copy_number_#{preferred_request_id}")
551✔
344
        hidden + hidden_field_tag("requestable[][status]", "", value: item['status'].to_s, id: "requestable_status_#{preferred_request_id}")
551✔
345
      end
346

347
      def hidden_fields_for_scsb(item:)
3✔
348
        hidden = hidden_field_tag("requestable[][cgd]", "", value: item['cgd'].to_s, id: "requestable_cgd_#{item['id']}")
7✔
349
        hidden += hidden_field_tag("requestable[][cc]", "", value: item['collection_code'].to_s, id: "requestable_collection_code_#{item['id']}")
7✔
350
        hidden + hidden_field_tag("requestable[][use_statement]", "", value: item['use_statement'].to_s, id: "requestable_use_statement_#{item['id']}")
7✔
351
      end
352

353
      def single_pickup(is_charged, name, id, location)
3✔
354
        style = if is_charged
94✔
355
                  'margin-top:10px;'
1✔
356
                else
357
                  ''
93✔
358
                end
359
        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
94✔
360
        label = label_tag id, "Pick-up location: #{location[:label]}", class: 'single-pick-up', style: style.to_s
94✔
361
        hidden + label
94✔
362
      end
363

364
      def aeon_base
3✔
365
        Requests::Config[:aeon_base]
1✔
366
      end
367
  end
368
end
369
# 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