blacklight 7.24.0 → 7.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +4 -4
  3. data/VERSION +1 -1
  4. data/app/assets/javascripts/blacklight/blacklight.js +2 -2
  5. data/app/components/blacklight/constraint_component.rb +1 -1
  6. data/app/components/blacklight/constraint_layout_component.rb +1 -1
  7. data/app/components/blacklight/constraints_component.rb +1 -1
  8. data/app/components/blacklight/document/action_component.rb +1 -1
  9. data/app/components/blacklight/document/actions_component.rb +1 -1
  10. data/app/components/blacklight/document/bookmark_component.rb +1 -1
  11. data/app/components/blacklight/document/citation_component.rb +2 -2
  12. data/app/components/blacklight/document/group_component.rb +3 -2
  13. data/app/components/blacklight/document/more_like_this_component.rb +1 -1
  14. data/app/components/blacklight/document/thumbnail_component.rb +1 -1
  15. data/app/components/blacklight/document_component.rb +1 -2
  16. data/app/components/blacklight/document_metadata_component.rb +1 -1
  17. data/app/components/blacklight/document_title_component.rb +1 -1
  18. data/app/components/blacklight/facet_field_checkboxes_component.rb +1 -1
  19. data/app/components/blacklight/facet_field_component.rb +1 -1
  20. data/app/components/blacklight/facet_field_filter_component.rb +1 -1
  21. data/app/components/blacklight/facet_field_inclusive_constraint_component.rb +1 -1
  22. data/app/components/blacklight/facet_field_list_component.rb +1 -1
  23. data/app/components/blacklight/facet_field_no_layout_component.rb +1 -1
  24. data/app/components/blacklight/facet_field_pagination_component.rb +1 -1
  25. data/app/components/blacklight/facet_item_component.rb +1 -1
  26. data/app/components/blacklight/facet_item_pivot_component.rb +1 -1
  27. data/app/components/blacklight/hidden_search_state_component.rb +2 -2
  28. data/app/components/blacklight/metadata_field_component.rb +1 -1
  29. data/app/components/blacklight/metadata_field_layout_component.rb +1 -1
  30. data/app/components/blacklight/response/facet_group_component.rb +1 -1
  31. data/app/components/blacklight/response/pagination_component.rb +1 -1
  32. data/app/components/blacklight/search_bar_component.html.erb +7 -7
  33. data/app/components/blacklight/search_bar_component.rb +18 -13
  34. data/app/components/blacklight/search_context_component.rb +1 -1
  35. data/app/components/blacklight/start_over_button_component.rb +1 -1
  36. data/app/helpers/blacklight/blacklight_helper_behavior.rb +3 -1
  37. data/app/helpers/blacklight/catalog_helper_behavior.rb +1 -1
  38. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +5 -7
  39. data/app/javascript/blacklight/modal.js +2 -2
  40. data/app/presenters/blacklight/search_bar_presenter.rb +2 -0
  41. data/app/services/blacklight/field_retriever.rb +1 -1
  42. data/app/views/catalog/_constraints.html.erb +2 -2
  43. data/app/views/catalog/_facet_group.html.erb +1 -1
  44. data/app/views/catalog/_search_form.html.erb +2 -2
  45. data/app/views/shared/_header_navbar.html.erb +5 -1
  46. data/lib/blacklight/component.rb +40 -0
  47. data/lib/blacklight/configuration/facet_field.rb +1 -1
  48. data/lib/blacklight/configuration/fields.rb +10 -11
  49. data/lib/blacklight/configuration/view_config.rb +6 -0
  50. data/lib/blacklight/configuration.rb +320 -179
  51. data/lib/blacklight/deprecations/search_state_normalization.rb +52 -0
  52. data/lib/blacklight/search_state/filter_field.rb +44 -16
  53. data/lib/blacklight/search_state.rb +55 -31
  54. data/lib/blacklight/solr/search_builder_behavior.rb +3 -1
  55. data/lib/blacklight.rb +1 -0
  56. data/package.json +1 -1
  57. data/spec/components/blacklight/constraints_component_spec.rb +14 -1
  58. data/spec/components/blacklight/facet_field_list_component_spec.rb +6 -1
  59. data/spec/components/blacklight/facet_item_pivot_component_spec.rb +7 -1
  60. data/spec/controllers/blacklight/base_spec.rb +4 -1
  61. data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +23 -6
  62. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +7 -0
  63. data/spec/lib/blacklight/component_spec.rb +43 -0
  64. data/spec/lib/blacklight/search_state/filter_field_spec.rb +12 -1
  65. data/spec/lib/blacklight/search_state_spec.rb +17 -3
  66. data/spec/models/blacklight/configuration_spec.rb +2 -2
  67. data/spec/models/blacklight/solr/search_builder_spec.rb +15 -0
  68. data/spec/presenters/blacklight/facet_field_presenter_spec.rb +10 -4
  69. data/spec/presenters/blacklight/facet_grouped_item_presenter_spec.rb +6 -1
  70. data/spec/presenters/blacklight/field_presenter_spec.rb +2 -0
  71. data/spec/views/catalog/index.json.jbuilder_spec.rb +1 -0
  72. metadata +7 -3
@@ -15,226 +15,356 @@ module Blacklight
15
15
  autoload :SearchField
16
16
  autoload :FacetField
17
17
  autoload :SortField
18
+ autoload :DisplayField
19
+ autoload :IndexField
20
+ autoload :ShowField
18
21
  end
19
22
 
20
- include Fields
21
-
22
23
  # Set up Blacklight::Configuration.default_values to contain the basic, required Blacklight fields
23
24
  class << self
24
- # rubocop:disable Metrics/MethodLength
25
+ def property(key, default: nil)
26
+ default_values[key] = default
27
+ end
28
+
25
29
  def default_values
26
- @default_values ||= begin
27
- {
28
- # === Search request configuration
29
- # HTTP method to use when making requests to solr; valid
30
- # values are :get and :post.
31
- http_method: :get,
32
- # The path to send requests to solr.
33
- solr_path: 'select',
34
- # Default values of parameters to send with every search request
35
- default_solr_params: {},
36
- ##
37
- # === Single document request configuration
38
- # The solr request handler to use when requesting only a single document
39
- document_solr_request_handler: nil,
40
- # The path to send single document requests to solr
41
- document_solr_path: 'get',
42
- document_unique_id_param: :ids,
43
- # Default values of parameters to send when requesting a single document
44
- default_document_solr_params: {},
45
- fetch_many_document_params: {},
46
- document_pagination_params: {},
47
- ##
48
- # == Response models
49
- ## Class for sending and receiving requests from a search index
50
- repository_class: nil,
51
- ## Class for converting Blacklight parameters to request parameters for the repository_class
52
- search_builder_class: nil,
53
- # model that maps index responses to the blacklight response model
54
- response_model: nil,
55
- # the model to use for each response document
56
- document_model: nil,
57
- # Class for paginating long lists of facet fields
58
- facet_paginator_class: nil,
59
- # repository connection configuration
60
- connection_config: nil,
61
- ##
62
- # == Blacklight view configuration
63
- navbar: OpenStructWithHashAccess.new(partials: {}),
64
- # General configuration for all views
65
- index: ViewConfig::Index.new(
66
- # document presenter class used by helpers and views
67
- document_presenter_class: nil,
68
- # component class used to render a document; defaults to Blacklight::DocumentComponent,
69
- # but can be set explicitly to avoid any legacy behavior
70
- document_component: nil,
71
- # solr field to use to render a document title
72
- title_field: nil,
73
- # solr field to use to render format-specific partials
74
- display_type_field: nil,
75
- # partials to render for each document(see #render_document_partials)
76
- partials: [:index_header, :thumbnail, :index],
77
- document_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
78
- collection_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
79
- # what field, if any, to use to render grouped results
80
- group: false,
81
- # additional response formats for search results
82
- respond_to: OpenStructWithHashAccess.new
83
- ),
84
- # Additional configuration when displaying a single document
85
- show: ViewConfig::Show.new(
86
- # document presenter class used by helpers and views
87
- document_presenter_class: nil,
88
- document_component: nil,
89
- display_type_field: nil,
90
- # Default route parameters for 'show' requests.
91
- # Set this to a hash with additional arguments to merge into the route,
92
- # or set `controller: :current` to route to the current controller.
93
- route: nil,
94
- # partials to render for each document(see #render_document_partials)
95
- partials: [:show_header, :show],
96
- document_actions: NestedOpenStructWithHashAccess.new(ToolConfig)
97
- ),
98
- action_mapping: NestedOpenStructWithHashAccess.new(
99
- ViewConfig,
100
- default: { top_level_config: :index },
101
- show: { top_level_config: :show },
102
- citation: { parent_config: :show }
103
- ),
104
- # SMS and Email configurations.
105
- sms: ViewConfig.new,
106
- email: ViewConfig.new,
107
- # Configurations for specific types of index views
108
- view: NestedOpenStructWithHashAccess.new(ViewConfig,
109
- list: {},
110
- atom: {
111
- if: false, # by default, atom should not show up as an alternative view
112
- partials: [:document],
113
- summary_partials: [:index]
114
- },
115
- rss: {
116
- if: false, # by default, rss should not show up as an alternative view
117
- partials: [:document]
118
- }),
119
- #
120
- # These fields are created and managed below by `define_field_access`
121
- # facet_fields
122
- # index_fields
123
- # show_fields
124
- # sort_fields
125
- # search_fields
126
- ##
127
- # === Blacklight behavior configuration
128
- # Maxiumum number of spelling suggestions to offer
129
- spell_max: 5,
130
- # Maximum number of results to show per page
131
- max_per_page: 100,
132
- # Options for the user for number of results to show per page
133
- per_page: [10, 20, 50, 100],
134
- default_per_page: nil,
135
- # how many searches to save in session history
136
- search_history_window: 100,
137
- default_facet_limit: 10,
138
- default_more_limit: 20,
139
- # proc for determining whether the session is a crawler/bot
140
- # ex.: crawler_detector: lambda { |req| req.env['HTTP_USER_AGENT'] =~ /bot/ }
141
- crawler_detector: nil,
142
- autocomplete_suggester: 'mySuggester',
143
- raw_endpoint: OpenStructWithHashAccess.new(enabled: false),
144
- track_search_session: true,
145
- advanced_search: OpenStruct.new(enabled: false),
146
- enable_search_bar_autofocus: false
147
- }
148
- end
149
- # rubocop:enable Metrics/MethodLength
30
+ @default_values ||= {}
150
31
  end
151
32
  end
33
+ # === Search request configuration
34
+
35
+ # @!attribute http_method
36
+ # @since v5.0.0
37
+ # @return [:get, :post] HTTP method used for search
38
+ property :http_method, default: :get
39
+ # @!attribute solr_path
40
+ # @return [String] The path to send requests to solr.
41
+ property :solr_path, default: 'select'
42
+ # @!attribute default_solr_params
43
+ # @return [Hash] Default values of parameters to send with every search request
44
+ property :default_solr_params, default: {}
45
+
46
+ # === Single document request configuration
47
+
48
+ # @!attribute document_solr_request_handler
49
+ # @return [String] The solr request handler to use when requesting only a single document
50
+ property :document_solr_request_handler, default: nil
51
+ # @!attribute document_solr_path
52
+ # @since v5.2.0
53
+ # @return [String] The url path (relative to the solr base url) to use when requesting only a single document
54
+ property :document_solr_path, default: 'get'
55
+ # @!attribute document_unique_id_param
56
+ # @since v5.2.0
57
+ # @return [Symbol] The solr query parameter used for sending the unique identifiers for one or more documents
58
+ property :document_unique_id_param, default: :ids
59
+ # @!attribute default_document_solr_params
60
+ # @return [Hash] Default values of parameters to send with every single-document request
61
+ property :default_document_solr_params, default: {}
62
+ # @!attribute fetch_many_document_params
63
+ # @since v7.0.0
64
+ # @return [Hash] Default values of parameters to send with every multi-document request
65
+ property :fetch_many_document_params, default: {}
66
+ # @!attribute document_pagination_params
67
+ # @return [Hash] Default values of parameters to send when getting the previous + next documents
68
+ property :document_pagination_params, default: {}
152
69
 
153
70
  ##
154
- # Create collections of solr field configurations.
155
- # This will create array-like accessor methods for
156
- # the given field, and an #add_x_field convenience
157
- # method for adding new fields to the configuration
158
-
159
- # facet fields
160
- define_field_access :facet_field
71
+ # == Response models
161
72
 
162
- # solr fields to display on search results
163
- define_field_access :index_field
164
-
165
- # solr fields to display when showing single documents
166
- define_field_access :show_field
167
-
168
- # solr "fields" to use for scoping user search queries to particular fields
169
- define_field_access :search_field
170
-
171
- # solr fields to use for sorting results
172
- define_field_access :sort_field
173
-
174
- # solr fields to use in text message
175
- define_field_access :sms_field
73
+ # @!attribute repository_class
74
+ # @return [Class] Class for sending and receiving requests from a search index
75
+ property :repository_class, default: nil
76
+ def repository_class
77
+ super || Blacklight::Solr::Repository
78
+ end
176
79
 
177
- # solr fields to use in email message
178
- define_field_access :email_field
80
+ # @!attribute search_builder_class
81
+ # @return [Class] class for converting Blacklight parameters to request parameters for the repository_class
82
+ property :search_builder_class, default: nil
83
+ def search_builder_class
84
+ super || locate_search_builder_class
85
+ end
179
86
 
180
- def initialize(hash = {})
181
- super(self.class.default_values.deep_dup.merge(hash))
182
- yield(self) if block_given?
87
+ def locate_search_builder_class
88
+ ::SearchBuilder
89
+ end
183
90
 
184
- @view_config ||= {}
91
+ # @!attribute response_model
92
+ # model that maps index responses to the blacklight response model
93
+ # @return [Class]
94
+ property :response_model, default: nil
95
+ def response_model
96
+ super || Blacklight::Solr::Response
185
97
  end
186
98
 
187
- def document_model
188
- super || ::SolrDocument
99
+ def response_model=(*args)
100
+ super
189
101
  end
190
102
 
103
+ # @!attribute document_factory
104
+ # the factory that builds document
105
+ # @return [Class]
106
+ property :document_factory, default: Blacklight::DocumentFactory
191
107
  # A class that builds documents
192
108
  def document_factory
193
109
  super || Blacklight::DocumentFactory
194
110
  end
111
+ # @!attribute document_model
112
+ # the model to use for each response document
113
+ # @return [Class]
114
+ property :document_model, default: nil
115
+ def document_model
116
+ super || ::SolrDocument
117
+ end
195
118
 
196
119
  # only here to support alias_method
197
120
  def document_model=(*args)
198
121
  super
199
122
  end
200
123
 
201
- def response_model
202
- super || Blacklight::Solr::Response
124
+ # @!attribute facet_paginator_class
125
+ # Class for paginating long lists of facet fields
126
+ # @return [Class]
127
+ property :facet_paginator_class, default: nil
128
+ def facet_paginator_class
129
+ super || Blacklight::Solr::FacetPaginator
203
130
  end
204
131
 
205
- def response_model=(*args)
206
- super
132
+ # @!attribute connection_config
133
+ # repository connection configuration
134
+ # @since v5.13.0
135
+ # @return [Class]
136
+ property :connection_config, default: nil
137
+ def connection_config
138
+ super || Blacklight.connection_config
207
139
  end
208
140
 
209
- def repository_class
210
- super || Blacklight::Solr::Repository
211
- end
141
+ ##
142
+ # == Blacklight view configuration
143
+
144
+ # @!attribute navbar
145
+ # @since v5.8.0
146
+ # @return [#partials]
147
+ property :navbar, default: OpenStructWithHashAccess.new(partials: {})
148
+
149
+ # @!attribute index
150
+ # General configuration for all views
151
+ # @return [Blacklight::Configuration::ViewConfig::Index]
152
+ property :index, default: ViewConfig::Index.new(
153
+ # document presenter class used by helpers and views
154
+ document_presenter_class: nil,
155
+ # component class used to render a document
156
+ document_component: nil,
157
+ # solr field to use to render a document title
158
+ title_field: nil,
159
+ # solr field to use to render format-specific partials
160
+ display_type_field: nil,
161
+ # partials to render for each document(see #render_document_partials)
162
+ partials: [:index_header, :thumbnail, :index],
163
+ document_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
164
+ collection_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
165
+ # what field, if any, to use to render grouped results
166
+ group: false,
167
+ # additional response formats for search results
168
+ respond_to: OpenStructWithHashAccess.new,
169
+ # component class used to render the facet grouping
170
+ facet_group_component: nil,
171
+ # component class used to render search constraints
172
+ constraints_component: nil,
173
+ # component class used to render the search bar
174
+ search_bar_component: nil
175
+ )
176
+
177
+ # @!attribute show
178
+ # Additional configuration when displaying a single document
179
+ # @return [Blacklight::Configuration::ViewConfig::Show]
180
+ property :show, default: ViewConfig::Show.new(
181
+ # document presenter class used by helpers and views
182
+ document_presenter_class: nil,
183
+ document_component: nil,
184
+ display_type_field: nil,
185
+ # Default route parameters for 'show' requests.
186
+ # Set this to a hash with additional arguments to merge into the route,
187
+ # or set `controller: :current` to route to the current controller.
188
+ route: nil,
189
+ # partials to render for each document(see #render_document_partials)
190
+ partials: [:show_header, :show],
191
+ document_actions: NestedOpenStructWithHashAccess.new(ToolConfig)
192
+ )
193
+
194
+ # @!attribute action_mapping
195
+ # @since v7.16.0
196
+ # @return [Hash{Symbol => Blacklight::Configuration::ViewConfig}]
197
+ property :action_mapping, default: NestedOpenStructWithHashAccess.new(
198
+ ViewConfig,
199
+ default: { top_level_config: :index },
200
+ show: { top_level_config: :show },
201
+ citation: { parent_config: :show }
202
+ )
203
+
204
+ # @!attribute sms
205
+ # @since v7.21.0
206
+ # @return [Blacklight::Configuration::ViewConfig]
207
+ property :sms, default: ViewConfig.new
212
208
 
213
- def repository
214
- repository_class.new(self)
215
- end
209
+ # @!attribute email
210
+ # @since v7.21.0
211
+ # @return [Blacklight::Configuration::ViewConfig]
212
+ property :email, default: ViewConfig.new
213
+
214
+ # @!attribute
215
+ # Configurations for specific types of index views
216
+ # @return [Hash{Symbol => Blacklight::Configuration::ViewConfig}]
217
+ property :view, default: NestedOpenStructWithHashAccess.new(ViewConfig,
218
+ list: {},
219
+ atom: {
220
+ if: false, # by default, atom should not show up as an alternative view
221
+ partials: [:document],
222
+ summary_partials: [:index]
223
+ },
224
+ rss: {
225
+ if: false, # by default, rss should not show up as an alternative view
226
+ partials: [:document]
227
+ })
216
228
 
217
- def connection_config
218
- super || Blacklight.connection_config
229
+ ##
230
+ # === Blacklight behavior configuration
231
+
232
+ # @!attribute spell_max
233
+ # Maxiumum number of spelling suggestions to offer
234
+ # @return [Integer]
235
+ property :spell_max, default: 5
236
+
237
+ # @!attribute max_per_page
238
+ # Maximum number of results to show per page
239
+ # @return [Integer]
240
+ property :max_per_page, default: 100
241
+ # @!attribute per_page
242
+ # Options for the user for number of results to show per page
243
+ # @return [Array<Integer>]
244
+ property :per_page, default: [10, 20, 50, 100]
245
+ # @!attribute default_per_page
246
+ # @return [Integer]
247
+ property :default_per_page, default: nil
248
+ # @return [Integer]
249
+ def default_per_page
250
+ super || per_page.first
219
251
  end
220
252
 
221
- def search_builder_class
222
- super || locate_search_builder_class
223
- end
253
+ # @!attribute search_history_window
254
+ # how many searches to save in session history
255
+ # @return [Integer]
256
+ property :search_history_window, default: 100
257
+ # @!attribute default_facet_limit
258
+ # @since v5.10.0
259
+ # @return [Integer]
260
+ property :default_facet_limit, default: 10
261
+ # @!attribute default_more_limit
262
+ # @since v7.0.0
263
+ # @return [Integer]
264
+ property :default_more_limit, default: 20
265
+
266
+ # @!attribute crawler_detector
267
+ # proc for determining whether the session is a crawler/bot
268
+ # ex.: crawler_detector: lambda { |req| req.env['HTTP_USER_AGENT'] =~ /bot/ }
269
+ # @since v7.0.0
270
+ # @return [<nil, Proc>]
271
+ property :crawler_detector, default: nil
272
+
273
+ # @!attribute autocomplete_suggester
274
+ # @since v7.0.0
275
+ # @return [String]
276
+ property :autocomplete_suggester, default: 'mySuggester'
277
+
278
+ # @!attribute raw_endpoint
279
+ # @since v7.0.0
280
+ # @return [#enabled]
281
+ property :raw_endpoint, default: OpenStructWithHashAccess.new(enabled: false)
282
+
283
+ # @!attribute track_search_session
284
+ # @since v7.1.0
285
+ # @return [Boolean]
286
+ property :track_search_session, default: true
287
+
288
+ # @!attribute advanced_search
289
+ # @since v7.15.0
290
+ # @return [#enabled]
291
+ property :advanced_search, default: OpenStruct.new(enabled: false)
292
+
293
+ # @!attribute enable_search_bar_autofocus
294
+ # @since v7.2.0
295
+ # @return [Boolean]
296
+ property :enable_search_bar_autofocus, default: false
297
+
298
+ BASIC_SEARCH_PARAMETERS = [:q, :qt, :page, :per_page, :search_field, :sort, :controller, :action, :'facet.page', :'facet.prefix', :'facet.sort', :rows, :format].freeze
299
+ ADVANCED_SEARCH_PARAMETERS = [:clause, :op].freeze
300
+ # List the request parameters that compose the SearchState.
301
+ # If you use a plugin that adds to the search state, then you can add the parameters
302
+ # by modifiying this field.
303
+ # @!attribute search_state_fields
304
+ # @since v8.0.0
305
+ # @return [Array<Symbol>]
306
+ property :search_state_fields, default: BASIC_SEARCH_PARAMETERS + ADVANCED_SEARCH_PARAMETERS
224
307
 
225
- def locate_search_builder_class
226
- ::SearchBuilder
227
- end
308
+ ##
309
+ # Create collections of solr field configurations.
310
+ # This will create array-like accessor methods for
311
+ # the given field, and an #add_x_field convenience
312
+ # method for adding new fields to the configuration
313
+ include Fields
228
314
 
229
- def facet_paginator_class
230
- super || Blacklight::Solr::FacetPaginator
315
+ # facet fields
316
+ # @!macro [attach] define_field_access
317
+ # @!attribute ${1}s
318
+ # @return [Hash{Symbol=>$2}]
319
+ # @!method add_${1}(config_key, hash_or_field_or_array)
320
+ # @param [Symbol] config_key
321
+ # @return [$2]
322
+ # @overload add_${1}(config_key, options)
323
+ # @param [Symbol] config_key
324
+ # @param [Hash] options
325
+ # @overload add_${1}(config_key, field)
326
+ # @param [Symbol] config_key
327
+ # @param [$2] field
328
+ # @overload add_${1}(config_key, array)
329
+ # @param [Symbol] config_key
330
+ # @param [Array<$2, Hash>] array
331
+ # @see #add_blacklight_field
332
+ define_field_access :facet_field, Blacklight::Configuration::FacetField
333
+
334
+ # solr fields to display on search results
335
+ define_field_access :index_field, Blacklight::Configuration::IndexField
336
+
337
+ # solr fields to display when showing single documents
338
+ define_field_access :show_field, Blacklight::Configuration::ShowField
339
+
340
+ # solr "fields" to use for scoping user search queries to particular fields
341
+ define_field_access :search_field, Blacklight::Configuration::SearchField
342
+
343
+ # solr fields to use for sorting results
344
+ define_field_access :sort_field, Blacklight::Configuration::SortField
345
+
346
+ # solr fields to use in text message
347
+ define_field_access :sms_field, Blacklight::Configuration::DisplayField
348
+
349
+ # solr fields to use in email message
350
+ define_field_access :email_field, Blacklight::Configuration::DisplayField
351
+
352
+ def initialize(hash = {})
353
+ super(self.class.default_values.deep_dup.merge(hash))
354
+ yield(self) if block_given?
355
+
356
+ @view_config ||= {}
231
357
  end
232
358
 
233
- def default_per_page
234
- super || per_page.first
359
+ # @return [Blacklight::Repository]
360
+ def repository
361
+ repository_class.new(self)
235
362
  end
236
363
 
237
364
  # DSL helper
365
+ # @yield [config]
366
+ # @yieldparam [Blacklight::Configuration]
367
+ # @return [Blacklight::Configuration]
238
368
  def configure
239
369
  yield self if block_given?
240
370
  self
@@ -242,6 +372,7 @@ module Blacklight
242
372
 
243
373
  # Returns default search field, used for simpler display in history, etc.
244
374
  # if not set, defaults to first defined search field
375
+ # @return [Blacklight::Configuration::SearchField]
245
376
  def default_search_field
246
377
  field = super || search_fields.values.find { |f| f.default == true }
247
378
  field || search_fields.values.first
@@ -249,11 +380,13 @@ module Blacklight
249
380
 
250
381
  # Returns default sort field, used for simpler display in history, etc.
251
382
  # if not set, defaults to first defined sort field
383
+ # @return [Blacklight::Configuration::SortField]
252
384
  def default_sort_field
253
385
  field = super || sort_fields.values.find { |f| f.default == true }
254
386
  field || sort_fields.values.first
255
387
  end
256
388
 
389
+ # @return [String]
257
390
  def default_title_field
258
391
  document_model.unique_key || 'id'
259
392
  end
@@ -272,7 +405,13 @@ module Blacklight
272
405
  # @param [String] group (nil) a group name of facet fields
273
406
  # @return [Array<String>] a list of the facet field names from the configuration
274
407
  def facet_field_names(group = nil)
275
- facet_fields.select { |_facet, opts| group == opts[:group] }.values.map(&:field)
408
+ facet_fields_in_group(group).map(&:field)
409
+ end
410
+
411
+ # @param [String] group (nil) a group name of facet fields
412
+ # @return [Array<Blacklight::Configuration::FacetField>] a list of facet fields
413
+ def facet_fields_in_group(group)
414
+ facet_fields.values.select { |opts| group == opts[:group] }
276
415
  end
277
416
 
278
417
  # @return [Array<String>] a list of facet groups
@@ -318,6 +457,7 @@ module Blacklight
318
457
  end
319
458
 
320
459
  # builds a copy for the provided controller class
460
+ # @param [Class] klass configuration host class
321
461
  def build(klass)
322
462
  deep_copy.tap do |conf|
323
463
  conf.klass = klass
@@ -439,6 +579,7 @@ module Blacklight
439
579
  fields.merge(show_fields)
440
580
  end
441
581
 
582
+ # @!visibility private
442
583
  def freeze
443
584
  each { |_k, v| v.is_a?(OpenStruct) && v.freeze }
444
585
  super
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ module Deprecations
5
+ module SearchStateNormalization
6
+ extend ActiveSupport::Concern
7
+
8
+ class_methods do
9
+ def facet_params_need_normalization(facet_params)
10
+ Deprecation.warn(self, 'Calling `facet_params_need_normalization` on the Blacklight::SearchState ' \
11
+ 'class is deprecated and will be removed in Blacklight 8. Delegate to #needs_normalization?(value_params) on the ' \
12
+ 'filter fields of the search state object.')
13
+
14
+ facet_params.is_a?(Hash) && facet_params.values.any? { |x| x.is_a?(Hash) }
15
+ end
16
+
17
+ def normalize_facet_params(facet_params)
18
+ Deprecation.warn(self, 'Calling `normalize_facet_params` on the Blacklight::SearchState ' \
19
+ 'class is deprecated and will be removed in Blacklight 8. Delegate to #normalize(value_params) on the ' \
20
+ 'filter fields of the search state object.')
21
+
22
+ facet_params.transform_values { |value| value.is_a?(Hash) ? value.values : value }
23
+ end
24
+
25
+ def normalize_params(untrusted_params = {})
26
+ Deprecation.warn(self, 'Calling `normalize_params` on the Blacklight::SearchState ' \
27
+ 'class is deprecated and will be removed in Blacklight 8. Call #normalize_params on the ' \
28
+ 'search state object.')
29
+ params = untrusted_params
30
+
31
+ if params.respond_to?(:to_unsafe_h)
32
+ # This is the typical (not-ActionView::TestCase) code path.
33
+ params = params.to_unsafe_h
34
+ # In Rails 5 to_unsafe_h returns a HashWithIndifferentAccess, in Rails 4 it returns Hash
35
+ params = params.with_indifferent_access if params.instance_of? Hash
36
+ elsif params.is_a? Hash
37
+ # This is an ActionView::TestCase workaround for Rails 4.2.
38
+ params = params.dup.with_indifferent_access
39
+ else
40
+ params = params.dup.to_h.with_indifferent_access
41
+ end
42
+
43
+ # Normalize facet parameters mangled by facebook
44
+ params[:f] = normalize_facet_params(params[:f]) if facet_params_need_normalization(params[:f])
45
+ params[:f_inclusive] = normalize_facet_params(params[:f_inclusive]) if facet_params_need_normalization(params[:f_inclusive])
46
+
47
+ params
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end