blacklight 7.6.0 → 7.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.docker/app/Dockerfile +26 -0
- data/.docker/app/entrypoint.sh +6 -0
- data/.env +5 -0
- data/.gitignore +1 -1
- data/.rubocop_todo.yml +13 -13
- data/.travis.yml +15 -23
- data/Gemfile +4 -1
- data/README.md +4 -0
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_facets.scss +20 -4
- data/app/assets/stylesheets/blacklight/_pagination.scss +4 -0
- data/app/components/blacklight/constraint_layout_component.html.erb +23 -0
- data/app/components/blacklight/constraint_layout_component.rb +16 -0
- data/app/components/blacklight/facet_field_component.html.erb +25 -0
- data/app/components/blacklight/facet_field_component.rb +11 -0
- data/app/components/blacklight/facet_field_list_component.html.erb +18 -0
- data/app/components/blacklight/facet_field_list_component.rb +22 -0
- data/app/components/blacklight/facet_field_no_layout_component.rb +13 -0
- data/app/components/blacklight/facet_item_component.rb +120 -0
- data/app/components/blacklight/facet_item_pivot_component.rb +84 -0
- data/app/helpers/blacklight/catalog_helper_behavior.rb +2 -2
- data/app/helpers/blacklight/configuration_helper_behavior.rb +3 -2
- data/app/helpers/blacklight/facets_helper_behavior.rb +95 -49
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +64 -33
- data/app/javascript/blacklight/modal.js +1 -1
- data/app/models/blacklight/icon.rb +12 -10
- data/app/models/concerns/blacklight/document.rb +0 -10
- data/app/models/concerns/blacklight/document/extensions.rb +3 -0
- data/app/models/concerns/blacklight/document/semantic_fields.rb +0 -4
- data/app/presenters/blacklight/document_presenter.rb +2 -1
- data/app/presenters/blacklight/facet_field_presenter.rb +57 -0
- data/app/presenters/blacklight/facet_item_presenter.rb +81 -0
- data/app/views/catalog/_citation.html.erb +1 -1
- data/app/views/catalog/_constraints.html.erb +2 -2
- data/app/views/catalog/_constraints_element.html.erb +5 -24
- data/app/views/catalog/_email_form.html.erb +1 -1
- data/app/views/catalog/_facet_layout.html.erb +8 -17
- data/app/views/catalog/_facet_limit.html.erb +3 -12
- data/app/views/catalog/_facet_pagination.html.erb +2 -2
- data/app/views/catalog/_facet_pivot.html.erb +3 -18
- data/app/views/catalog/_previous_next_doc.html.erb +5 -5
- data/app/views/catalog/_search_form.html.erb +1 -1
- data/app/views/catalog/_sms_form.html.erb +1 -1
- data/app/views/layouts/blacklight/base.html.erb +1 -1
- data/blacklight.gemspec +1 -0
- data/config/locales/blacklight.ar.yml +32 -25
- data/config/locales/blacklight.de.yml +3 -0
- data/config/locales/blacklight.en.yml +3 -0
- data/config/locales/blacklight.es.yml +3 -0
- data/config/locales/blacklight.fr.yml +3 -0
- data/config/locales/blacklight.hu.yml +3 -0
- data/config/locales/blacklight.it.yml +3 -0
- data/config/locales/blacklight.nl.yml +3 -0
- data/config/locales/blacklight.pt-BR.yml +3 -0
- data/config/locales/blacklight.sq.yml +3 -0
- data/config/locales/blacklight.zh.yml +3 -0
- data/docker-compose.yml +35 -0
- data/lib/blacklight/configuration.rb +35 -8
- data/lib/blacklight/configuration/facet_field.rb +1 -0
- data/lib/blacklight/engine.rb +2 -6
- data/lib/blacklight/search_state.rb +52 -0
- data/lib/blacklight/solr/response/facets.rb +2 -0
- data/lib/generators/blacklight/assets_generator.rb +10 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +1 -1
- data/package.json +2 -2
- data/spec/{views/catalog/_constraints_element.html.erb_spec.rb → components/blacklight/constraint_layout_component_spec.rb} +22 -12
- data/spec/components/blacklight/facet_field_list_component_spec.rb +108 -0
- data/spec/components/blacklight/facet_item_component_spec.rb +50 -0
- data/spec/components/blacklight/facet_item_pivot_component_spec.rb +66 -0
- data/spec/features/facets_spec.rb +21 -1
- data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +3 -0
- data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +57 -12
- data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +4 -23
- data/spec/lib/blacklight/search_state_spec.rb +50 -0
- data/spec/models/blacklight/configuration_spec.rb +4 -0
- data/spec/models/blacklight/icon_spec.rb +11 -10
- data/spec/models/blacklight/solr/response/facets_spec.rb +30 -1
- data/spec/presenters/blacklight/document_presenter_spec.rb +10 -1
- data/spec/presenters/blacklight/facet_field_presenter_spec.rb +109 -0
- data/spec/presenters/blacklight/facet_item_presenter_spec.rb +92 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/presenter_test_helpers.rb +11 -0
- data/spec/views/catalog/_facet_group.html.erb_spec.rb +1 -0
- data/spec/views/catalog/_previous_next_doc.html.erb_spec.rb +18 -0
- data/tasks/blacklight.rake +30 -23
- metadata +48 -8
- data/Vagrantfile +0 -79
- data/package-lock.json +0 -2793
- data/provision.sh +0 -30
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Blacklight
|
4
|
+
# Render facet items and any subtree
|
5
|
+
class FacetItemPivotComponent < ::ViewComponent::Base
|
6
|
+
# Somewhat arbitrary number; the only important thing is that
|
7
|
+
# it is bigger than the number of leaf nodes in any collapsing
|
8
|
+
# pivot facet on the page.
|
9
|
+
ID_COUNTER_MAX = 2**20 - 1
|
10
|
+
|
11
|
+
# Mint a (sufficiently) unique identifier, so we can associate
|
12
|
+
# the expand/collapse control with labels
|
13
|
+
def self.mint_id
|
14
|
+
@id_counter = ((@id_counter || 0) + 1) % ID_COUNTER_MAX
|
15
|
+
|
16
|
+
# We convert the ID to hex for markup compactness
|
17
|
+
@id_counter.to_s(16)
|
18
|
+
end
|
19
|
+
|
20
|
+
with_collection_parameter :facet_item
|
21
|
+
|
22
|
+
def initialize(facet_item:, wrapping_element: 'li', suppress_link: false, collapsing: nil)
|
23
|
+
@facet_item = facet_item
|
24
|
+
@wrapping_element = wrapping_element
|
25
|
+
@suppress_link = suppress_link
|
26
|
+
@collapsing = collapsing.nil? ? facet_item.facet_config.collapsing : collapsing
|
27
|
+
@icons = { show: '⊞', hide: '⊟' }.merge(facet_item.facet_config.icons || {})
|
28
|
+
end
|
29
|
+
|
30
|
+
def call
|
31
|
+
facet = Blacklight::FacetItemComponent.new(facet_item: @facet_item, wrapping_element: nil, suppress_link: @suppress_link)
|
32
|
+
|
33
|
+
id = "h-#{self.class.mint_id}" if @collapsing && has_items?
|
34
|
+
|
35
|
+
content_tag @wrapping_element, role: 'treeitem' do
|
36
|
+
concat facet_toggle_button(id) if has_items? && @collapsing
|
37
|
+
concat content_tag('span', render_component(facet), class: "facet-values #{'facet-leaf-node' if has_items? && @collapsing}", id: id && "#{id}_label")
|
38
|
+
|
39
|
+
if has_items?
|
40
|
+
concat(content_tag('ul', class: "pivot-facet list-unstyled #{'collapse' if @collapsing}", id: id, role: 'group') do
|
41
|
+
render_component(
|
42
|
+
self.class.with_collection(
|
43
|
+
@facet_item.items.map { |i| facet_item_presenter(i) }
|
44
|
+
)
|
45
|
+
)
|
46
|
+
end)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def has_items?
|
54
|
+
@facet_item.items.present?
|
55
|
+
end
|
56
|
+
|
57
|
+
def facet_toggle_button(id)
|
58
|
+
content_tag 'button', class: 'btn facet-toggle-handle collapsed',
|
59
|
+
data: { toggle: 'collapse', target: "##{id}" },
|
60
|
+
aria: { expanded: false, controls: id, describedby: "#{id}_label" } do
|
61
|
+
concat toggle_icon(:show)
|
62
|
+
concat toggle_icon(:hide)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def toggle_icon(type)
|
67
|
+
content_tag 'span', class: type do
|
68
|
+
concat @icons[type]
|
69
|
+
concat content_tag('span', t(type, scope: 'blacklight.search.facets.pivot'), class: 'sr-only')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# This is a little convoluted in Blacklight 7 in order to maintain backwards-compat
|
74
|
+
# with overrides of deprecated helpers. In 8.x, we can just call Component#render_in
|
75
|
+
# and call it a day
|
76
|
+
def render_component(component)
|
77
|
+
@view_context.render(component)
|
78
|
+
end
|
79
|
+
|
80
|
+
def facet_item_presenter(facet_item)
|
81
|
+
Blacklight::FacetItemPresenter.new(facet_item, @facet_item.facet_config, @view_context, @facet_item.facet_field, @facet_item.search_state)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -151,7 +151,7 @@ module Blacklight::CatalogHelperBehavior
|
|
151
151
|
# @return [String]
|
152
152
|
def render_document_sidebar_partial(document = nil)
|
153
153
|
unless document
|
154
|
-
Deprecation.warn(self, 'render_document_sidebar_partial expects one argument '
|
154
|
+
Deprecation.warn(self, 'render_document_sidebar_partial expects one argument ' \
|
155
155
|
'(@document) and you passed none. This behavior will be removed in version 8')
|
156
156
|
document = @document
|
157
157
|
end
|
@@ -277,7 +277,7 @@ module Blacklight::CatalogHelperBehavior
|
|
277
277
|
facet_config = facet_configuration_for_field(facet)
|
278
278
|
filter_label = facet_field_label(facet_config.key)
|
279
279
|
filter_value = if values.size < 3
|
280
|
-
values.map { |value|
|
280
|
+
values.map { |value| facet_item_presenter(facet_config, value, facet).label }.to_sentence
|
281
281
|
else
|
282
282
|
t('blacklight.search.page_title.many_constraint_values', values: values.size)
|
283
283
|
end
|
@@ -91,10 +91,11 @@ module Blacklight::ConfigurationHelperBehavior
|
|
91
91
|
end
|
92
92
|
|
93
93
|
# Shortcut for commonly needed operation, look up display
|
94
|
-
# label for the key specified.
|
95
|
-
# can't be found.
|
94
|
+
# label for the key specified.
|
96
95
|
def label_for_search_field(key)
|
97
96
|
field_config = blacklight_config.search_fields[key]
|
97
|
+
return if key.nil? && field_config.nil?
|
98
|
+
|
98
99
|
field_config ||= Blacklight::Configuration::NullField.new(key: key)
|
99
100
|
|
100
101
|
field_config.display_label('search')
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Blacklight::FacetsHelperBehavior
|
3
|
+
extend Deprecation
|
4
|
+
self.deprecation_horizon = 'blacklight 8.0'
|
5
|
+
|
3
6
|
include Blacklight::Facet
|
4
7
|
|
5
8
|
##
|
@@ -14,7 +17,9 @@ module Blacklight::FacetsHelperBehavior
|
|
14
17
|
'8.0.0')
|
15
18
|
response = @response
|
16
19
|
end
|
17
|
-
|
20
|
+
Deprecation.silence(Blacklight::FacetsHelperBehavior) do
|
21
|
+
facets_from_request(fields, response).any? { |display_facet| should_render_facet?(display_facet) }
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
##
|
@@ -58,10 +63,32 @@ module Blacklight::FacetsHelperBehavior
|
|
58
63
|
# @return [String]
|
59
64
|
def render_facet_limit(display_facet, options = {})
|
60
65
|
field_config = facet_configuration_for_field(display_facet.name)
|
61
|
-
return unless should_render_facet?(display_facet, field_config)
|
62
66
|
|
67
|
+
if field_config.component
|
68
|
+
return unless should_render_field?(field_config, display_facet)
|
69
|
+
|
70
|
+
component = field_config.component == true ? Blacklight::FacetFieldListComponent : field_config.component
|
71
|
+
|
72
|
+
return render(
|
73
|
+
component.new(
|
74
|
+
facet_field: facet_field_presenter(field_config, display_facet),
|
75
|
+
layout: (params[:action] == 'facet' ? false : options[:layout])
|
76
|
+
)
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
Deprecation.warn(Blacklight::FacetsHelperBehavior, 'Calling #render_facet_limit on a non-componentized'\
|
81
|
+
' facet is deprecated and will be removed in Blacklight 8')
|
82
|
+
|
83
|
+
Deprecation.silence(Blacklight::FacetsHelperBehavior) do
|
84
|
+
return unless should_render_facet?(display_facet, field_config)
|
85
|
+
end
|
63
86
|
options = options.dup
|
64
|
-
|
87
|
+
|
88
|
+
Deprecation.silence(Blacklight::FacetsHelperBehavior) do
|
89
|
+
options[:partial] ||= facet_partial_name(display_facet)
|
90
|
+
end
|
91
|
+
|
65
92
|
options[:layout] ||= "facet_layout" unless options.key?(:layout)
|
66
93
|
options[:locals] ||= {}
|
67
94
|
options[:locals][:field_name] ||= display_facet.name
|
@@ -76,12 +103,20 @@ module Blacklight::FacetsHelperBehavior
|
|
76
103
|
# removes any elements where render_facet_item returns a nil value. This enables an application
|
77
104
|
# to filter undesireable facet items so they don't appear in the UI
|
78
105
|
def render_facet_limit_list(paginator, facet_field, wrapping_element = :li)
|
79
|
-
|
106
|
+
facet_config ||= facet_configuration_for_field(facet_field)
|
107
|
+
|
108
|
+
collection = paginator.items.map do |item|
|
109
|
+
facet_item_presenter(facet_config, item, facet_field)
|
110
|
+
end
|
111
|
+
|
112
|
+
render(facet_item_component_class(facet_config).with_collection(collection, wrapping_element: wrapping_element))
|
80
113
|
end
|
114
|
+
deprecation_deprecate :render_facet_limit_list
|
81
115
|
|
82
116
|
##
|
83
117
|
# Renders a single facet item
|
84
118
|
def render_facet_item(facet_field, item)
|
119
|
+
deprecated_method(:render_facet_item)
|
85
120
|
if facet_in_params?(facet_field, item.value)
|
86
121
|
render_selected_facet_value(facet_field, item)
|
87
122
|
else
|
@@ -104,6 +139,7 @@ module Blacklight::FacetsHelperBehavior
|
|
104
139
|
facet_config ||= facet_configuration_for_field(display_facet.name)
|
105
140
|
should_render_field?(facet_config, display_facet)
|
106
141
|
end
|
142
|
+
deprecation_deprecate :should_render_facet?
|
107
143
|
|
108
144
|
##
|
109
145
|
# Determine whether a facet should be rendered as collapsed or not.
|
@@ -114,8 +150,11 @@ module Blacklight::FacetsHelperBehavior
|
|
114
150
|
# @param [Blacklight::Configuration::FacetField] facet_field
|
115
151
|
# @return [Boolean]
|
116
152
|
def should_collapse_facet? facet_field
|
117
|
-
|
153
|
+
Deprecation.silence(Blacklight::FacetsHelperBehavior) do
|
154
|
+
!facet_field_in_params?(facet_field.key) && facet_field.collapse
|
155
|
+
end
|
118
156
|
end
|
157
|
+
deprecation_deprecate :should_collapse_facet?
|
119
158
|
|
120
159
|
##
|
121
160
|
# The name of the partial to use to render a facet field.
|
@@ -130,6 +169,11 @@ module Blacklight::FacetsHelperBehavior
|
|
130
169
|
name ||= "facet_pivot" if config.pivot
|
131
170
|
name || "facet_limit"
|
132
171
|
end
|
172
|
+
deprecation_deprecate :facet_partial_name
|
173
|
+
|
174
|
+
def facet_field_presenter(facet_config, display_facet)
|
175
|
+
facet_config.presenter.new(facet_config, display_facet, self)
|
176
|
+
end
|
133
177
|
|
134
178
|
##
|
135
179
|
# Standard display of a facet value in a list. Used in both _facets sidebar
|
@@ -142,13 +186,9 @@ module Blacklight::FacetsHelperBehavior
|
|
142
186
|
# @option options [Boolean] :suppress_link display the facet, but don't link to it
|
143
187
|
# @return [String]
|
144
188
|
def render_facet_value(facet_field, item, options = {})
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
facet_display_value(facet_field, item),
|
149
|
-
path,
|
150
|
-
class: "facet-select")
|
151
|
-
end + render_facet_count(item.hits)
|
189
|
+
deprecated_method(:render_facet_value)
|
190
|
+
facet_config = facet_configuration_for_field(facet_field)
|
191
|
+
facet_item_component(facet_config, item, facet_field, **options).render_facet_value
|
152
192
|
end
|
153
193
|
|
154
194
|
##
|
@@ -158,12 +198,9 @@ module Blacklight::FacetsHelperBehavior
|
|
158
198
|
# @return [String]
|
159
199
|
def path_for_facet(facet_field, item, path_options = {})
|
160
200
|
facet_config = facet_configuration_for_field(facet_field)
|
161
|
-
|
162
|
-
send(facet_config.url_method, facet_field, item)
|
163
|
-
else
|
164
|
-
search_action_path(search_state.add_facet_params_and_redirect(facet_field, item).merge(path_options))
|
165
|
-
end
|
201
|
+
facet_item_presenter(facet_config, item, facet_field).href(path_options)
|
166
202
|
end
|
203
|
+
deprecation_deprecate :path_for_facet
|
167
204
|
|
168
205
|
##
|
169
206
|
# Standard display of a SELECTED facet value (e.g. without a link and with a remove button)
|
@@ -171,15 +208,9 @@ module Blacklight::FacetsHelperBehavior
|
|
171
208
|
# @param [Blacklight::Solr::Response::Facets::FacetField] facet_field
|
172
209
|
# @param [String] item
|
173
210
|
def render_selected_facet_value(facet_field, item)
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
# remove link
|
178
|
-
link_to(remove_href, class: "remove") do
|
179
|
-
content_tag(:span, '✖', class: "remove-icon") +
|
180
|
-
content_tag(:span, '[remove]', class: 'sr-only')
|
181
|
-
end
|
182
|
-
end + render_facet_count(item.hits, classes: ["selected"])
|
211
|
+
deprecated_method(:render_selected_facet_value)
|
212
|
+
facet_config = facet_configuration_for_field(facet_field)
|
213
|
+
facet_item_component(facet_config, item, facet_field).render_selected_facet_value
|
183
214
|
end
|
184
215
|
|
185
216
|
##
|
@@ -191,18 +222,22 @@ module Blacklight::FacetsHelperBehavior
|
|
191
222
|
# @option options [Array<String>] an array of classes to add to count span.
|
192
223
|
# @return [String]
|
193
224
|
def render_facet_count(num, options = {})
|
225
|
+
deprecated_method(:render_facet_count)
|
194
226
|
classes = (options[:classes] || []) << "facet-count"
|
195
227
|
content_tag("span", t('blacklight.search.facets.count', number: number_with_delimiter(num)), class: classes)
|
196
228
|
end
|
197
229
|
|
198
230
|
##
|
199
231
|
# Are any facet restrictions for a field in the query parameters?
|
200
|
-
#
|
232
|
+
# @private
|
201
233
|
# @param [String] field
|
202
234
|
# @return [Boolean]
|
203
235
|
def facet_field_in_params? field
|
204
|
-
|
236
|
+
config = facet_configuration_for_field(field)
|
237
|
+
search_state.has_facet? config
|
205
238
|
end
|
239
|
+
# Left undeprecated for the sake of temporary backwards compatibility
|
240
|
+
# deprecation_deprecate :facet_field_in_params?
|
206
241
|
|
207
242
|
##
|
208
243
|
# Check if the query parameters have the given facet field with the
|
@@ -212,18 +247,19 @@ module Blacklight::FacetsHelperBehavior
|
|
212
247
|
# @param [String] item facet value
|
213
248
|
# @return [Boolean]
|
214
249
|
def facet_in_params?(field, item)
|
215
|
-
|
216
|
-
|
217
|
-
(facet_params(field) || []).include? value
|
250
|
+
config = facet_configuration_for_field(field)
|
251
|
+
search_state.has_facet? config, value: facet_value_for_facet_item(item)
|
218
252
|
end
|
253
|
+
deprecation_deprecate :facet_in_params?
|
219
254
|
|
220
255
|
##
|
221
256
|
# Get the values of the facet set in the blacklight query string
|
222
257
|
def facet_params field
|
223
258
|
config = facet_configuration_for_field(field)
|
224
259
|
|
225
|
-
params
|
260
|
+
search_state.params.dig(:f, config.key)
|
226
261
|
end
|
262
|
+
deprecation_deprecate :facet_params
|
227
263
|
|
228
264
|
##
|
229
265
|
# Get the displayable version of a facet's value
|
@@ -231,30 +267,17 @@ module Blacklight::FacetsHelperBehavior
|
|
231
267
|
# @param [Object] field
|
232
268
|
# @param [String] item value
|
233
269
|
# @return [String]
|
270
|
+
# @deprecated
|
234
271
|
def facet_display_value field, item
|
272
|
+
deprecated_method(:facet_display_value)
|
235
273
|
facet_config = facet_configuration_for_field(field)
|
236
|
-
|
237
|
-
value = if item.respond_to? :label
|
238
|
-
item.label
|
239
|
-
else
|
240
|
-
facet_value_for_facet_item(item)
|
241
|
-
end
|
242
|
-
|
243
|
-
if facet_config.helper_method
|
244
|
-
send facet_config.helper_method, value
|
245
|
-
elsif facet_config.query && facet_config.query[value]
|
246
|
-
facet_config.query[value][:label]
|
247
|
-
elsif facet_config.date
|
248
|
-
localization_options = facet_config.date == true ? {} : facet_config.date
|
249
|
-
l(Time.zone.parse(value), localization_options)
|
250
|
-
else
|
251
|
-
value
|
252
|
-
end
|
274
|
+
facet_item_presenter(facet_config, item, field).label
|
253
275
|
end
|
254
276
|
|
255
277
|
def facet_field_id facet_field
|
256
278
|
"facet-#{facet_field.key.parameterize}"
|
257
279
|
end
|
280
|
+
deprecation_deprecate :facet_field_id
|
258
281
|
|
259
282
|
private
|
260
283
|
|
@@ -265,4 +288,27 @@ module Blacklight::FacetsHelperBehavior
|
|
265
288
|
item
|
266
289
|
end
|
267
290
|
end
|
291
|
+
|
292
|
+
def facet_item_presenter(facet_config, facet_item, facet_field)
|
293
|
+
Blacklight::FacetItemPresenter.new(facet_item, facet_config, self, facet_field)
|
294
|
+
end
|
295
|
+
|
296
|
+
def facet_item_component(facet_config, facet_item, facet_field, **args)
|
297
|
+
facet_item_component_class(facet_config).new(facet_item: facet_item_presenter(facet_config, facet_item, facet_field), **args).with_view_context(self)
|
298
|
+
end
|
299
|
+
|
300
|
+
def facet_item_component_class(facet_config)
|
301
|
+
default_component = facet_config.pivot ? Blacklight::FacetItemPivotComponent : Blacklight::FacetItemComponent
|
302
|
+
facet_config.fetch(:item_component, default_component)
|
303
|
+
end
|
304
|
+
|
305
|
+
# We can't use .deprecation_deprecate here, because the new components need to
|
306
|
+
# see the originally defined location for these methods in order to properly
|
307
|
+
# call back into the helpers for backwards compatibility
|
308
|
+
def deprecated_method(method_name)
|
309
|
+
Deprecation.warn(Blacklight::FacetsHelperBehavior,
|
310
|
+
Deprecation.deprecated_method_warning(Blacklight::FacetsHelperBehavior,
|
311
|
+
method_name, {}),
|
312
|
+
caller)
|
313
|
+
end
|
268
314
|
end
|
@@ -6,14 +6,19 @@
|
|
6
6
|
# Includes methods for rendering contraints graphically on the
|
7
7
|
# search results page (render_constraints(_*))
|
8
8
|
module Blacklight::RenderConstraintsHelperBehavior
|
9
|
+
extend Deprecation
|
10
|
+
self.deprecation_horizon = 'blacklight 8.0'
|
11
|
+
|
9
12
|
##
|
10
13
|
# Check if the query has any constraints defined (a query, facet, etc)
|
11
14
|
#
|
12
15
|
# @param [Hash] localized_params query parameters
|
13
16
|
# @return [Boolean]
|
14
|
-
def query_has_constraints?(
|
15
|
-
|
17
|
+
def query_has_constraints?(params_or_search_state = search_state)
|
18
|
+
search_state = convert_to_search_state(params_or_search_state)
|
19
|
+
search_state.has_constraints?
|
16
20
|
end
|
21
|
+
deprecation_deprecate query_has_constraints?: 'use search_state#has_constraints?'
|
17
22
|
|
18
23
|
##
|
19
24
|
# Render the actual constraints, not including header or footer
|
@@ -21,8 +26,16 @@ module Blacklight::RenderConstraintsHelperBehavior
|
|
21
26
|
#
|
22
27
|
# @param [Hash] localized_params query parameters
|
23
28
|
# @return [String]
|
24
|
-
def render_constraints(localized_params = params)
|
25
|
-
|
29
|
+
def render_constraints(localized_params = params, local_search_state = search_state)
|
30
|
+
params_or_search_state = if localized_params != params
|
31
|
+
localized_params
|
32
|
+
else
|
33
|
+
local_search_state
|
34
|
+
end
|
35
|
+
|
36
|
+
Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
|
37
|
+
render_constraints_query(params_or_search_state) + render_constraints_filters(params_or_search_state)
|
38
|
+
end
|
26
39
|
end
|
27
40
|
|
28
41
|
##
|
@@ -30,15 +43,20 @@ module Blacklight::RenderConstraintsHelperBehavior
|
|
30
43
|
#
|
31
44
|
# @param [ActionController::Parameters] localized_params query parameters
|
32
45
|
# @return [String]
|
33
|
-
def render_constraints_query(
|
46
|
+
def render_constraints_query(params_or_search_state = search_state)
|
47
|
+
search_state = convert_to_search_state(params_or_search_state)
|
48
|
+
|
34
49
|
# So simple don't need a view template, we can just do it here.
|
35
|
-
return "".html_safe if
|
50
|
+
return "".html_safe if search_state.query_param.blank?
|
36
51
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
52
|
+
Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
|
53
|
+
render_constraint_element(constraint_query_label(search_state.params),
|
54
|
+
search_state.query_param,
|
55
|
+
classes: ["query"],
|
56
|
+
remove: remove_constraint_url(search_state))
|
57
|
+
end
|
41
58
|
end
|
59
|
+
deprecation_deprecate :render_constraints_query
|
42
60
|
|
43
61
|
##
|
44
62
|
# Provide a url for removing a particular constraint. This can be overriden
|
@@ -47,52 +65,53 @@ module Blacklight::RenderConstraintsHelperBehavior
|
|
47
65
|
#
|
48
66
|
# @param [ActionController::Parameters] localized_params query parameters
|
49
67
|
# @return [String]
|
50
|
-
def remove_constraint_url(
|
51
|
-
|
52
|
-
|
53
|
-
unless localized_params.is_a? ActionController::Parameters
|
54
|
-
localized_params = ActionController::Parameters.new(localized_params)
|
55
|
-
end
|
68
|
+
def remove_constraint_url(params_or_search_state = search_state)
|
69
|
+
search_state = convert_to_search_state(params_or_search_state)
|
56
70
|
|
57
|
-
|
58
|
-
options.permit!
|
59
|
-
scope.url_for(options)
|
71
|
+
search_action_path(search_state.remove_query_params)
|
60
72
|
end
|
73
|
+
deprecation_deprecate :remove_constraint_url
|
61
74
|
|
62
75
|
##
|
63
76
|
# Render the facet constraints
|
64
77
|
# @param [Hash] localized_params query parameters
|
65
78
|
# @return [String]
|
66
|
-
def render_constraints_filters(
|
67
|
-
|
79
|
+
def render_constraints_filters(params_or_search_state = search_state)
|
80
|
+
search_state = convert_to_search_state(params_or_search_state)
|
68
81
|
|
69
|
-
|
70
|
-
content = []
|
71
|
-
localized_params[:f].each_pair do |facet, values|
|
72
|
-
content << render_filter_element(facet, values, path)
|
73
|
-
end
|
82
|
+
return "".html_safe if search_state.filter_params.blank?
|
74
83
|
|
75
|
-
|
84
|
+
Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
|
85
|
+
safe_join(search_state.filter_params.each_pair.map do |facet, values|
|
86
|
+
render_filter_element(facet, values, search_state)
|
87
|
+
end, "\n")
|
88
|
+
end
|
76
89
|
end
|
90
|
+
deprecation_deprecate :render_constraints_filters
|
77
91
|
|
78
92
|
##
|
79
93
|
# Render a single facet's constraint
|
80
94
|
# @param [String] facet field
|
81
95
|
# @param [Array<String>] values selected facet values
|
82
|
-
# @param [Blacklight::SearchState] path query parameters
|
96
|
+
# @param [Blacklight::SearchState] path query parameters (unused)
|
83
97
|
# @return [String]
|
84
|
-
def render_filter_element(facet, values,
|
98
|
+
def render_filter_element(facet, values, search_state)
|
85
99
|
facet_config = facet_configuration_for_field(facet)
|
86
100
|
|
87
101
|
safe_join(Array(values).map do |val|
|
88
102
|
next if val.blank? # skip empty string
|
89
103
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
104
|
+
presenter = facet_item_presenter(facet_config, val, facet)
|
105
|
+
|
106
|
+
Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
|
107
|
+
render_constraint_element(facet_field_label(facet_config.key),
|
108
|
+
presenter.label,
|
109
|
+
remove: presenter.remove_href(search_state),
|
110
|
+
classes: ["filter", "filter-" + facet.parameterize])
|
111
|
+
end
|
94
112
|
end, "\n")
|
95
113
|
end
|
114
|
+
deprecation_deprecate :render_filter_element
|
96
115
|
|
97
116
|
# Render a label/value constraint on the screen. Can be called
|
98
117
|
# by plugins and such to get application-defined rendering.
|
@@ -111,4 +130,16 @@ module Blacklight::RenderConstraintsHelperBehavior
|
|
111
130
|
def render_constraint_element(label, value, options = {})
|
112
131
|
render(partial: "catalog/constraints_element", locals: { label: label, value: value, options: options })
|
113
132
|
end
|
133
|
+
deprecation_deprecate :render_constraint_element
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
def convert_to_search_state(params_or_search_state)
|
138
|
+
if params_or_search_state.is_a? Blacklight::SearchState
|
139
|
+
params_or_search_state
|
140
|
+
else
|
141
|
+
# deprecated
|
142
|
+
controller.search_state_class.new(params_or_search_state, blacklight_config, controller)
|
143
|
+
end
|
144
|
+
end
|
114
145
|
end
|