blacklight_range_limit 8.0.1 → 8.2.1
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/.github/workflows/ruby.yml +14 -46
- data/README.md +4 -4
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight_range_limit/range_limit_distro_facets.js +1 -1
- data/app/assets/javascripts/blacklight_range_limit/range_limit_plotting.js +27 -15
- data/app/assets/javascripts/blacklight_range_limit/range_limit_slider.js +29 -9
- data/app/components/blacklight_range_limit/range_facet_component.html.erb +48 -0
- data/app/components/blacklight_range_limit/range_facet_component.rb +29 -0
- data/app/components/blacklight_range_limit/range_form_component.html.erb +12 -0
- data/app/components/blacklight_range_limit/range_form_component.rb +46 -0
- data/app/components/blacklight_range_limit/range_segments_component.html.erb +3 -0
- data/app/components/blacklight_range_limit/range_segments_component.rb +26 -0
- data/app/helpers/range_limit_helper.rb +70 -79
- data/app/presenters/blacklight_range_limit/facet_field_presenter.rb +85 -0
- data/app/presenters/blacklight_range_limit/facet_item_presenter.rb +45 -0
- data/app/presenters/blacklight_range_limit/filter_field.rb +85 -0
- data/app/views/blacklight_range_limit/_range_segments.html.erb +7 -21
- data/app/views/blacklight_range_limit/range_segments.html.erb +1 -1
- data/app/views/catalog/range_limit_panel.html.erb +1 -0
- data/blacklight_range_limit.gemspec +1 -1
- data/config/locales/blacklight_range_limit.de.yml +13 -0
- data/config/locales/blacklight_range_limit.it.yml +13 -0
- data/lib/blacklight_range_limit/controller_override.rb +41 -24
- data/lib/blacklight_range_limit/engine.rb +4 -0
- data/lib/blacklight_range_limit/facet_field_config_override.rb +25 -0
- data/lib/blacklight_range_limit/range_limit_builder.rb +15 -39
- data/lib/blacklight_range_limit/segment_calculation.rb +2 -2
- data/lib/blacklight_range_limit.rb +31 -12
- data/lib/generators/blacklight_range_limit/install_generator.rb +3 -17
- data/solr/conf/schema.xml +0 -13
- data/solr/conf/solrconfig.xml +1 -0
- data/spec/components/range_facet_component_spec.rb +111 -0
- data/spec/features/a_javascript_spec.rb +4 -4
- data/spec/features/blacklight_range_limit_spec.rb +7 -6
- data/spec/helpers/blacklight_range_limit_helper_spec.rb +7 -7
- data/spec/presenters/facet_field_presenter_spec.rb +144 -0
- data/spec/presenters/facet_item_presenter_spec.rb +47 -0
- data/spec/presenters/filter_field_spec.rb +79 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/support/presenter_test_helpers.rb +11 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
- metadata +40 -17
- data/app/views/blacklight_range_limit/_range_limit_panel.html.erb +0 -90
- data/app/views/blacklight_range_limit/range_limit_panel.html.erb +0 -10
- data/lib/blacklight_range_limit/view_helper_override.rb +0 -100
- data/lib/generators/blacklight_range_limit/templates/search_history_controller.rb +0 -7
- data/spec/lib/blacklight_range_limit/view_helper_override_helper_spec.rb +0 -137
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe BlacklightRangeLimit::FilterField do
|
6
|
+
let(:search_state) { Blacklight::SearchState.new(params, blacklight_config, controller) }
|
7
|
+
|
8
|
+
let(:param_values) { {} }
|
9
|
+
let(:params) { ActionController::Parameters.new(param_values) }
|
10
|
+
let(:blacklight_config) do
|
11
|
+
Blacklight::Configuration.new.configure do |config|
|
12
|
+
config.add_facet_field 'some_field', filter_class: described_class
|
13
|
+
config.filter_search_state_fields = true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
let(:controller) { double }
|
17
|
+
let(:filter) { search_state.filter('some_field') }
|
18
|
+
|
19
|
+
describe '#add' do
|
20
|
+
it 'adds a new range parameter' do
|
21
|
+
new_state = filter.add(1999..2099)
|
22
|
+
|
23
|
+
expect(new_state.params.dig(:range, 'some_field')).to include begin: 1999, end: 2099
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with some existing data' do
|
28
|
+
let(:param_values) { { range: { some_field: { begin: '2013', end: '2022' } } } }
|
29
|
+
|
30
|
+
describe '#add' do
|
31
|
+
it 'replaces the existing range' do
|
32
|
+
new_state = filter.add(1999..2099)
|
33
|
+
|
34
|
+
expect(new_state.params.dig(:range, 'some_field')).to include begin: 1999, end: 2099
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#remove' do
|
39
|
+
it 'removes the existing range' do
|
40
|
+
new_state = filter.remove(2013..2022)
|
41
|
+
|
42
|
+
expect(new_state.params.dig(:range, 'some_field')).to be_blank
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#values' do
|
47
|
+
it 'converts the parameters to a Range' do
|
48
|
+
expect(filter.values).to eq [2013..2022]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#include?' do
|
53
|
+
it 'compares the provided value to the parameter values' do
|
54
|
+
expect(filter.include?(2013..2022)).to eq true
|
55
|
+
expect(filter.include?(1234..2345)).to eq false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with missing data' do
|
61
|
+
let(:param_values) { { range: { some_field: { begin: '', end: '' } } } }
|
62
|
+
|
63
|
+
describe '#values' do
|
64
|
+
it 'drops the empty range' do
|
65
|
+
expect(filter.values).to be_empty
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with array-mangled data' do
|
71
|
+
let(:param_values) { { range: { some_field: { begin: { '0' => '2013' }, end: { '0' => '2022' } } } } }
|
72
|
+
|
73
|
+
describe '#values' do
|
74
|
+
it 'converts the parameters to a Range' do
|
75
|
+
expect(filter.values).to eq [2013..2022]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,6 +21,10 @@ Capybara.register_driver :headless_chrome do |app|
|
|
21
21
|
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
|
22
22
|
end
|
23
23
|
|
24
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
25
|
+
# in spec/support/ and its subdirectories.
|
26
|
+
Dir[Pathname.new(File.expand_path('support/**/*.rb', __dir__))].sort.each { |f| require f }
|
27
|
+
|
24
28
|
RSpec.configure do |config|
|
25
29
|
# rspec-rails 3 will no longer automatically infer an example group's spec type
|
26
30
|
# from the file location. You can explicitly opt-in to the feature using this
|
@@ -32,4 +36,7 @@ RSpec.configure do |config|
|
|
32
36
|
# # Equivalent to being in spec/controllers
|
33
37
|
# end
|
34
38
|
config.infer_spec_type_from_file_location!
|
39
|
+
|
40
|
+
config.include PresenterTestHelpers, type: :presenter
|
41
|
+
config.include ViewComponent::TestHelpers, type: :component
|
35
42
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PresenterTestHelpers
|
4
|
+
def controller
|
5
|
+
@controller ||= ViewComponent::Base.test_controller.constantize.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers)
|
6
|
+
end
|
7
|
+
|
8
|
+
def request
|
9
|
+
@request ||= ActionDispatch::TestRequest.create
|
10
|
+
end
|
11
|
+
end
|
@@ -27,7 +27,7 @@ class TestAppGenerator < Rails::Generators::Base
|
|
27
27
|
|
28
28
|
def inject_into_catalog_controller
|
29
29
|
inject_into_file 'app/controllers/catalog_controller.rb', after: /config.add_facet_field 'format'.*$/ do
|
30
|
-
"\n config.add_facet_field 'pub_date_si', label: 'Publication Date Sort',
|
30
|
+
"\n config.add_facet_field 'pub_date_si', label: 'Publication Date Sort', **default_range_config"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
metadata
CHANGED
@@ -1,30 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacklight_range_limit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.
|
4
|
+
version: 8.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Rochkind
|
8
8
|
- Chris Beer
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: blacklight
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 7.22.2
|
21
|
+
- - "<"
|
19
22
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
23
|
+
version: '9'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
|
-
- - "
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 7.22.2
|
31
|
+
- - "<"
|
26
32
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
33
|
+
version: '9'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
35
|
name: rspec
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,7 +171,7 @@ dependencies:
|
|
165
171
|
- - ">="
|
166
172
|
- !ruby/object:Gem::Version
|
167
173
|
version: '0'
|
168
|
-
description:
|
174
|
+
description:
|
169
175
|
email:
|
170
176
|
- blacklight-development@googlegroups.com
|
171
177
|
executables: []
|
@@ -188,31 +194,40 @@ files:
|
|
188
194
|
- app/assets/javascripts/blacklight_range_limit/range_limit_slider.js
|
189
195
|
- app/assets/stylesheets/blacklight_range_limit.css.scss
|
190
196
|
- app/assets/stylesheets/blacklight_range_limit/blacklight_range_limit.css
|
197
|
+
- app/components/blacklight_range_limit/range_facet_component.html.erb
|
198
|
+
- app/components/blacklight_range_limit/range_facet_component.rb
|
199
|
+
- app/components/blacklight_range_limit/range_form_component.html.erb
|
200
|
+
- app/components/blacklight_range_limit/range_form_component.rb
|
201
|
+
- app/components/blacklight_range_limit/range_segments_component.html.erb
|
202
|
+
- app/components/blacklight_range_limit/range_segments_component.rb
|
191
203
|
- app/helpers/range_limit_helper.rb
|
192
|
-
- app/
|
204
|
+
- app/presenters/blacklight_range_limit/facet_field_presenter.rb
|
205
|
+
- app/presenters/blacklight_range_limit/facet_item_presenter.rb
|
206
|
+
- app/presenters/blacklight_range_limit/filter_field.rb
|
193
207
|
- app/views/blacklight_range_limit/_range_segments.html.erb
|
194
|
-
- app/views/blacklight_range_limit/range_limit_panel.html.erb
|
195
208
|
- app/views/blacklight_range_limit/range_segments.html.erb
|
209
|
+
- app/views/catalog/range_limit_panel.html.erb
|
196
210
|
- blacklight_range_limit.gemspec
|
197
211
|
- config/jetty.yml
|
198
212
|
- config/locales/blacklight_range_limit.ar.yml
|
213
|
+
- config/locales/blacklight_range_limit.de.yml
|
199
214
|
- config/locales/blacklight_range_limit.en.yml
|
215
|
+
- config/locales/blacklight_range_limit.it.yml
|
200
216
|
- config/routes.rb
|
201
217
|
- config/solr.yml
|
202
218
|
- doc/example-screenshot.png
|
203
219
|
- lib/blacklight_range_limit.rb
|
204
220
|
- lib/blacklight_range_limit/controller_override.rb
|
205
221
|
- lib/blacklight_range_limit/engine.rb
|
222
|
+
- lib/blacklight_range_limit/facet_field_config_override.rb
|
206
223
|
- lib/blacklight_range_limit/range_limit_builder.rb
|
207
224
|
- lib/blacklight_range_limit/route_sets.rb
|
208
225
|
- lib/blacklight_range_limit/routes.rb
|
209
226
|
- lib/blacklight_range_limit/routes/range_searchable.rb
|
210
227
|
- lib/blacklight_range_limit/segment_calculation.rb
|
211
228
|
- lib/blacklight_range_limit/version.rb
|
212
|
-
- lib/blacklight_range_limit/view_helper_override.rb
|
213
229
|
- lib/generators/blacklight_range_limit/assets_generator.rb
|
214
230
|
- lib/generators/blacklight_range_limit/install_generator.rb
|
215
|
-
- lib/generators/blacklight_range_limit/templates/search_history_controller.rb
|
216
231
|
- lib/tasks/blacklight_range_limit.rake
|
217
232
|
- solr/conf/_rest_managed.json
|
218
233
|
- solr/conf/admin-extra.html
|
@@ -231,14 +246,18 @@ files:
|
|
231
246
|
- solr/conf/xslt/example_rss.xsl
|
232
247
|
- solr/conf/xslt/luke.xsl
|
233
248
|
- solr/sample_solr_documents.yml
|
249
|
+
- spec/components/range_facet_component_spec.rb
|
234
250
|
- spec/features/a_javascript_spec.rb
|
235
251
|
- spec/features/blacklight_range_limit_spec.rb
|
236
252
|
- spec/fixtures/solr_documents/unknown_year.yml
|
237
253
|
- spec/fixtures/solr_documents/zero_year.yml
|
238
254
|
- spec/helpers/blacklight_range_limit_helper_spec.rb
|
239
255
|
- spec/lib/blacklight_range_limit/segment_calculation_spec.rb
|
240
|
-
- spec/
|
256
|
+
- spec/presenters/facet_field_presenter_spec.rb
|
257
|
+
- spec/presenters/facet_item_presenter_spec.rb
|
258
|
+
- spec/presenters/filter_field_spec.rb
|
241
259
|
- spec/spec_helper.rb
|
260
|
+
- spec/support/presenter_test_helpers.rb
|
242
261
|
- spec/test_app_templates/Gemfile.extra
|
243
262
|
- spec/test_app_templates/lib/generators/test_app_generator.rb
|
244
263
|
- vendor/assets/javascripts/bootstrap-slider.js
|
@@ -257,7 +276,7 @@ homepage: https://github.com/projectblacklight/blacklight_range_limit
|
|
257
276
|
licenses:
|
258
277
|
- Apache 2.0
|
259
278
|
metadata: {}
|
260
|
-
post_install_message:
|
279
|
+
post_install_message:
|
261
280
|
rdoc_options: []
|
262
281
|
require_paths:
|
263
282
|
- lib
|
@@ -272,18 +291,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
291
|
- !ruby/object:Gem::Version
|
273
292
|
version: '0'
|
274
293
|
requirements: []
|
275
|
-
rubygems_version: 3.
|
276
|
-
signing_key:
|
294
|
+
rubygems_version: 3.2.32
|
295
|
+
signing_key:
|
277
296
|
specification_version: 4
|
278
297
|
summary: Blacklight Range Limit plugin
|
279
298
|
test_files:
|
299
|
+
- spec/components/range_facet_component_spec.rb
|
280
300
|
- spec/features/a_javascript_spec.rb
|
281
301
|
- spec/features/blacklight_range_limit_spec.rb
|
282
302
|
- spec/fixtures/solr_documents/unknown_year.yml
|
283
303
|
- spec/fixtures/solr_documents/zero_year.yml
|
284
304
|
- spec/helpers/blacklight_range_limit_helper_spec.rb
|
285
305
|
- spec/lib/blacklight_range_limit/segment_calculation_spec.rb
|
286
|
-
- spec/
|
306
|
+
- spec/presenters/facet_field_presenter_spec.rb
|
307
|
+
- spec/presenters/facet_item_presenter_spec.rb
|
308
|
+
- spec/presenters/filter_field_spec.rb
|
287
309
|
- spec/spec_helper.rb
|
310
|
+
- spec/support/presenter_test_helpers.rb
|
288
311
|
- spec/test_app_templates/Gemfile.extra
|
289
312
|
- spec/test_app_templates/lib/generators/test_app_generator.rb
|
@@ -1,90 +0,0 @@
|
|
1
|
-
<%- # requires solr_config local passed in
|
2
|
-
field_config = range_config(field_name)
|
3
|
-
label = facet_field_label(field_name)
|
4
|
-
|
5
|
-
input_label_range_begin = field_config[:input_label_range_begin] || t("blacklight.range_limit.range_begin", field_label: label)
|
6
|
-
input_label_range_end = field_config[:input_label_range_end] || t("blacklight.range_limit.range_end", field_label: label)
|
7
|
-
maxlength = field_config[:maxlength]
|
8
|
-
-%>
|
9
|
-
|
10
|
-
<div class="limit_content range_limit <%= field_name %>-config blrl-plot-config">
|
11
|
-
<% if has_selected_range_limit?(field_name) %>
|
12
|
-
<ul class="current list-unstyled facet-values">
|
13
|
-
<li class="selected">
|
14
|
-
<span class="facet-label">
|
15
|
-
<span class="selected"><%= range_display(field_name) %></span>
|
16
|
-
<%= link_to search_action_url(remove_range_param(field_name).except(:controller, :action)), :class=>"remove", :title => t('blacklight.range_limit.remove_limit') do %>
|
17
|
-
<span class="remove-icon">✖</span>
|
18
|
-
<span class="sr-only">[<%= t('blacklight.range_limit.remove_limit') %>]</span>
|
19
|
-
<% end %>
|
20
|
-
</span>
|
21
|
-
<span class="selected facet-count"><%= number_with_delimiter(@response.total) %></span>
|
22
|
-
</li>
|
23
|
-
</ul>
|
24
|
-
|
25
|
-
<% end %>
|
26
|
-
|
27
|
-
<!-- no results profile if missing is selected -->
|
28
|
-
<% unless selected_missing_for_range_limit?(field_name) %>
|
29
|
-
<!-- you can hide this if you want, but it has to be on page if you want
|
30
|
-
JS slider and calculated facets to show up, JS sniffs it. -->
|
31
|
-
<div class="profile">
|
32
|
-
<% if stats_for_field?(field_name) %>
|
33
|
-
<!-- No stats information found for field in search response -->
|
34
|
-
<% end %>
|
35
|
-
|
36
|
-
<% if (min = range_results_endpoint(field_name, :min)) &&
|
37
|
-
(max = range_results_endpoint(field_name, :max)) %>
|
38
|
-
|
39
|
-
<% if field_config[:segments] != false %>
|
40
|
-
<div class="distribution subsection <%= 'chart_js' unless field_config[:chart_js] == false %>">
|
41
|
-
<!-- if we already fetched segments from solr, display them
|
42
|
-
here. Otherwise, display a link to fetch them, which JS
|
43
|
-
will AJAX fetch. -->
|
44
|
-
<% if solr_range_queries_to_a(field_name).length > 0 %>
|
45
|
-
|
46
|
-
<%= render(:partial => "blacklight_range_limit/range_segments", :locals => {:solr_field => field_name}) %>
|
47
|
-
|
48
|
-
<% else %>
|
49
|
-
<%= link_to(t('blacklight.range_limit.view_distribution'), range_limit_url(range_field: field_name, range_start: min, range_end: max), :class => "load_distribution") %>
|
50
|
-
<% end %>
|
51
|
-
</div>
|
52
|
-
<% end %>
|
53
|
-
<p class="range subsection <%= "slider_js" unless field_config[:slider_js] == false %>">
|
54
|
-
<%= t('blacklight.range_limit.results_range_html', min: range_results_endpoint(field_name, :min), max: range_results_endpoint(field_name, :max)) %>
|
55
|
-
</p>
|
56
|
-
<% end %>
|
57
|
-
</div>
|
58
|
-
|
59
|
-
<%= form_tag search_action_path, :method => :get, class: [BlacklightRangeLimit.classes[:form], "range_#{field_name} d-flex justify-content-center"].join(' ') do %>
|
60
|
-
<%= render_hash_as_hidden_fields(search_state.params_for_search.except(:page)) %>
|
61
|
-
<div class="input-group input-group-sm mb-3 flex-nowrap range-limit-input-group">
|
62
|
-
<%= render_range_input(field_name, :begin, input_label_range_begin, maxlength) %>
|
63
|
-
<%= render_range_input(field_name, :end, input_label_range_end, maxlength) %>
|
64
|
-
<div class="input-group-append">
|
65
|
-
<%= submit_tag t('blacklight.range_limit.submit_limit'), class: BlacklightRangeLimit.classes[:submit] %>
|
66
|
-
</div>
|
67
|
-
</div>
|
68
|
-
<% end %>
|
69
|
-
|
70
|
-
<%= link_to t('blacklight.range_limit.view_larger', field_name: label),
|
71
|
-
range_limit_panel_url(id: field_name, range_start: 0, range_end: 2019),
|
72
|
-
class: 'view_larger mt-1',
|
73
|
-
data: { blacklight_modal: 'trigger' } %>
|
74
|
-
|
75
|
-
<% unless request.xhr? %>
|
76
|
-
<% if (stats = stats_for_field(field_name)) && stats["missing"] > 0 %>
|
77
|
-
<ul class="missing list-unstyled facet-values subsection">
|
78
|
-
<li>
|
79
|
-
<span class="facet-label">
|
80
|
-
<%= link_to t('blacklight.range_limit.missing'), search_action_url(add_range_missing(field_name).except(:controller, :action)) %>
|
81
|
-
</span>
|
82
|
-
<%# note important there be no whitespace inside facet-count to avoid
|
83
|
-
bug in some versions of Blacklight (including 7.1.0.alpha) %>
|
84
|
-
<span class="facet-count"><%= number_with_delimiter(stats["missing"]) %></span>
|
85
|
-
</li>
|
86
|
-
</ul>
|
87
|
-
<% end %>
|
88
|
-
<% end %>
|
89
|
-
<% end %>
|
90
|
-
</div>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<div class="modal-header">
|
2
|
-
<h1 class="modal-title"><%= facet_field_label(@facet.key) %></h1>
|
3
|
-
<button type="button" class="blacklight-modal-close close" data-dismiss="modal" aria-label="<%= t('blacklight.modal.close') %>">
|
4
|
-
<span aria-hidden="true">×</span>
|
5
|
-
</button>
|
6
|
-
</div>
|
7
|
-
|
8
|
-
<div class="modal-body">
|
9
|
-
<%= render :partial => "blacklight_range_limit/range_limit_panel", :locals => {field_name: @facet.key} %>
|
10
|
-
</div>
|
@@ -1,100 +0,0 @@
|
|
1
|
-
# Meant to be applied on top of Blacklight helpers, to over-ride
|
2
|
-
# Will add rendering of limit itself in sidebar, and of constraings
|
3
|
-
# display.
|
4
|
-
module BlacklightRangeLimit::ViewHelperOverride
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def facet_partial_name(display_facet)
|
9
|
-
config = range_config(display_facet.name)
|
10
|
-
return config[:partial] || 'blacklight_range_limit/range_limit_panel' if config && should_show_limit(display_facet.name)
|
11
|
-
super
|
12
|
-
end
|
13
|
-
|
14
|
-
def query_has_constraints?(my_params = params)
|
15
|
-
super || has_range_limit_parameters?(my_params)
|
16
|
-
end
|
17
|
-
|
18
|
-
# Over-ride to recognize our custom params for range facets
|
19
|
-
def facet_field_in_params?(field_name)
|
20
|
-
return super || (
|
21
|
-
range_config(field_name) &&
|
22
|
-
params[:range] &&
|
23
|
-
params[:range][field_name] &&
|
24
|
-
( params[:range][field_name]["begin"].present? ||
|
25
|
-
params[:range][field_name]["end"].present? ||
|
26
|
-
params[:range][field_name]["missing"].present?
|
27
|
-
)
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
def render_constraints_filters(my_params = params)
|
32
|
-
# add a constraint for ranges?
|
33
|
-
range_params(my_params).keys.each_with_object(super) do |solr_field, content|
|
34
|
-
content << render_constraint_element(
|
35
|
-
facet_field_label(solr_field),
|
36
|
-
range_display(solr_field, my_params),
|
37
|
-
escape_value: false,
|
38
|
-
remove: search_action_path(remove_range_param(solr_field, my_params))
|
39
|
-
)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def render_search_to_s_filters(my_params)
|
44
|
-
# add a constraint for ranges?
|
45
|
-
range_params(my_params).keys.each_with_object(super) do |solr_field, content|
|
46
|
-
content << render_search_to_s_element(
|
47
|
-
facet_field_label(solr_field),
|
48
|
-
range_display(solr_field, my_params),
|
49
|
-
escape_value: false
|
50
|
-
)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def remove_range_param(solr_field, my_params = params)
|
55
|
-
my_params = Blacklight::SearchState.new(my_params, blacklight_config).to_h
|
56
|
-
if ( my_params["range"] )
|
57
|
-
my_params = my_params.dup
|
58
|
-
my_params["range"] = my_params["range"].dup
|
59
|
-
my_params["range"].delete(solr_field)
|
60
|
-
end
|
61
|
-
return my_params
|
62
|
-
end
|
63
|
-
|
64
|
-
# Looks in the solr @response for ["facet_counts"]["facet_queries"][solr_field], for elements
|
65
|
-
# expressed as "solr_field:[X to Y]", turns them into
|
66
|
-
# a list of hashes with [:from, :to, :count], sorted by
|
67
|
-
# :from. Assumes integers for sorting purposes.
|
68
|
-
def solr_range_queries_to_a(solr_field)
|
69
|
-
return [] unless @response["facet_counts"] && @response["facet_counts"]["facet_queries"]
|
70
|
-
|
71
|
-
array = []
|
72
|
-
|
73
|
-
@response["facet_counts"]["facet_queries"].each_pair do |query, count|
|
74
|
-
if query =~ /#{solr_field}: *\[ *(-?\d+) *TO *(-?\d+) *\]/
|
75
|
-
array << {:from => $1, :to => $2, :count => count}
|
76
|
-
end
|
77
|
-
end
|
78
|
-
array = array.sort_by {|hash| hash[:from].to_i }
|
79
|
-
|
80
|
-
return array
|
81
|
-
end
|
82
|
-
|
83
|
-
def range_config(solr_field)
|
84
|
-
BlacklightRangeLimit.range_config(blacklight_config, solr_field)
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
def range_params(my_params = params)
|
90
|
-
return {} unless my_params[:range].is_a?(ActionController::Parameters) || my_params[:range].is_a?(Hash)
|
91
|
-
|
92
|
-
my_params[:range].select do |_solr_field, range_options|
|
93
|
-
next unless range_options
|
94
|
-
|
95
|
-
[range_options['missing'].presence,
|
96
|
-
range_options['begin'].presence,
|
97
|
-
range_options['end'].presence].any?
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe BlacklightRangeLimit::ViewHelperOverride, type: :helper do
|
4
|
-
describe '#render_constraints_filters' do
|
5
|
-
before do
|
6
|
-
allow(helper).to receive_messages(
|
7
|
-
facet_field_label: 'Date Range',
|
8
|
-
remove_range_param: {},
|
9
|
-
search_action_path: '/catalog',
|
10
|
-
blacklight_config: CatalogController.blacklight_config,
|
11
|
-
search_state: {},
|
12
|
-
)
|
13
|
-
allow(controller).to receive_messages(
|
14
|
-
search_state_class: Blacklight::SearchState,
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'does not return any content when the range parameter invalid' do
|
19
|
-
params = ActionController::Parameters.new(range: 'garbage')
|
20
|
-
|
21
|
-
expect(helper.render_constraints_filters(params)).to eq ''
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'renders a constraint for the given data in the range param' do
|
25
|
-
params = ActionController::Parameters.new(
|
26
|
-
range: { range_field: { 'begin' => 1900, 'end' => 2000 } }
|
27
|
-
)
|
28
|
-
constraints = helper.render_constraints_filters(params)
|
29
|
-
|
30
|
-
expect(constraints).to have_css(
|
31
|
-
'.constraint .filter-name', text: 'Date Range'
|
32
|
-
)
|
33
|
-
expect(constraints).to have_css(
|
34
|
-
'.constraint .filter-value', text: '1900 to 2000'
|
35
|
-
)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'render_search_to_s_filters' do
|
40
|
-
before do
|
41
|
-
allow(helper).to receive_messages(
|
42
|
-
facet_field_label: 'Date Range',
|
43
|
-
blacklight_config: CatalogController.blacklight_config,
|
44
|
-
search_state: {},
|
45
|
-
)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'does not return any content when the range parameter invalid' do
|
49
|
-
params = ActionController::Parameters.new(range: 'garbage')
|
50
|
-
|
51
|
-
expect(helper.render_search_to_s_filters(params)).to eq ''
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'renders a constraint for the given data in the range param' do
|
55
|
-
params = ActionController::Parameters.new(
|
56
|
-
range: { range_field: { 'begin' => 1900, 'end' => 2000 } }
|
57
|
-
)
|
58
|
-
constraints = helper.render_search_to_s_filters(params)
|
59
|
-
|
60
|
-
expect(constraints).to have_css(
|
61
|
-
'.constraint .filter-name', text: 'Date Range:'
|
62
|
-
)
|
63
|
-
expect(constraints).to have_css(
|
64
|
-
'.constraint .filter-values', text: '1900 to 2000'
|
65
|
-
)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '#range_params' do
|
70
|
-
it 'handles no range input' do
|
71
|
-
expect(
|
72
|
-
helper.send(:range_params, ActionController::Parameters.new(q: 'blah'))
|
73
|
-
).to eq({})
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'handles non-compliant range input' do
|
77
|
-
expect(
|
78
|
-
helper.send(:range_params, ActionController::Parameters.new(range: 'blah'))
|
79
|
-
).to eq({})
|
80
|
-
|
81
|
-
expect(
|
82
|
-
helper.send(:range_params, ActionController::Parameters.new(range: ['blah']))
|
83
|
-
).to eq({})
|
84
|
-
|
85
|
-
expect(
|
86
|
-
helper.send(:range_params, ActionController::Parameters.new(range: { 'wrong' => 'data' }))
|
87
|
-
).to eq({})
|
88
|
-
|
89
|
-
expect(
|
90
|
-
helper.send(
|
91
|
-
:range_params,
|
92
|
-
ActionController::Parameters.new(range: { field_name: { 'wrong' => 'data' } })
|
93
|
-
)
|
94
|
-
).to eq({})
|
95
|
-
|
96
|
-
expect(
|
97
|
-
helper.send(
|
98
|
-
:range_params,
|
99
|
-
ActionController::Parameters.new(range: { field_name: { 'begin' => '', 'end' => '' } })
|
100
|
-
)
|
101
|
-
).to eq({})
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'returns the range parameters that are present' do
|
105
|
-
expect(
|
106
|
-
helper.send(
|
107
|
-
:range_params,
|
108
|
-
ActionController::Parameters.new(range: { field_name: { 'missing' => true } })
|
109
|
-
).permit!.to_h
|
110
|
-
).to eq({ 'field_name' => { 'missing' => true } })
|
111
|
-
|
112
|
-
expect(
|
113
|
-
helper.send(
|
114
|
-
:range_params,
|
115
|
-
ActionController::Parameters.new(range: { field_name: { 'begin' => '1800', 'end' => '1900' } })
|
116
|
-
).permit!.to_h
|
117
|
-
).to eq({ 'field_name' => { 'begin' => '1800', 'end' => '1900' } })
|
118
|
-
|
119
|
-
expect(
|
120
|
-
helper.send(
|
121
|
-
:range_params,
|
122
|
-
ActionController::Parameters.new(
|
123
|
-
range: {
|
124
|
-
field_name: { 'begin' => '1800', 'end' => '1900' },
|
125
|
-
field_name2: { 'begin' => '1800', 'end' => '1900' }
|
126
|
-
}
|
127
|
-
)
|
128
|
-
).permit!.to_h
|
129
|
-
).to eq(
|
130
|
-
{
|
131
|
-
'field_name' => { 'begin' => '1800', 'end' => '1900' },
|
132
|
-
'field_name2' => { 'begin' => '1800', 'end' => '1900' }
|
133
|
-
}
|
134
|
-
)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|