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

pulibrary / orangelight / a9945904-c4b1-47a3-9b94-042f58dd8a8e

26 Nov 2024 06:06PM UTC coverage: 96.419% (-0.3%) from 96.676%
a9945904-c4b1-47a3-9b94-042f58dd8a8e

push

circleci

web-flow
Merge pull request #4446 from pulibrary/4081-bootstrap5

[#4081] Update to bootstrap 5

4 of 5 new or added lines in 4 files covered. (80.0%)

16 existing lines in 4 files now uncovered.

6005 of 6228 relevant lines covered (96.42%)

1553.05 hits per line

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

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

3
class OnlineHoldingsMarkupBuilder < HoldingRequestsBuilder
3✔
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)
3✔
UNCOV
9
    children = content_tag(
×
10
      :span, 'Link Missing',
11
      class: 'availability-icon badge bg-secondary'
12
    )
13
    # AJAX requests are made using availability.js here
UNCOV
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)
3✔
27
    markup = if /Open access/.match? texts.first
54✔
28
               link_to(texts.first, url.to_s, target: '_blank', rel: 'noopener')
2✔
29
             elsif %r{(\/catalog\/.+?#view)} =~ url.to_s
52✔
30
               if texts.first == "arks.princeton.edu"
13✔
31
                 link_to('Digital content', ::Regexp.last_match(0))
1✔
32
               else
33
                 link_to(texts.first, ::Regexp.last_match(0))
12✔
34
               end
35
             else
36
               link_text = new_tab_icon(texts.first)
39✔
37
               link_to(link_text, EzProxyService.ez_proxy_url(url), target: '_blank', rel: 'noopener')
39✔
38
             end
39
    markup
54✔
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)
3✔
46
    if /go\.galegroup\.com.+?%257C/.match? url
50✔
47
      URI.decode_www_form_component(url)
1✔
48
    else
49
      url
49✔
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)
3✔
60
    markup = ''
106✔
61

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

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

73
    return content_tag(:ul, markup.html_safe) if electronic_access.count > 1
106✔
74
    markup
95✔
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)
3✔
82
    markup = ''
102✔
83

84
    portfolios = adapter.electronic_portfolios + adapter.sibling_electronic_portfolios
102✔
85
    return '' if portfolios.present? && portfolios[0].key?('thesis')
102✔
86
    portfolios.each do |portfolio|
99✔
87
      start_date = portfolio['start']
50✔
88
      end_date = portfolio['end']
50✔
89
      date_range = "#{start_date} - #{end_date}: " if start_date && end_date
50✔
90
      label = new_tab_icon("#{date_range}#{portfolio['title']}")
50✔
91
      link = link_to(label, portfolio["url"], target: '_blank', rel: 'noopener')
50✔
92
      link += " #{portfolio['desc']}"
50✔
93
      link = "#{link} (#{portfolio['notes'].join(', ')})" if portfolio['notes']&.any?
50✔
94
      markup << content_tag(:li, link.html_safe, class: 'electronic-access')
50✔
95
    end
96

97
    markup
99✔
98
  end
99

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

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

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

117
  private
3✔
118

119
    # Generate the markup for the online holdings
120
    # @return [String] the markup
121
    def online_holdings
3✔
122
      markup = ''
101✔
123

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

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

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

137
      markup
101✔
138
    end
139

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