• 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/holdings_helper.rb
1
# frozen_string_literal: false
2

3
# rubocop:disable Metrics/ModuleLength
4
module HoldingsHelper
×
5
  # Generate the markup block for individual search result items containing holding information
6
  # @param document [SolrDocument] the Solr Document retrieved in the search result set
7
  # @return [String] the markup
8

9
  # rubocop:disable Metrics/MethodLength
10
  def holding_block_search(document)
×
11
    block = ''.html_safe
×
12
    block_extra = ''.html_safe
×
13
    holdings_hash = document.holdings_all_display.sort { |a, b| sort_holdings(a, b) }
×
14
    @scsb_multiple = false
×
15
    if holdings_hash.count <= 4
×
16
      holdings_hash.each do |id, holding|
×
17
        block << holdings_block(document, id, holding)
×
18
      end
×
19
    elsif holdings_hash.count > 4
×
20
      holdings_array = holdings_hash.to_a
×
21
      holdings_array_first_three = holdings_array.first(3)
×
22
      holdings_array.count
×
23
      holdings_remaining = holdings_array.count - 3
×
24

25
      holdings_array_first_three.each do |id, holding|
×
26
        block << holdings_block(document, id, holding)
×
27
      end
×
28
      block_extra << content_tag(:a, href: "/catalog/#{document['id']}") do
×
29
        content_tag(:"lux-card", class: 'show-more-holdings') do
×
30
          content_tag(:span, "See #{holdings_remaining} more locations", class: 'lux-text-style blue')
×
31
        end
×
32
      end
×
33

34
      block << block_extra
×
35

36
    end
×
37

38
    if block.empty?
×
39
      ''
×
40
    else
×
41
      content_tag(:div, block, class: "holdings-card")
×
42
    end
×
43
  end
×
44
  # rubocop:enable Metrics/MethodLength
45

46
  def online_content_block(document)
×
47
    controller.view_context.render(Holdings::OnlineHoldingsComponent.new(document:))
×
48
  end
×
49

50
  # rubocop:disable Metrics/MethodLength
51
  # Currently having trouble breaking up this method further due to the "check_availability" variable
52
  def holdings_block(document, id, holding)
×
53
    location = holding_location(holding)
×
54
    check_availability = render_availability?
×
55
    accumulator = ''.html_safe
×
56
    if holding['library'] == 'Online'
×
57
      rendered_online_holdings_block = controller.view_context.render(Holdings::OnlineHoldingsComponent.new(document:))
×
58
      return rendered_online_holdings_block if rendered_online_holdings_block.present?
×
59

60
      check_availability = render_availability?
×
61
      accumulator << empty_link_online_holding_block
×
62

63
    else
×
64
      accumulator << library_location_div(holding, document, id)
×
65
      if holding['dspace'] || holding['location_code'] == 'rare$num'
×
66
        check_availability = false
×
67
        accumulator << dspace_or_numismatics_holding_block
×
68
      elsif /^scsb.+/.match? location[:code]
×
69
        check_availability = false
×
70
        unless holding['items'].nil?
×
71
          @scsb_multiple = true unless holding['items'].one?
×
72
          accumulator << scsb_item_block(holding)
×
73
        end
×
74
      elsif holding['dspace'].nil?
×
75
        accumulator << dspace_not_defined_block(location)
×
76
      else
×
77
        check_availability = false
×
78
        accumulator << under_embargo_block
×
79
      end
×
80
    end
×
81
    holding_status_li(accumulator, document, check_availability, id, holding)
×
82
  end
×
83
  # rubocop:enable Metrics/MethodLength
84

85
  def empty_link_online_holding_block
×
86
    data = content_tag(
×
87
      :span,
×
88
      'Link Missing',
×
89
      class: 'lux-text-style gray strong'
×
90
    )
×
91
    data << content_tag(
×
92
      :div,
×
93
      'Online access is not currently available.',
×
94
      class: 'library-location'
×
95
    )
×
96
  end
×
97

98
  def onsite_access_span
×
99
    content_tag(
×
100
      :span,
×
101
      'On-site access',
×
102
      class: 'lux-text-style green strong'
×
103
    )
×
104
  end
×
105

106
  def available_access_span
×
107
    content_tag(
×
108
      :span,
×
109
      'Available',
×
110
      class: 'lux-text-style green strong'
×
111
    )
×
112
  end
×
113

114
  def dspace_or_numismatics_holding_block
×
115
    available_access_span
×
116
  end
×
117

118
  def scsb_item_block(holding)
×
119
    scsb_supervised_items?(holding) ? scsb_supervised_item : scsb_unsupervised_item(holding)
×
120
  end
×
121

122
  def scsb_supervised_item
×
123
    onsite_access_span
×
124
  end
×
125

126
  def scsb_unsupervised_item(holding)
×
127
    content_tag(
×
128
      :span,
×
129
      '',
×
130
      class: 'lux-text-style',
×
131
      data: {
×
132
        'scsb-availability': 'true',
×
133
        'scsb-barcode': holding['items'].first['barcode'].to_s
×
134
      }
×
135
    )
×
136
  end
×
137

138
  def dspace_not_defined_block(_location)
×
139
    content_tag(
×
140
      :span,
×
141
      'Loading...',
×
142
      class: 'lux-text-style gray strong'
×
143
    )
×
144
  end
×
145

146
  def under_embargo_block
×
147
    content_tag(
×
148
      :span,
×
149
      'Request',
×
150
      class: 'lux-text-style gray strong'
×
151
    )
×
152
  end
×
153

154
  def library_location_div(holding, document, id)
×
155
    content_tag(
×
156
      :div,
×
157
      ApplicationController.new.view_context.render(Holdings::SearchLocationComponent.new(holding)),
×
158
      class: 'library-location',
×
159
      data: {
×
160
        location: true,
×
161
        record_id: document['id'],
×
162
        holding_id: id
×
163
      }
×
164
    )
×
165
  end
×
166

167
  def holding_status_li(accumulator, document, check_availability, id, holding)
×
168
    location = holding_location(holding)
×
169
    content_tag(:a, href: "/catalog/#{document['id']}") do
×
170
      content_tag(
×
171
        :'lux-card',
×
172
        accumulator,
×
173
        class: 'holding-status',
×
174
        data: {
×
175
          availability_record: check_availability,
×
176
          record_id: document['id'],
×
177
          holding_id: id,
×
178
          temp_location_code: holding['temp_location_code'],
×
179
          aeon: aeon_location?(location),
×
180
          bound_with: document.bound_with?
×
181
        }.compact
×
182
      )
×
183
    end
×
184
  end
×
185

186
  private
×
187

188
    # rubocop:disable Naming/MethodParameterName
189
    # rubocop:disable Lint/DuplicateBranch
190
    # :reek:DuplicateMethodCall
191
    # :reek:TooManyStatements
192
    # :reek:UncommunicativeParameterName
193
    # :reek:UtilityFunction
194
    def sort_holdings(a, b)
×
195
      # First, check if one of the items is Firestone.  If so, it should come first
196
      if a.second['location_code'].starts_with?('firestone') && !b.second['location_code'].starts_with?('firestone')
×
197
        -1
×
198
      elsif b.second['location_code'].starts_with?('firestone') && !a.second['location_code'].starts_with?('firestone')
×
199
        1
×
200
      # Next, check if one of the items is Recap.  If so, it should come last
201
      elsif a.second['location_code'].starts_with?('recap') && !b.second['location_code'].starts_with?('recap')
×
202
        1
×
203
      elsif b.second['location_code'].starts_with?('recap') && !a.second['location_code'].starts_with?('recap')
×
204
        -1
×
205
      # Next, check if one of the items is Annex.  If so, it should come last (but still before recap, which was handled previously)
206
      elsif a.second['location_code'].starts_with?('annex') && !b.second['location_code'].starts_with?('annex')
×
207
        1
×
208
      elsif b.second['location_code'].starts_with?('annex') && !a.second['location_code'].starts_with?('annex')
×
209
        -1
×
210
      else
×
211
        a.second['location_code'] <=> b.second['location_code']
×
212
      end
×
213
    end
×
214
  # rubocop:enable Naming/MethodParameterName
215
  # rubocop:enable Lint/DuplicateBranch
216
end
×
217
# 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