blacklight 7.25.3 → 7.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_facets.scss +15 -0
- data/app/components/blacklight/advanced_search_form_component.html.erb +21 -17
- data/app/components/blacklight/advanced_search_form_component.rb +12 -6
- data/app/components/blacklight/facet_component.rb +58 -0
- data/app/components/blacklight/facet_field_checkboxes_component.html.erb +2 -1
- data/app/components/blacklight/facet_field_list_component.rb +1 -1
- data/app/components/blacklight/facet_item_component.rb +11 -9
- data/app/controllers/concerns/blacklight/catalog.rb +11 -3
- data/app/helpers/blacklight/facets_helper_behavior.rb +3 -6
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +29 -3
- data/app/presenters/blacklight/clause_presenter.rb +1 -1
- data/app/views/bookmarks/_tools.html.erb +1 -1
- data/lib/blacklight/solr/response/facets.rb +6 -0
- data/lib/generators/blacklight/templates/solr/conf/solrconfig.xml +1 -0
- data/spec/components/blacklight/facet_component_spec.rb +102 -0
- data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +1 -1
- data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +24 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39fe32f4252deb7d8bb08a1d2781a8d1af7e387eb2bafc93fc083cd13eda9b21
|
4
|
+
data.tar.gz: f0b41d058163f54ca1f5a11b745077c8404eea4f8cea43d87c8ea4e6d6ed0d30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e02cee90b4acb73a5b3fe4883c2a076f37146200fdec169bc3bbf0012ffcd79e5244019ee703c97c601f7100bdaecacf65617dccbc2050911b0fa4e7a24eefbd
|
7
|
+
data.tar.gz: 80036e1203a14f9d7f90e11a8fd02309e447d29be4f1deb4250d7628a3bcfad1ed00e43d57d9152fd1fff751e27e983af0adb0747978978039a6d1d81309e688
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.
|
1
|
+
7.27.0
|
@@ -120,6 +120,21 @@
|
|
120
120
|
text-align: right;
|
121
121
|
width: 5em;
|
122
122
|
}
|
123
|
+
|
124
|
+
.facet-checkbox {
|
125
|
+
display: table-cell;
|
126
|
+
width: 1.25rem;
|
127
|
+
vertical-align: top;
|
128
|
+
}
|
129
|
+
|
130
|
+
.label-and-count {
|
131
|
+
display: table;
|
132
|
+
width: 100%;
|
133
|
+
}
|
134
|
+
|
135
|
+
.label-and-count label {
|
136
|
+
display: table-row;
|
137
|
+
}
|
123
138
|
}
|
124
139
|
|
125
140
|
.facet-extended-list {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% if constraints
|
1
|
+
<% if constraints? %>
|
2
2
|
<div class="constraints well search_history">
|
3
3
|
<h4><%= t 'blacklight.advanced_search.form.search_context' %></h4>
|
4
4
|
<% constraints.each do |constraint| %>
|
@@ -11,8 +11,8 @@
|
|
11
11
|
<%= render_hash_as_hidden_fields(@params) %>
|
12
12
|
|
13
13
|
<div class="input-criteria">
|
14
|
-
<div class="query-criteria">
|
15
|
-
<h2 class="query-criteria-heading">
|
14
|
+
<div class="query-criteria mb-4">
|
15
|
+
<h2 class="query-criteria-heading h3 mb-4">
|
16
16
|
<%= t('blacklight.advanced_search.form.query_criteria_heading_html', select_menu: default_operator_menu) %>
|
17
17
|
</h2>
|
18
18
|
|
@@ -23,28 +23,32 @@
|
|
23
23
|
</div>
|
24
24
|
</div>
|
25
25
|
|
26
|
-
|
27
|
-
<
|
26
|
+
<% if search_filter_controls? %>
|
27
|
+
<div class="limit-criteria mb-4">
|
28
|
+
<h2 class="limit-criteria-heading h3"><%= t('blacklight.advanced_search.form.limit_criteria_heading_html')%></h2>
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
<div id="advanced_search_facets" class="limit_input row">
|
31
|
+
<div class="advanced-facet-limits panel-group col-md-9 offset-md-3">
|
32
|
+
<% search_filter_controls.each do |control| %>
|
33
|
+
<%= control %>
|
34
|
+
<% end %>
|
35
|
+
</div>
|
34
36
|
</div>
|
35
37
|
</div>
|
36
|
-
|
38
|
+
<% end %>
|
37
39
|
</div>
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
<% if sort_fields_select %>
|
42
|
+
<div class="form-group row mb-4">
|
43
|
+
<%= content_tag :h2, t('blacklight.advanced_search.form.sort_label'), class: 'col-md-3 col-form-label text-md-right' %>
|
44
|
+
<div class="col">
|
45
|
+
<%= sort_fields_select %>
|
46
|
+
</div>
|
43
47
|
</div>
|
44
|
-
|
48
|
+
<% end %>
|
45
49
|
|
46
50
|
<div class="form-group row">
|
47
|
-
<div class="submit-buttons col-
|
51
|
+
<div class="submit-buttons col-md-9 offset-md-3">
|
48
52
|
<%= submit_tag t('blacklight.advanced_search.form.search_btn_html'), class: 'btn btn-primary advanced-search-submit', id: "advanced-search-submit" %>
|
49
53
|
<%= button_tag t('blacklight.advanced_search.form.start_over_html'), type: 'reset', class: 'btn btn-link advanced-search-start-over' %>
|
50
54
|
</div>
|
@@ -31,7 +31,9 @@ module Blacklight
|
|
31
31
|
|
32
32
|
def sort_fields_select
|
33
33
|
options = sort_fields.values.map { |field_config| [helpers.sort_field_label(field_config.key), field_config.key] }
|
34
|
-
|
34
|
+
return unless options.any?
|
35
|
+
|
36
|
+
select_tag(:sort, options_for_select(options, params[:sort]), class: "form-control sort-select w-auto")
|
35
37
|
end
|
36
38
|
|
37
39
|
private
|
@@ -41,7 +43,7 @@ module Blacklight
|
|
41
43
|
search_field_control do
|
42
44
|
fields_for('clause[]', i, include_id: false) do |f|
|
43
45
|
content_tag(:div, class: 'form-group advanced-search-field row') do
|
44
|
-
f.label(:query, field.display_label('search'), class: "col-
|
46
|
+
f.label(:query, field.display_label('search'), class: "col-md-3 col-form-label text-md-right") +
|
45
47
|
content_tag(:div, class: 'col-sm-9') do
|
46
48
|
f.hidden_field(:field, value: field.key) +
|
47
49
|
f.text_field(:query, value: query_for_search_clause(field.key), class: 'form-control')
|
@@ -62,12 +64,16 @@ module Blacklight
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def initialize_constraints
|
65
|
-
|
66
|
-
|
67
|
+
params = helpers.search_state.params_for_search.except :page, :f_inclusive, :q, :search_field, :op, :index, :sort
|
68
|
+
|
69
|
+
adv_search_context = helpers.search_state.reset(params)
|
67
70
|
|
68
|
-
|
71
|
+
constraints_text = render(Blacklight::ConstraintsComponent.for_search_history(search_state: adv_search_context))
|
69
72
|
|
70
|
-
|
73
|
+
return if constraints_text.blank?
|
74
|
+
|
75
|
+
constraint do
|
76
|
+
constraints_text
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Blacklight
|
4
|
+
##
|
5
|
+
# Renders a single section for facet limit with a specified
|
6
|
+
# solr field used for faceting. This renders no UI of it's own, but renders
|
7
|
+
# the component that is configured for the facet.
|
8
|
+
class FacetComponent < ViewComponent::Base
|
9
|
+
with_collection_parameter :display_facet_or_field_config
|
10
|
+
|
11
|
+
# @param [Blacklight::Solr::Response::Facets::FacetField] display_facet
|
12
|
+
# @param [Blacklight::Configuration] blacklight_config
|
13
|
+
# @param [Boolean] layout
|
14
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
15
|
+
def initialize(display_facet_or_field_config: nil, display_facet: nil, field_config: nil, response: nil, blacklight_config: nil, **component_args)
|
16
|
+
if display_facet_or_field_config.is_a? Blacklight::FacetFieldPresenter
|
17
|
+
@facet_field_presenter = display_facet_or_field_config
|
18
|
+
@field_config = @facet_field_presenter.facet_field
|
19
|
+
@display_facet = @facet_field_presenter.display_facet
|
20
|
+
elsif display_facet_or_field_config.is_a?(Blacklight::Configuration::Field) || field_config
|
21
|
+
@facet_field_presenter = nil # we need the view context to generate this
|
22
|
+
@field_config = display_facet_or_field_config || field_config
|
23
|
+
@display_facet = display_facet ||
|
24
|
+
response&.aggregations&.fetch(@field_config.field) { Blacklight::Solr::Response::Facets::NullFacetField.new(@field_config.field, response: response) }
|
25
|
+
elsif (display_facet || display_facet_or_field_config).respond_to?(:name)
|
26
|
+
@facet_field_presenter = nil # we need the view context to generate this
|
27
|
+
@display_facet = display_facet || display_facet_or_field_config
|
28
|
+
@field_config = field_config || blacklight_config&.facet_configuration_for_field(@display_facet.name)
|
29
|
+
else
|
30
|
+
raise ArgumentError, 'You must provide one of display_facet or field_config' unless @field_config
|
31
|
+
end
|
32
|
+
|
33
|
+
@component_args = component_args
|
34
|
+
end
|
35
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
36
|
+
|
37
|
+
def render?
|
38
|
+
helpers.should_render_field?(@field_config, @display_facet)
|
39
|
+
end
|
40
|
+
|
41
|
+
def call
|
42
|
+
return render_partial if @field_config.partial
|
43
|
+
|
44
|
+
component = @field_config.component == true ? Blacklight::FacetFieldListComponent : @field_config.component
|
45
|
+
|
46
|
+
render(
|
47
|
+
component.new(
|
48
|
+
facet_field: @facet_field_presenter || helpers.facet_field_presenter(@field_config, @display_facet),
|
49
|
+
**@component_args
|
50
|
+
)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def render_partial
|
55
|
+
helpers.render(@field_config.partial, locals: { field_name: @field_config.field, facet_field: @field_config, display_facet: @display_facet }.merge(@component_args))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -13,7 +13,8 @@
|
|
13
13
|
|
14
14
|
<span class="label-and-count">
|
15
15
|
<%= label_tag "f_inclusive_#{@facet_field.key}_#{idx}" do %>
|
16
|
-
|
16
|
+
<span class="facet-label"><%= presenter.label %></span>
|
17
|
+
<span class="facet-count"><%= t('blacklight.search.facets.count', number: number_with_delimiter(presenter.hits)) %></span>
|
17
18
|
<% end %>
|
18
19
|
<span>
|
19
20
|
</li>
|
@@ -4,6 +4,8 @@ module Blacklight
|
|
4
4
|
class FacetItemComponent < Blacklight::Component
|
5
5
|
extend Deprecation
|
6
6
|
|
7
|
+
attr_reader :label, :href, :hits
|
8
|
+
|
7
9
|
with_collection_parameter :facet_item
|
8
10
|
|
9
11
|
def initialize(facet_item:, wrapping_element: 'li', suppress_link: false)
|
@@ -48,9 +50,9 @@ module Blacklight
|
|
48
50
|
def overridden_helper_methods?
|
49
51
|
return false if explicit_component_configuration?
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
helpers.method(:render_facet_item).owner != Blacklight::FacetsHelperBehavior ||
|
54
|
+
helpers.method(:render_facet_value).owner != Blacklight::FacetsHelperBehavior ||
|
55
|
+
helpers.method(:render_selected_facet_value).owner != Blacklight::FacetsHelperBehavior
|
54
56
|
end
|
55
57
|
|
56
58
|
# Call out to the helper method equivalent of this component
|
@@ -72,7 +74,7 @@ module Blacklight
|
|
72
74
|
# @private
|
73
75
|
def render_facet_value
|
74
76
|
tag.span(class: "facet-label") do
|
75
|
-
link_to_unless(@suppress_link,
|
77
|
+
link_to_unless(@suppress_link, label, href, class: "facet-select", rel: "nofollow")
|
76
78
|
end + render_facet_count
|
77
79
|
end
|
78
80
|
|
@@ -83,9 +85,9 @@ module Blacklight
|
|
83
85
|
# @private
|
84
86
|
def render_selected_facet_value
|
85
87
|
tag.span(class: "facet-label") do
|
86
|
-
tag.span(
|
88
|
+
tag.span(label, class: "selected") +
|
87
89
|
# remove link
|
88
|
-
link_to(
|
90
|
+
link_to(href, class: "remove", rel: "nofollow") do
|
89
91
|
tag.span('✖', class: "remove-icon", aria: { hidden: true }) +
|
90
92
|
tag.span(helpers.t(:'blacklight.search.facets.selected.remove'), class: 'sr-only visually-hidden')
|
91
93
|
end
|
@@ -101,12 +103,12 @@ module Blacklight
|
|
101
103
|
# @return [String]
|
102
104
|
# @private
|
103
105
|
def render_facet_count(options = {})
|
104
|
-
return helpers.render_facet_count(
|
106
|
+
return helpers.render_facet_count(hits, options) unless helpers.method(:render_facet_count).owner == Blacklight::FacetsHelperBehavior || explicit_component_configuration?
|
105
107
|
|
106
|
-
return '' if
|
108
|
+
return '' if hits.blank?
|
107
109
|
|
108
110
|
classes = (options[:classes] || []) << "facet-count"
|
109
|
-
tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(
|
111
|
+
tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(hits)), class: classes)
|
110
112
|
end
|
111
113
|
|
112
114
|
private
|
@@ -60,9 +60,7 @@ module Blacklight::Catalog
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def advanced_search
|
63
|
-
|
64
|
-
|
65
|
-
(@response, _deprecated_document_list) = empty_service.search_results
|
63
|
+
(@response, _deprecated_document_list) = blacklight_advanced_search_form_search_service.search_results
|
66
64
|
end
|
67
65
|
|
68
66
|
# get a single document from the index
|
@@ -334,4 +332,14 @@ module Blacklight::Catalog
|
|
334
332
|
flash[:notice] = flash_notice
|
335
333
|
redirect_to search_action_url
|
336
334
|
end
|
335
|
+
|
336
|
+
def blacklight_advanced_search_form_search_service
|
337
|
+
form_search_state = search_state_class.new(blacklight_advanced_search_form_params, blacklight_config, self)
|
338
|
+
|
339
|
+
search_service_class.new(config: blacklight_config, search_state: form_search_state, user_params: form_search_state.to_h, **search_service_context)
|
340
|
+
end
|
341
|
+
|
342
|
+
def blacklight_advanced_search_form_params
|
343
|
+
{}
|
344
|
+
end
|
337
345
|
end
|
@@ -76,13 +76,10 @@ module Blacklight::FacetsHelperBehavior
|
|
76
76
|
field_config = facet_configuration_for_field(display_facet.name)
|
77
77
|
|
78
78
|
if field_config.component
|
79
|
-
return unless should_render_field?(field_config, display_facet)
|
80
|
-
|
81
|
-
component = field_config.component == true ? Blacklight::FacetFieldListComponent : field_config.component
|
82
|
-
|
83
79
|
return render(
|
84
|
-
|
85
|
-
|
80
|
+
Blacklight::FacetComponent.new(
|
81
|
+
display_facet: display_facet,
|
82
|
+
field_config: field_config,
|
86
83
|
layout: (params[:action] == 'facet' ? false : options[:layout])
|
87
84
|
)
|
88
85
|
)
|
@@ -35,7 +35,7 @@ module Blacklight::RenderConstraintsHelperBehavior
|
|
35
35
|
end
|
36
36
|
|
37
37
|
Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
|
38
|
-
render_constraints_query(params_or_search_state) + render_constraints_filters(params_or_search_state)
|
38
|
+
render_constraints_query(params_or_search_state) + render_constraints_clauses(params_or_search_state) + render_constraints_filters(params_or_search_state)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -60,6 +60,24 @@ module Blacklight::RenderConstraintsHelperBehavior
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
##
|
64
|
+
# Render the query constraints
|
65
|
+
#
|
66
|
+
# @deprecated
|
67
|
+
# @param [Blacklight::SearchState,ActionController::Parameters] params_or_search_state query parameters
|
68
|
+
# @return [String]
|
69
|
+
def render_constraints_clauses(params_or_search_state = search_state)
|
70
|
+
search_state = convert_to_search_state(params_or_search_state)
|
71
|
+
|
72
|
+
clause_presenters = search_state.clause_params.map do |key, clause|
|
73
|
+
field_config = blacklight_config.search_fields[clause[:field]]
|
74
|
+
Blacklight::ClausePresenter.new(key, clause, field_config, self, search_state)
|
75
|
+
end
|
76
|
+
|
77
|
+
render(Blacklight::ConstraintComponent.with_collection(clause_presenters))
|
78
|
+
end
|
79
|
+
deprecation_deprecate :render_constraints_clauses
|
80
|
+
|
63
81
|
##
|
64
82
|
# Provide a url for removing a particular constraint. This can be overriden
|
65
83
|
# in the case that you want parameters other than the defaults to be removed
|
@@ -107,9 +125,13 @@ module Blacklight::RenderConstraintsHelperBehavior
|
|
107
125
|
safe_join(Array(values).map do |val|
|
108
126
|
next if val.blank? # skip empty string
|
109
127
|
|
110
|
-
presenter = facet_item_presenter(facet_config, val, facet)
|
111
|
-
|
112
128
|
Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
|
129
|
+
presenter = if val.is_a? Array
|
130
|
+
inclusive_facet_item_presenter(facet_config, val, facet)
|
131
|
+
else
|
132
|
+
facet_item_presenter(facet_config, val, facet)
|
133
|
+
end
|
134
|
+
|
113
135
|
render_constraint_element(presenter.field_label,
|
114
136
|
presenter.label,
|
115
137
|
remove: presenter.remove_href(search_state),
|
@@ -118,6 +140,10 @@ module Blacklight::RenderConstraintsHelperBehavior
|
|
118
140
|
end, "\n")
|
119
141
|
end
|
120
142
|
|
143
|
+
def inclusive_facet_item_presenter(facet_config, facet_item, facet_field)
|
144
|
+
Blacklight::InclusiveFacetItemPresenter.new(facet_item, facet_config, self, facet_field)
|
145
|
+
end
|
146
|
+
|
121
147
|
# Render a label/value constraint on the screen. Can be called
|
122
148
|
# by plugins and such to get application-defined rendering.
|
123
149
|
#
|
@@ -25,7 +25,7 @@ module Blacklight
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def remove_href(path = search_state)
|
28
|
-
view_context.search_action_path(path.reset_search(clause: path.clause_params.except(key)))
|
28
|
+
view_context.search_action_path(path.reset_search(clause: path.clause_params.except(key)).to_h)
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% if render_show_doc_actions_method_from_blacklight? %>
|
2
|
-
<%= render(Blacklight::Document::ActionsComponent.new(document: nil, tag: 'div', classes: "#{controller_name}Tools",
|
2
|
+
<%= render(Blacklight::Document::ActionsComponent.new(document: nil, tag: 'div', classes: "#{controller_name}Tools", link_classes: 'btn btn-outline-primary', actions: document_actions(document_list, options: { document: nil }), options: { document_list: @response.documents }, url_opts: Blacklight::Parameters.sanitize(params.to_unsafe_h))) %>
|
3
3
|
<% else %>
|
4
4
|
<% Deprecation.warn(self, '#render_show_doc_actions is deprecated; use ActionComponents instead') %>
|
5
5
|
<ul class="<%= controller_name %>Tools nav nav-pills">
|
@@ -99,6 +99,12 @@ module Blacklight::Solr::Response::Facets
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
class NullFacetField < FacetField
|
103
|
+
def initialize name, items = [], response: nil, **kwargs
|
104
|
+
super(name, items, response: response, **kwargs)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
102
108
|
##
|
103
109
|
# Get all the Solr facet data (fields, queries, pivots) as a hash keyed by
|
104
110
|
# both the Solr field name and/or by the blacklight field name
|
@@ -17,6 +17,7 @@
|
|
17
17
|
</updateHandler>
|
18
18
|
|
19
19
|
<!-- solr lib dirs -->
|
20
|
+
<lib dir="${solr.install.dir:../../../..}/contrib/modules/lib" />
|
20
21
|
<lib dir="${solr.install.dir:../../../..}/contrib/analysis-extras/lib" />
|
21
22
|
<lib dir="${solr.install.dir:../../../..}/contrib/analysis-extras/lucene-libs" />
|
22
23
|
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Blacklight::FacetComponent, type: :component do
|
6
|
+
subject(:rendered) do
|
7
|
+
render_inline_to_capybara_node(component)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:component) { described_class.new(**component_kwargs) }
|
11
|
+
let(:component_kwargs) { { field_config: facet_config, display_facet: display_facet } }
|
12
|
+
let(:items) { [{ label: "Book", value: 'Book', hits: 20 }] }
|
13
|
+
|
14
|
+
let(:display_facet) do
|
15
|
+
instance_double(Blacklight::Solr::Response::Facets::FacetField, name: 'field', items: items, limit: nil, sort: :index, offset: 0, prefix: nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:facet_config) { Blacklight::Configuration::FacetField.new(key: 'field', component: Blacklight::FacetFieldListComponent).normalize! }
|
19
|
+
|
20
|
+
before do
|
21
|
+
allow(controller).to receive(:view_context).and_return(controller.view_context)
|
22
|
+
allow(controller.view_context).to receive(:facet_limit_for).and_return(20)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'delegates to the configured component to render something' do
|
26
|
+
expect(rendered).to have_selector 'ul.facet-values'
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with a facet configured to use a partial' do
|
30
|
+
let(:facet_config) do
|
31
|
+
Blacklight::Configuration::FacetField.new(key: 'field', partial: 'catalog/facet_partial').normalize!
|
32
|
+
end
|
33
|
+
|
34
|
+
before do
|
35
|
+
controller.view_context.view_paths.unshift(RSpec::Rails::ViewExampleGroup::StubResolverCache.resolver_for('catalog/_facet_partial.html.erb' => 'facet partial'))
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'renders the partial' do
|
39
|
+
expect(rendered).to have_content 'facet partial'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with a field and response' do
|
44
|
+
let(:component_kwargs) do
|
45
|
+
{ display_facet_or_field_config: facet_config, response: response }
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:response) { instance_double(Blacklight::Solr::Response, aggregations: { 'field' => display_facet }) }
|
49
|
+
|
50
|
+
it 'extracts the facet data from the response to pass on to the rendering component' do
|
51
|
+
allow(facet_config.component).to receive(:new).and_call_original
|
52
|
+
|
53
|
+
rendered
|
54
|
+
|
55
|
+
expect(facet_config.component).to have_received(:new).with(facet_field: have_attributes(facet_field: facet_config, display_facet: display_facet))
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when the field is not in the response' do
|
59
|
+
let(:facet_config) { Blacklight::Configuration::FacetField.new(key: 'some_other_field', component: Blacklight::FacetFieldListComponent).normalize! }
|
60
|
+
|
61
|
+
it 'uses a null field to pass through the response information anyway' do
|
62
|
+
allow(facet_config.component).to receive(:new).and_call_original
|
63
|
+
|
64
|
+
rendered
|
65
|
+
|
66
|
+
expect(facet_config.component).to have_received(:new).with(facet_field: have_attributes(facet_field: facet_config, display_facet: have_attributes(items: [], response: response)))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with a display facet and configuration' do
|
72
|
+
let(:component_kwargs) do
|
73
|
+
{ display_facet_or_field_config: display_facet, blacklight_config: blacklight_config }
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:blacklight_config) { Blacklight::Configuration.new.tap { |config| config.facet_fields['field'] = facet_config } }
|
77
|
+
|
78
|
+
it 'pulls the facet config from the blacklight config' do
|
79
|
+
allow(facet_config.component).to receive(:new).and_call_original
|
80
|
+
|
81
|
+
rendered
|
82
|
+
|
83
|
+
expect(facet_config.component).to have_received(:new).with(facet_field: have_attributes(facet_field: facet_config, display_facet: display_facet))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with a presenter' do
|
88
|
+
let(:component_kwargs) do
|
89
|
+
{ display_facet_or_field_config: presenter }
|
90
|
+
end
|
91
|
+
|
92
|
+
let(:presenter) { Blacklight::FacetFieldPresenter.new(facet_config, display_facet, controller.view_context) }
|
93
|
+
|
94
|
+
it 'renders the component with the provided presenter' do
|
95
|
+
allow(facet_config.component).to receive(:new).and_call_original
|
96
|
+
|
97
|
+
rendered
|
98
|
+
|
99
|
+
expect(facet_config.component).to have_received(:new).with(facet_field: presenter)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -199,7 +199,7 @@ RSpec.describe Blacklight::FacetsHelperBehavior do
|
|
199
199
|
|
200
200
|
it "lets you override the rendered partial for pivot facets" do
|
201
201
|
mock_facet = double(name: 'component_field')
|
202
|
-
expect(helper).to receive(:render).with(an_instance_of(Blacklight::
|
202
|
+
expect(helper).to receive(:render).with(an_instance_of(Blacklight::FacetComponent))
|
203
203
|
helper.render_facet_limit(mock_facet)
|
204
204
|
end
|
205
205
|
|
@@ -6,6 +6,7 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
|
|
6
6
|
let(:config) do
|
7
7
|
Blacklight::Configuration.new do |config|
|
8
8
|
config.add_facet_field 'type'
|
9
|
+
config.add_search_field 'title'
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -31,6 +32,21 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
describe '#render_constraints_clauses' do
|
36
|
+
subject { helper.render_constraints_clauses(params) }
|
37
|
+
|
38
|
+
let(:my_engine) { double("Engine") }
|
39
|
+
let(:params) { ActionController::Parameters.new(clause: { "0": { field: 'title', query: 'nature' } }, f: { type: 'journal' }) }
|
40
|
+
|
41
|
+
it 'renders the clause constraint' do
|
42
|
+
expect(subject).to have_selector '.constraint-value', text: /Title\s+nature/
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has a link relative to the current url" do
|
46
|
+
expect(subject).to have_link 'Remove constraint Title: nature', href: '/catalog?f%5Btype%5D%5B%5D=journal'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
34
50
|
describe '#render_filter_element' do
|
35
51
|
subject { helper.render_filter_element('type', ['journal'], path) }
|
36
52
|
|
@@ -54,6 +70,14 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
|
|
54
70
|
expect(subject).to have_link "Remove constraint Item Type: journal", href: "/catalog?q=biz"
|
55
71
|
end
|
56
72
|
end
|
73
|
+
|
74
|
+
context 'with multivalued facets' do
|
75
|
+
subject { helper.render_filter_element('type', [%w[journal book]], path) }
|
76
|
+
|
77
|
+
it "handles such values gracefully" do
|
78
|
+
expect(subject).to have_link "Remove constraint Item Type: journal OR book", href: "/catalog?q=biz"
|
79
|
+
end
|
80
|
+
end
|
57
81
|
end
|
58
82
|
|
59
83
|
describe "#render_constraints_filters" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacklight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Rochkind
|
@@ -14,10 +14,10 @@ authors:
|
|
14
14
|
- Dan Funk
|
15
15
|
- Naomi Dushay
|
16
16
|
- Justin Coyne
|
17
|
-
autorequire:
|
17
|
+
autorequire:
|
18
18
|
bindir: exe
|
19
19
|
cert_chain: []
|
20
|
-
date: 2022-
|
20
|
+
date: 2022-07-01 00:00:00.000000000 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rails
|
@@ -453,6 +453,7 @@ files:
|
|
453
453
|
- app/components/blacklight/document_metadata_component.rb
|
454
454
|
- app/components/blacklight/document_title_component.html.erb
|
455
455
|
- app/components/blacklight/document_title_component.rb
|
456
|
+
- app/components/blacklight/facet_component.rb
|
456
457
|
- app/components/blacklight/facet_field_checkboxes_component.html.erb
|
457
458
|
- app/components/blacklight/facet_field_checkboxes_component.rb
|
458
459
|
- app/components/blacklight/facet_field_component.html.erb
|
@@ -779,6 +780,7 @@ files:
|
|
779
780
|
- spec/components/blacklight/document/group_component_spec.rb
|
780
781
|
- spec/components/blacklight/document_component_spec.rb
|
781
782
|
- spec/components/blacklight/document_metadata_component_spec.rb
|
783
|
+
- spec/components/blacklight/facet_component_spec.rb
|
782
784
|
- spec/components/blacklight/facet_field_checkboxes_component_spec.rb
|
783
785
|
- spec/components/blacklight/facet_field_list_component_spec.rb
|
784
786
|
- spec/components/blacklight/facet_item_component_spec.rb
|
@@ -931,7 +933,7 @@ homepage: http://projectblacklight.org/
|
|
931
933
|
licenses:
|
932
934
|
- Apache 2.0
|
933
935
|
metadata: {}
|
934
|
-
post_install_message:
|
936
|
+
post_install_message:
|
935
937
|
rdoc_options: []
|
936
938
|
require_paths:
|
937
939
|
- lib
|
@@ -946,8 +948,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
946
948
|
- !ruby/object:Gem::Version
|
947
949
|
version: '0'
|
948
950
|
requirements: []
|
949
|
-
rubygems_version: 3.2
|
950
|
-
signing_key:
|
951
|
+
rubygems_version: 3.1.2
|
952
|
+
signing_key:
|
951
953
|
specification_version: 4
|
952
954
|
summary: Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr)
|
953
955
|
index.
|
@@ -959,6 +961,7 @@ test_files:
|
|
959
961
|
- spec/components/blacklight/document/group_component_spec.rb
|
960
962
|
- spec/components/blacklight/document_component_spec.rb
|
961
963
|
- spec/components/blacklight/document_metadata_component_spec.rb
|
964
|
+
- spec/components/blacklight/facet_component_spec.rb
|
962
965
|
- spec/components/blacklight/facet_field_checkboxes_component_spec.rb
|
963
966
|
- spec/components/blacklight/facet_field_list_component_spec.rb
|
964
967
|
- spec/components/blacklight/facet_item_component_spec.rb
|