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

pulibrary / orangelight / 4c391e0e-519a-40cb-8ad3-354445f4ce03

12 Aug 2025 08:47PM UTC coverage: 85.348% (-10.0%) from 95.335%
4c391e0e-519a-40cb-8ad3-354445f4ce03

push

circleci

web-flow
[#5143] Use access restriction note as Aeon ItemInfo1 if available (#5173)

With this commit, if a user visits a record with an access
restrictions note and presses the Reading Room Request
button, they will get to an Aeon form with the 'Restrictions'
field pre-filled with the restriction note.

If the record does not have an access restrictions note,
the field will be pre-filled with 'Reading Room Access Only',
as it has been previously.

Closes #5143

5493 of 6436 relevant lines covered (85.35%)

251.82 hits per line

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

91.04
/app/services/online_holdings_markup_builder.rb
1
# frozen_string_literal: false
2

3
class OnlineHoldingsMarkupBuilder < HoldingRequestsBuilder
1✔
4
  # Generate a block of markup for an online holding
5
  # @param bib_id [String] the ID for the SolrDocument
6
  # @param holding_id [String] the ID for the holding
7
  # @return [String] the markup
8
  def self.online_link(bib_id, holding_id)
1✔
9
    children = content_tag(
×
10
      :span, 'Link Missing',
11
      class: 'lux-text-style gray strong'
12
    )
13
    # AJAX requests are made using availability.js here
14
    content_tag(:div, children.html_safe,
×
15
                class: 'holding-block',
16
                data: {
17
                  availability_record: true,
18
                  record_id: bib_id,
19
                  holding_id:
20
                })
21
  end
22

23
  # Generate the link for electronic access information within a record
24
  # @param url [String] the URL to the service endpoint
25
  # @param text [String] the label for the link
26
  def self.electronic_access_link(url, texts)
1✔
27
    markup = if /Open access/.match? texts.first
14✔
28
               link_to(texts.first, url.to_s, target: '_blank', rel: 'noopener', class: 'electronic-access-link')
×
29
             elsif %r{(\/catalog\/.+?#view)} =~ url.to_s
14✔
30
               if texts.first == "arks.princeton.edu"
5✔
31
                 link_to('Digital content', ::Regexp.last_match(0), class: 'electronic-access-link')
×
32
               else
33
                 link_to(texts.first, ::Regexp.last_match(0), class: 'electronic-access-link')
5✔
34
               end
35
             else
36
               link_text = new_tab_icon(texts.first)
9✔
37
               link_to(link_text, EzProxyService.ez_proxy_url(url), target: '_blank', rel: 'noopener', class: 'electronic-access-link')
9✔
38
             end
39
    markup
14✔
40
  end
41

42
  # Method for cleaning URLs
43
  # @param url [String] the URL for an online holding
44
  # @return [String] the cleaned URL
45
  def self.clean_url(url)
1✔
46
    if /go\.galegroup\.com.+?%257C/.match? url
14✔
47
      URI.decode_www_form_component(url)
×
48
    else
49
      url
14✔
50
    end
51
  end
52

53
  # Generate the markup for the electronic access block
54
  # First argument of link_to is optional display text. If null, the second argument
55
  # (URL) is the display text for the link.
56
  # Proxy Base is added to force remote access when appropriate
57
  # @param adapter [HoldingRequestsAdapter] the adapter for Solr and Bibdata
58
  # @return [String] the markup
59
  def self.urlify(adapter)
1✔
60
    markup = ''
29✔
61

62
    electronic_access = adapter.doc_electronic_access
29✔
63
    electronic_access.each do |url, electronic_texts|
29✔
64
      texts = electronic_texts.flatten
14✔
65
      url = clean_url(url)
14✔
66

67
      link = electronic_access_link(url, texts)
14✔
68
      link = "#{texts[1]}: " + link if texts[1]
14✔
69
      link = "<li>#{link}</li>" if electronic_access.many?
14✔
70
      markup << content_tag(:li, link.html_safe, class: 'electronic-access')
14✔
71
    end
72

73
    return content_tag(:ul, markup.html_safe) if electronic_access.many?
29✔
74
    markup
23✔
75
  end
76

77
  # Returns electronic portforlio link markup.
78
  # Replaces Umlaut AJAX data when using Alma.
79
  # @param adapter [HoldingRequestsAdapter] the adapter for Solr and Bibdata
80
  # @return [String] the markup
81
  def self.electronic_portfolio_markup(adapter)
1✔
82
    markup = ''
29✔
83

84
    portfolios = adapter.electronic_portfolios + adapter.sibling_electronic_portfolios
29✔
85
    return '' if portfolios.present? && portfolios[0].key?('thesis')
29✔
86
    portfolios.each do |portfolio|
29✔
87
      start_date = portfolio['start']
28✔
88
      end_date = portfolio['end']
28✔
89
      date_range = "#{start_date} - #{end_date}: " if start_date && end_date
28✔
90
      label = new_tab_icon("#{date_range}#{portfolio['title']}")
28✔
91
      link = link_to(label, portfolio["url"], target: '_blank', rel: 'noopener', class: 'electronic-access-link')
28✔
92
      link += "<br/><lux-show-more v-bind:character-limit=150 show-label='See more' hide-label='See less'>#{portfolio['desc']}</lux-show-more>".html_safe
28✔
93

94
      link = "#{link} (#{portfolio['notes'].join(', ')})" if portfolio['notes']&.any?
28✔
95
      markup << content_tag(:li, link.html_safe, class: 'electronic-access lux')
28✔
96
    end
97

98
    markup
29✔
99
  end
100

101
  def self.new_tab_icon(text)
1✔
102
    text = text.html_safe
37✔
103
    text + content_tag(:i, "", class: "fa fa-external-link new-tab-icon-padding", "aria-label": "opens in new tab", role: "img")
37✔
104
  end
105

106
  # Constructor
107
  # @param adapter [HoldingRequestsAdapter] adapter for the SolrDocument and Bibdata API
108
  def initialize(adapter)
1✔
109
    @adapter = adapter
29✔
110
  end
111

112
  # Builds the markup for online and physical holdings for a given record
113
  # @return [Array<String>] the markup for the online and physical holdings
114
  def build
1✔
115
    online_holdings_block
29✔
116
  end
117

118
  private
1✔
119

120
    # Generate the markup for the online holdings
121
    # @return [String] the markup
122
    def online_holdings
1✔
123
      markup = ''
29✔
124

125
      electronic_access_links = self.class.urlify(@adapter)
29✔
126
      markup << electronic_access_links
29✔
127
      elf_holdings = @adapter.doc_holdings_elf
29✔
128

129
      if electronic_access_links.empty?
29✔
130
        elf_holdings.each_key do |holding_id|
21✔
131
          markup << self.class.online_link(@adapter.doc_id, holding_id)
×
132
        end
133
      end
134

135
      # For Alma records, add links from the electronic portfolio field
136
      markup << self.class.electronic_portfolio_markup(@adapter)
29✔
137

138
      markup
29✔
139
    end
140

141
    # Generate the markup for the online holdings block
142
    # @return [String] the markup
143
    def online_holdings_block
1✔
144
      markup = ''
29✔
145
      children = online_holdings
29✔
146
      markup = self.class.content_tag(:ul, children.html_safe) unless children.empty?
29✔
147
      markup
29✔
148
    end
149
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