blacklight_range_limit 6.1.2 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/views/blacklight_range_limit/_range_limit_panel.html.erb +2 -2
- data/blacklight_range_limit.gemspec +2 -2
- data/lib/blacklight_range_limit.rb +12 -5
- data/lib/blacklight_range_limit/engine.rb +4 -0
- data/lib/blacklight_range_limit/segment_calculation.rb +34 -31
- data/lib/blacklight_range_limit/view_helper_override.rb +11 -12
- data/spec/lib/blacklight_range_limit/segment_calculation_spec.rb +49 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb869c85a59ab43a06d60fcbe6515595c68ef57c
|
4
|
+
data.tar.gz: 32b3de05633cd25ca26465840e1d50afe7bceeaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4209b4107bfc5c05794aa238f7fe17020f98cd2f4a91a3a242a6884eb1305fc7f6bc4175f1196a6e28632d8b682123b77123f5a9e3523c86d4acb9ddb0133a8
|
7
|
+
data.tar.gz: d85a7d7ff3057d76355e8417d417f2e23b50f274caad3e06d75e679f990b9928dc20570ce5fcff5ace4b907740ed9fadaa58bcc56ed6222c3b4bddfdd5d6774a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
6.
|
1
|
+
6.2.0
|
@@ -29,7 +29,7 @@
|
|
29
29
|
<% end %>
|
30
30
|
|
31
31
|
<% unless params["range"] && params["range"][solr_field] && params["range"][solr_field]["missing"] %>
|
32
|
-
<%= form_tag search_action_path, :method => :get, :
|
32
|
+
<%= form_tag search_action_path, :method => :get, class: [BlacklightRangeLimit.classes[:form], "range_#{solr_field}"].join(' ') do %>
|
33
33
|
<%= render_hash_as_hidden_fields(search_state.params_for_search) %>
|
34
34
|
|
35
35
|
<!-- we need to include a dummy search_field parameter if none exists,
|
@@ -40,7 +40,7 @@
|
|
40
40
|
<% end %>
|
41
41
|
|
42
42
|
<%= render_range_input(solr_field, :begin, input_label_range_begin, maxlength) %> – <%= render_range_input(solr_field, :end, input_label_range_end, maxlength) %>
|
43
|
-
<%= submit_tag t('blacklight.range_limit.submit_limit'), :
|
43
|
+
<%= submit_tag t('blacklight.range_limit.submit_limit'), class: BlacklightRangeLimit.classes[:submit] %>
|
44
44
|
|
45
45
|
<% end %>
|
46
46
|
<% end %>
|
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
s.add_dependency 'rails', '>= 3.0'
|
21
21
|
s.add_dependency 'jquery-rails' # our JS needs jquery_rails
|
22
|
-
s.add_dependency 'blacklight', '
|
23
|
-
|
22
|
+
s.add_dependency 'blacklight', '>= 6.0.2'
|
23
|
+
|
24
24
|
s.add_development_dependency 'rspec', '~> 3.0'
|
25
25
|
s.add_development_dependency 'rspec-rails'
|
26
26
|
s.add_development_dependency 'capybara'
|
@@ -10,11 +10,18 @@ module BlacklightRangeLimit
|
|
10
10
|
|
11
11
|
autoload :Routes, 'blacklight_range_limit/routes'
|
12
12
|
|
13
|
-
|
13
|
+
# Raised when an invalid range is encountered
|
14
|
+
class InvalidRange < TypeError; end
|
15
|
+
|
16
|
+
mattr_accessor :labels, :classes
|
14
17
|
self.labels = {
|
15
18
|
:missing => "Unknown"
|
16
19
|
}
|
17
|
-
|
20
|
+
self.classes = {
|
21
|
+
form: 'range_limit subsection form-inline',
|
22
|
+
submit: 'submit btn btn-default'
|
23
|
+
}
|
24
|
+
|
18
25
|
# Add element to array only if it's not already there
|
19
26
|
def self.safe_arr_add(array, element)
|
20
27
|
array << element unless array.include?(element)
|
@@ -22,11 +29,11 @@ module BlacklightRangeLimit
|
|
22
29
|
|
23
30
|
# Convenience method for returning range config hash from
|
24
31
|
# blacklight config, for a specific solr field, in a normalized
|
25
|
-
# way.
|
32
|
+
# way.
|
26
33
|
#
|
27
|
-
# Returns false if range limiting not configured.
|
34
|
+
# Returns false if range limiting not configured.
|
28
35
|
# Returns hash even if configured to 'true'
|
29
|
-
# for consistency.
|
36
|
+
# for consistency.
|
30
37
|
def self.range_config(blacklight_config, solr_field)
|
31
38
|
field = blacklight_config.facet_fields[solr_field.to_s]
|
32
39
|
|
@@ -9,5 +9,9 @@ module BlacklightRangeLimit
|
|
9
9
|
initializer "blacklight_range_limit.assets", :after => "assets" do
|
10
10
|
Rails.application.config.assets.precompile += %w( flot/excanvas.min.js )
|
11
11
|
end
|
12
|
+
|
13
|
+
config.action_dispatch.rescue_responses.merge!(
|
14
|
+
"BlacklightRangeLimit::InvalidRange" => :not_acceptable
|
15
|
+
)
|
12
16
|
end
|
13
17
|
end
|
@@ -3,32 +3,34 @@ module BlacklightRangeLimit
|
|
3
3
|
module SegmentCalculation
|
4
4
|
|
5
5
|
protected
|
6
|
-
|
6
|
+
|
7
7
|
# Calculates segment facets within a given start and end on a given
|
8
8
|
# field, returns request params to be added on to what's sent to
|
9
9
|
# solr to get the calculated facet segments.
|
10
10
|
# Assumes solr_field is an integer, as range endpoint will be found
|
11
11
|
# by subtracting one from subsequent boundary.
|
12
12
|
#
|
13
|
-
# Changes solr_params passed in.
|
13
|
+
# Changes solr_params passed in.
|
14
14
|
def add_range_segments_to_solr!(solr_params, solr_field, min, max)
|
15
|
-
|
16
|
-
|
15
|
+
raise InvalidRange, "The min date must be before the max date" if min > max
|
16
|
+
|
17
|
+
field_config = BlacklightRangeLimit.range_config(blacklight_config, solr_field)
|
18
|
+
|
17
19
|
solr_params[:"facet.query"] ||= []
|
18
|
-
|
19
|
-
boundaries = boundaries_for_range_facets(min, max, (field_config[:num_segments] || 10) )
|
20
|
-
|
20
|
+
|
21
|
+
boundaries = boundaries_for_range_facets(min, max, (field_config[:num_segments] || 10) )
|
22
|
+
|
21
23
|
# Now make the boundaries into actual filter.queries.
|
22
24
|
0.upto(boundaries.length - 2) do |index|
|
23
25
|
first = boundaries[index]
|
24
26
|
last = boundaries[index+1].to_i - 1
|
25
|
-
|
27
|
+
|
26
28
|
solr_params[:"facet.query"] << "#{solr_field}:[#{first} TO #{last}]"
|
27
29
|
end
|
28
|
-
|
30
|
+
|
29
31
|
return solr_params
|
30
32
|
end
|
31
|
-
|
33
|
+
|
32
34
|
# returns an array of 'boundaries' for producing approx num_div
|
33
35
|
# segments between first and last. The boundaries are 'nicefied'
|
34
36
|
# to factors of 5 or 10, so exact number of segments may be more
|
@@ -36,70 +38,71 @@ module BlacklightRangeLimit
|
|
36
38
|
#
|
37
39
|
# Because of arithmetic issues with creating boundaries that will
|
38
40
|
# be turned into inclusive ranges, the FINAL boundary will be one
|
39
|
-
# unit more than the actual end of the last range later computed.
|
40
|
-
def boundaries_for_range_facets(first, last, num_div)
|
41
|
+
# unit more than the actual end of the last range later computed.
|
42
|
+
def boundaries_for_range_facets(first, last, num_div)
|
43
|
+
raise ArgumentError, "The first date must be before the last date" if last < first
|
41
44
|
# arithmetic issues require last to be one more than the actual
|
42
45
|
# last value included in our inclusive range
|
43
46
|
last += 1
|
44
|
-
|
47
|
+
|
45
48
|
# code cribbed from Flot auto tick calculating, but leaving out
|
46
|
-
# some of Flot's options becuase it started to get confusing.
|
49
|
+
# some of Flot's options becuase it started to get confusing.
|
47
50
|
delta = (last - first).to_f / num_div
|
48
|
-
|
51
|
+
|
49
52
|
# Don't know what most of these variables mean, just copying
|
50
|
-
# from Flot.
|
53
|
+
# from Flot.
|
51
54
|
dec = -1 * ( Math.log10(delta) ).floor
|
52
55
|
magn = (10 ** (-1 * dec)).to_f
|
53
56
|
norm = (magn == 0) ? delta : (delta / magn) # norm is between 1.0 and 10.0
|
54
|
-
|
57
|
+
|
55
58
|
size = 10
|
56
59
|
if (norm < 1.5)
|
57
60
|
size = 1
|
58
61
|
elsif (norm < 3)
|
59
62
|
size = 2;
|
60
63
|
# special case for 2.5, requires an extra decimal
|
61
|
-
if (norm > 2.25 )
|
64
|
+
if (norm > 2.25 )
|
62
65
|
size = 2.5;
|
63
66
|
dec = dec + 1
|
64
|
-
end
|
67
|
+
end
|
65
68
|
elsif (norm < 7.5)
|
66
69
|
size = 5
|
67
70
|
end
|
68
|
-
|
71
|
+
|
69
72
|
size = size * magn
|
70
|
-
|
71
|
-
boundaries = []
|
72
|
-
|
73
|
+
|
74
|
+
boundaries = []
|
75
|
+
|
73
76
|
start = floorInBase(first, size)
|
74
77
|
i = 0
|
75
78
|
v = Float::MAX
|
76
79
|
prev = nil
|
77
|
-
begin
|
80
|
+
begin
|
78
81
|
prev = v
|
79
82
|
v = start + i * size
|
80
83
|
boundaries.push(v.to_i)
|
81
84
|
i += 1
|
82
85
|
end while ( v < last && v != prev)
|
83
|
-
|
86
|
+
|
84
87
|
# Can create dups for small ranges, tighten up
|
85
88
|
boundaries.uniq!
|
86
|
-
|
89
|
+
|
87
90
|
# That algorithm i don't entirely understand will sometimes
|
88
91
|
# extend past our first and last, tighten it up and make sure
|
89
|
-
# first and last are endpoints.
|
92
|
+
# first and last are endpoints.
|
90
93
|
boundaries.delete_if {|b| b <= first || b >= last}
|
91
94
|
boundaries.unshift(first)
|
92
95
|
boundaries.push(last)
|
93
|
-
|
96
|
+
|
94
97
|
return boundaries
|
95
98
|
end
|
96
|
-
|
99
|
+
|
97
100
|
# Cribbed from Flot. Round to nearby lower multiple of base
|
98
|
-
def floorInBase(n, base)
|
101
|
+
def floorInBase(n, base)
|
99
102
|
return base * (n / base).floor
|
100
103
|
end
|
101
104
|
|
102
105
|
|
103
|
-
|
106
|
+
|
104
107
|
end
|
105
108
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# Meant to be applied on top of Blacklight helpers, to over-ride
|
2
2
|
# Will add rendering of limit itself in sidebar, and of constraings
|
3
|
-
# display.
|
3
|
+
# display.
|
4
4
|
module BlacklightRangeLimit::ViewHelperOverride
|
5
5
|
|
6
6
|
|
7
|
-
|
7
|
+
|
8
8
|
def facet_partial_name(display_facet)
|
9
9
|
return "blacklight_range_limit/range_limit_panel" if range_config(display_facet.name) and should_show_limit(display_facet.name)
|
10
10
|
super
|
@@ -12,8 +12,8 @@
|
|
12
12
|
|
13
13
|
def has_range_limit_parameters?(my_params = params)
|
14
14
|
my_params[:range] &&
|
15
|
-
my_params[:range].any? do |key, v|
|
16
|
-
v.present? && v.respond_to?(:'[]') &&
|
15
|
+
my_params[:range].to_unsafe_h.any? do |key, v|
|
16
|
+
v.present? && v.respond_to?(:'[]') &&
|
17
17
|
(v["begin"].present? || v["end"].present? || v["missing"].present?)
|
18
18
|
end
|
19
19
|
end
|
@@ -52,7 +52,7 @@
|
|
52
52
|
range_display(solr_field, my_params),
|
53
53
|
:escape_value => false,
|
54
54
|
:remove => remove_range_param(solr_field, my_params)
|
55
|
-
)
|
55
|
+
)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
return content
|
@@ -63,14 +63,14 @@
|
|
63
63
|
# add a constraint for ranges?
|
64
64
|
unless my_params[:range].blank?
|
65
65
|
my_params[:range].each_pair do |solr_field, hash|
|
66
|
-
next unless hash["missing"] || (!hash["begin"].blank?) || (! hash["end"].blank?)
|
67
|
-
|
66
|
+
next unless hash["missing"] || (!hash["begin"].blank?) || (! hash["end"].blank?)
|
67
|
+
|
68
68
|
content << render_search_to_s_element(
|
69
69
|
facet_field_label(solr_field),
|
70
70
|
range_display(solr_field, my_params),
|
71
71
|
:escape_value => false
|
72
|
-
)
|
73
|
-
|
72
|
+
)
|
73
|
+
|
74
74
|
end
|
75
75
|
end
|
76
76
|
return content
|
@@ -89,7 +89,7 @@
|
|
89
89
|
# Looks in the solr @response for ["facet_counts"]["facet_queries"][solr_field], for elements
|
90
90
|
# expressed as "solr_field:[X to Y]", turns them into
|
91
91
|
# a list of hashes with [:from, :to, :count], sorted by
|
92
|
-
# :from. Assumes integers for sorting purposes.
|
92
|
+
# :from. Assumes integers for sorting purposes.
|
93
93
|
def solr_range_queries_to_a(solr_field)
|
94
94
|
return [] unless @response["facet_counts"] && @response["facet_counts"]["facet_queries"]
|
95
95
|
|
@@ -108,6 +108,5 @@
|
|
108
108
|
def range_config(solr_field)
|
109
109
|
BlacklightRangeLimit.range_config(blacklight_config, solr_field)
|
110
110
|
end
|
111
|
-
|
112
|
-
end
|
113
111
|
|
112
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe BlacklightRangeLimit::SegmentCalculation do
|
4
|
+
let(:dummy_class) do
|
5
|
+
Class.new do
|
6
|
+
include BlacklightRangeLimit::SegmentCalculation
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#boundaries_for_range_facets' do
|
11
|
+
subject { dummy_class.new.send(:boundaries_for_range_facets, first, last, num_div) }
|
12
|
+
|
13
|
+
context "the happy path" do
|
14
|
+
let(:first) { 1000 }
|
15
|
+
let(:last) { 2008 }
|
16
|
+
let(:num_div) { 10 }
|
17
|
+
|
18
|
+
it { is_expected.to eq [1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2009] }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when the last is before the first' do
|
22
|
+
let(:first) { 1000 }
|
23
|
+
let(:last) { 800 }
|
24
|
+
let(:num_div) { 3 }
|
25
|
+
|
26
|
+
it 'raises and error' do
|
27
|
+
expect { subject }.to raise_error ArgumentError,
|
28
|
+
'The first date must be before the last date'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#add_range_segments_to_solr!" do
|
34
|
+
subject { dummy_class.new.send(:add_range_segments_to_solr!, solr_params, solr_field, min, max) }
|
35
|
+
|
36
|
+
let(:solr_params) { {} }
|
37
|
+
let(:solr_field) { 'date_dt' }
|
38
|
+
|
39
|
+
context 'when the last is before the first' do
|
40
|
+
let(:min) { 1000 }
|
41
|
+
let(:max) { 800 }
|
42
|
+
|
43
|
+
it 'raises an error' do
|
44
|
+
expect { subject }.to raise_error BlacklightRangeLimit::InvalidRange,
|
45
|
+
'The min date must be before the max date'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacklight_range_limit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Rochkind
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -43,16 +43,16 @@ dependencies:
|
|
43
43
|
name: blacklight
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
48
|
+
version: 6.0.2
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: 6.0.2
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -217,6 +217,7 @@ files:
|
|
217
217
|
- spec/features/blacklight_range_limit_spec.rb
|
218
218
|
- spec/fixtures/solr_documents/zero_year.yml
|
219
219
|
- spec/helpers/blacklight_range_limit_helper_spec.rb
|
220
|
+
- spec/lib/blacklight_range_limit/segment_calculation_spec.rb
|
220
221
|
- spec/spec_helper.rb
|
221
222
|
- spec/test_app_templates/lib/generators/test_app_generator.rb
|
222
223
|
- vendor/assets/javascripts/bootstrap-slider.js
|
@@ -252,5 +253,6 @@ test_files:
|
|
252
253
|
- spec/features/blacklight_range_limit_spec.rb
|
253
254
|
- spec/fixtures/solr_documents/zero_year.yml
|
254
255
|
- spec/helpers/blacklight_range_limit_helper_spec.rb
|
256
|
+
- spec/lib/blacklight_range_limit/segment_calculation_spec.rb
|
255
257
|
- spec/spec_helper.rb
|
256
258
|
- spec/test_app_templates/lib/generators/test_app_generator.rb
|