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

pulibrary / orangelight / 0e37073d-109c-440c-949f-49d2aa86311b

18 Aug 2025 09:05PM UTC coverage: 0.482% (-94.9%) from 95.343%
0e37073d-109c-440c-949f-49d2aa86311b

push

circleci

web-flow
Replace per_page_options_for_select with custom component to avoid deprecation issue (#5186)

* Start creating new component to address deprecaton warning

* Replace per_page_options_for_select with custom component to avoid deprecation issue

Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>

---------

Co-authored-by: Ryan Jensen <rj1044@princeton.edu>
Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>

0 of 33 new or added lines in 1 file covered. (0.0%)

9374 existing lines in 213 files now uncovered.

47 of 9753 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/controllers/orangelight/browsables_controller.rb
1
# frozen_string_literal: true
2

UNCOV
3
class Orangelight::BrowsablesController < ApplicationController
×
4
  # GET /orangelight/names
5
  # GET /orangelight/names.json
6

UNCOV
7
  def index
×
8
    # if rpp isn't specified default is 50
9
    # if rpp has values other than 10, 25, 50, 100 then set it to 50
10
    # previous/next page links need to pass
11
    # manually set rpp
12

UNCOV
13
    assign_values
×
14

15
    # makes sure valid page is displayed
UNCOV
16
    if !((@last_id - @rpp + 1)..@last_id).cover?(@start) && @is_last
×
UNCOV
17
      @start = @last_id - @rpp + 1
×
UNCOV
18
      @start = 1 if @start < 1 # catch for start ids higher than last id
×
UNCOV
19
    end
×
20

UNCOV
21
    assign_pagination_values
×
22

UNCOV
23
    @facet = facet
×
UNCOV
24
    @list_name = list_name
×
25

UNCOV
26
    respond_to do |format|
×
UNCOV
27
      format.html # index.html.erb
×
UNCOV
28
      format.json { render json: @orangelight_browsables }
×
UNCOV
29
    end
×
UNCOV
30
  end
×
31

UNCOV
32
  private
×
33

UNCOV
34
    def assign_values
×
UNCOV
35
      @model = model_table_name
×
UNCOV
36
      @rpp = rpp
×
UNCOV
37
      @page_link = page_link
×
38

39
      # @start gets the id of the first entry to display on page
40
      # specific ids are given based on search results
UNCOV
41
      @start = first_model_id
×
42

UNCOV
43
      populate_search_results
×
44

45
      # gets last page of table's results
UNCOV
46
      @last_id = last_model_id
×
47

48
      # makes sure no next page link is shown for last page
UNCOV
49
      @is_last = (@last_id - @rpp + 1) <= @start
×
UNCOV
50
    end
×
51

UNCOV
52
    def rpp
×
UNCOV
53
      if rpp_param.nil?
×
UNCOV
54
        50
×
UNCOV
55
      else
×
UNCOV
56
        validate_rpp(requested_rpp)
×
UNCOV
57
      end
×
UNCOV
58
    end
×
59

UNCOV
60
    def page_link
×
UNCOV
61
      if rpp_param.nil?
×
UNCOV
62
        '?'
×
UNCOV
63
      else
×
UNCOV
64
        size = validate_rpp(requested_rpp)
×
UNCOV
65
        "?rpp=#{size}&"
×
UNCOV
66
      end
×
UNCOV
67
    end
×
68

UNCOV
69
    def validate_rpp(size)
×
UNCOV
70
      rpp_range = [10, 25, 50, 100]
×
UNCOV
71
      if rpp_range.include? size
×
UNCOV
72
        size
×
UNCOV
73
      else
×
UNCOV
74
        50
×
UNCOV
75
      end
×
UNCOV
76
    end
×
77

UNCOV
78
    def populate_search_results
×
UNCOV
79
      return if query_param.nil?
×
80
      # 'subject_facet' is the default vocabulary type if there is no vocabulary type specified
UNCOV
81
      search_result = if vocabulary_search_on_facet == 'subject_facet'
×
UNCOV
82
                        model_param.where('sort <= ?', search_term).order('sort').last
×
UNCOV
83
                      else
×
UNCOV
84
                        model_param.where(sort: search_term).where(vocabulary: vocabulary_search_on_facet).first
×
UNCOV
85
                      end
×
86

UNCOV
87
      return if search_result.nil?
×
88

UNCOV
89
      populate_search_params(search_result)
×
UNCOV
90
    end
×
91

UNCOV
92
    def populate_search_params(search_result)
×
UNCOV
93
      @search_result = search_result.label
×
UNCOV
94
      @search_term = search_term
×
UNCOV
95
      @exact_match = search_term == search_result.sort
×
UNCOV
96
      @match = search_result.id
×
UNCOV
97
      @match_vocabulary = search_result.vocabulary if @model == 'subjects'
×
UNCOV
98
      @start = search_result.id - 1
×
UNCOV
99
      @start -= 1 if @exact_match
×
UNCOV
100
      @start = 1 if @start < 1
×
UNCOV
101
      @query = query_param
×
UNCOV
102
    end
×
103

UNCOV
104
    def assign_pagination_values
×
UNCOV
105
      @is_first = @start == 1
×
106

UNCOV
107
      @page_last = if (@start + @rpp - 1) > @last_id
×
UNCOV
108
                     @last_id
×
UNCOV
109
                   else
×
UNCOV
110
                     @start + @rpp - 1
×
UNCOV
111
                   end
×
112

UNCOV
113
      @prev = @start - @rpp
×
UNCOV
114
      @prev = 1 if @prev < 1
×
UNCOV
115
      @next = @start + @rpp
×
116

UNCOV
117
      @orangelight_browsables = model_param.where(id: @start..@page_last)
×
UNCOV
118
    end
×
119

UNCOV
120
    def facet
×
UNCOV
121
      if browsing_names?
×
UNCOV
122
        'author_s'
×
UNCOV
123
      elsif browsing_subjects?
×
UNCOV
124
        vocab_param
×
UNCOV
125
      elsif browsing_titles?
×
UNCOV
126
        'name_title_browse_s'
×
UNCOV
127
      end
×
UNCOV
128
    end
×
129

130
    # Retrieve the Model mapped to the request parameter
131
    # @return [Class]
UNCOV
132
    def model_param
×
UNCOV
133
      params[:model]
×
UNCOV
134
    end
×
135

UNCOV
136
    def vocab_param
×
UNCOV
137
      params[:vocab]
×
UNCOV
138
    end
×
139

UNCOV
140
    def vocabulary_search_on_facet
×
141
      # TODO: move vocab_types to a config file
142
      # the hash also exists in vocab_type method
UNCOV
143
      vocab_types = {
×
UNCOV
144
        'Library of Congress subject heading' => 'lc_subject_facet',
×
UNCOV
145
        'Library of Congress genre/form terms for library and archival materials' => 'lcgft_genre_facet',
×
UNCOV
146
        'Art & architecture thesaurus' => 'aat_genre_facet',
×
UNCOV
147
        'Homosaurus terms' => 'homoit_subject_facet',
×
UNCOV
148
        'Homosaurus genres' => 'homoit_genre_facet',
×
UNCOV
149
        'Rare books genre term' => 'rbgenr_genre_facet',
×
UNCOV
150
        'Chinese traditional subjects' => 'siku_subject_facet',
×
UNCOV
151
        'Locally assigned term' => 'local_subject_facet'
×
UNCOV
152
      }
×
UNCOV
153
      vocab_types_invert = vocab_types.invert
×
UNCOV
154
      vocab_types_invert.fetch(vocab_param, 'subject_facet')
×
UNCOV
155
    end
×
156

157
    # Generates the name of the table mapped to the model in the request
158
    # @return [String]
UNCOV
159
    def model_table_name
×
UNCOV
160
      model_name = model_param.name
×
UNCOV
161
      model_class = model_name.demodulize
×
UNCOV
162
      model_class.tableize
×
UNCOV
163
    end
×
164

165
    # Determines whether or not the client is requesting to browse call numbers
166
    # @return [Boolean]
UNCOV
167
    def browsing_call_numbers?
×
UNCOV
168
      model_table_name == 'call_numbers'
×
UNCOV
169
    end
×
170

171
    # Determines whether or not the client is requesting to browse names
172
    # @return [Boolean]
UNCOV
173
    def browsing_names?
×
UNCOV
174
      model_table_name == 'names'
×
UNCOV
175
    end
×
176

177
    # Determines whether or not the client is requesting to browse subjects
178
    # @return [Boolean]
UNCOV
179
    def browsing_subjects?
×
UNCOV
180
      model_table_name == 'subjects'
×
UNCOV
181
    end
×
182

183
    # Determines whether or not the client is requesting to browse titles
184
    # @return [Boolean]
UNCOV
185
    def browsing_titles?
×
UNCOV
186
      model_table_name == 'name_titles'
×
UNCOV
187
    end
×
188

189
    # Generates the name of the list (based upon the model for the request)
190
    # @return [String]
UNCOV
191
    def list_name
×
UNCOV
192
      value = model_table_name.humanize
×
UNCOV
193
      return 'author-title headings' if value == 'Name titles'
×
UNCOV
194
      value
×
UNCOV
195
    end
×
196

197
    # Retrieves the ID requested by the client
198
    # @return [String]
UNCOV
199
    def id_param
×
200
      params[:id]
×
UNCOV
201
    end
×
202

203
    # Retrieves the query transmitted by the client
204
    # @return [String]
UNCOV
205
    def query_param
×
UNCOV
206
      params[:q]
×
UNCOV
207
    end
×
208

209
    # Retrieves the ID for the first object requested by the client
210
    # @return [String]
UNCOV
211
    def start_param
×
UNCOV
212
      params[:start]
×
UNCOV
213
    end
×
214

215
    # Retrieves the ID of the first object for this request
216
    # @return [Integer]
UNCOV
217
    def first_model_id
×
UNCOV
218
      return 1 if start_param.nil?
×
UNCOV
219
      start_param.to_i
×
UNCOV
220
    end
×
221

222
    # Normalizes the query transmitted by the client
223
    # @return [String]
UNCOV
224
    def search_term
×
UNCOV
225
      return StringFunctions.cn_normalize(query_param) if browsing_call_numbers?
×
226

UNCOV
227
      query_param.normalize_em
×
UNCOV
228
    end
×
229

230
    # Retrieves the ID of the last object for this request
231
    # @return [Integer]
UNCOV
232
    def last_model_id
×
UNCOV
233
      return model_param.last.id if model_param.last
×
234
      1
×
UNCOV
235
    end
×
236

237
    # Retrieves the requested rows per page (rpp) from the client
238
    # @return [String]
UNCOV
239
    def rpp_param
×
UNCOV
240
      params[:rpp]
×
UNCOV
241
    end
×
242

243
    # Generates the requested rows per page as an Integer
244
    # @return [Integer]
UNCOV
245
    def requested_rpp
×
UNCOV
246
      rpp_param.to_i
×
UNCOV
247
    end
×
248

249
    # Use callbacks to share common setup or constraints between actions.
UNCOV
250
    def set_orangelight_browsable
×
251
      @orangelight_browsable = model_param.find(id_param) if model_param
×
UNCOV
252
    end
×
253

254
    # Never trust parameters from the scary internet; run the params we receive through an allowlist
UNCOV
255
    def orangelight_browsable_params
×
256
      params.require(:orangelight_browsable).permit(:model, :id)
×
UNCOV
257
    end
×
UNCOV
258
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