blacklight_range_limit 8.1.0 → 8.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +14 -46
  3. data/README.md +4 -4
  4. data/VERSION +1 -1
  5. data/app/assets/javascripts/blacklight_range_limit/range_limit_distro_facets.js +1 -1
  6. data/app/assets/javascripts/blacklight_range_limit/range_limit_plotting.js +27 -15
  7. data/app/assets/javascripts/blacklight_range_limit/range_limit_slider.js +29 -9
  8. data/app/components/blacklight_range_limit/range_facet_component.html.erb +48 -0
  9. data/app/components/blacklight_range_limit/range_facet_component.rb +29 -0
  10. data/app/components/blacklight_range_limit/range_form_component.html.erb +12 -0
  11. data/app/components/blacklight_range_limit/range_form_component.rb +46 -0
  12. data/app/components/blacklight_range_limit/range_segments_component.html.erb +3 -0
  13. data/app/components/blacklight_range_limit/range_segments_component.rb +26 -0
  14. data/app/helpers/range_limit_helper.rb +70 -79
  15. data/app/presenters/blacklight_range_limit/facet_field_presenter.rb +85 -0
  16. data/app/presenters/blacklight_range_limit/facet_item_presenter.rb +45 -0
  17. data/app/presenters/blacklight_range_limit/filter_field.rb +85 -0
  18. data/app/views/blacklight_range_limit/_range_segments.html.erb +7 -21
  19. data/app/views/blacklight_range_limit/range_segments.html.erb +1 -1
  20. data/app/views/catalog/range_limit_panel.html.erb +1 -0
  21. data/blacklight_range_limit.gemspec +1 -1
  22. data/config/locales/blacklight_range_limit.de.yml +13 -0
  23. data/config/locales/blacklight_range_limit.it.yml +13 -0
  24. data/lib/blacklight_range_limit/controller_override.rb +41 -24
  25. data/lib/blacklight_range_limit/engine.rb +4 -0
  26. data/lib/blacklight_range_limit/facet_field_config_override.rb +25 -0
  27. data/lib/blacklight_range_limit/range_limit_builder.rb +15 -39
  28. data/lib/blacklight_range_limit/segment_calculation.rb +2 -2
  29. data/lib/blacklight_range_limit.rb +31 -12
  30. data/lib/generators/blacklight_range_limit/install_generator.rb +3 -17
  31. data/solr/conf/schema.xml +0 -13
  32. data/solr/conf/solrconfig.xml +1 -0
  33. data/spec/components/range_facet_component_spec.rb +111 -0
  34. data/spec/features/a_javascript_spec.rb +4 -4
  35. data/spec/features/blacklight_range_limit_spec.rb +7 -6
  36. data/spec/helpers/blacklight_range_limit_helper_spec.rb +7 -7
  37. data/spec/presenters/facet_field_presenter_spec.rb +144 -0
  38. data/spec/presenters/facet_item_presenter_spec.rb +47 -0
  39. data/spec/presenters/filter_field_spec.rb +70 -0
  40. data/spec/spec_helper.rb +7 -0
  41. data/spec/support/presenter_test_helpers.rb +11 -0
  42. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
  43. metadata +40 -17
  44. data/app/views/blacklight_range_limit/_range_limit_panel.html.erb +0 -90
  45. data/app/views/blacklight_range_limit/range_limit_panel.html.erb +0 -10
  46. data/lib/blacklight_range_limit/view_helper_override.rb +0 -100
  47. data/lib/generators/blacklight_range_limit/templates/search_history_controller.rb +0 -7
  48. data/spec/lib/blacklight_range_limit/view_helper_override_helper_spec.rb +0 -137
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dfdb61da699ad394376b877e63199d1cb10f5545208ed347e26e7e4f8365fc6
4
- data.tar.gz: a61b1886322ead30ef33d6520201473fa271691ddcbc8940ffc738feeef32e21
3
+ metadata.gz: '00179d23555229bb58884ff2625e599307bbda4404fe0ebab00fa460a95b0e58'
4
+ data.tar.gz: 742c87c6be6c52491abda708761027e68986bb0cf7ae1c95cff2605f779e5fd0
5
5
  SHA512:
6
- metadata.gz: bb77af5e998bcd4b5b9abdddd5ab19c97086616ac6d08fff5314a818cea40d12bb496a39edd1f00ef643b818360749c65c2e74edfab1d54204a10fb8ce1002a3
7
- data.tar.gz: 7455bda6064549df976002a07e306bb87e8d462b03aa4cdd5e2504f10540cbe8efd29f55e9746bc595d9f943a7e07bce50dd428d36799e13f218a0abf98c6417
6
+ metadata.gz: 668f99b158ff431e50e484d851f59d24aa55580699b7e1e2338d326d9346b59a29ac4d9031cf8d61d5e28a4aa0629b6776c6da40f553791a13cf165eb03afbc7
7
+ data.tar.gz: ed441dacce85f39b0b7ecffecf0afdd14d1174eb8f5d5ab1e7a3832002e5bd3c46d9753779b0b1119e79d916633590f9228672694e1a821c0409cb35de699983
@@ -16,61 +16,29 @@ on:
16
16
  jobs:
17
17
  test:
18
18
  runs-on: ubuntu-latest
19
+ name: test (ruby ${{ matrix.ruby }} / rails ${{ matrix.rails_version }})
19
20
  strategy:
20
21
  matrix:
21
- rails_version: [6.1.1]
22
- ruby: [2.7, 3.0]
22
+ ruby: [2.7, '3.0']
23
+ rails_version: ['6.1.5', '7.0.2.3']
24
+ additional_engine_cart_rails_options: ['']
25
+ include:
26
+ - ruby: '2.7'
27
+ rails_version: '5.2.4.2'
28
+ - ruby: '3.1'
29
+ rails_version: '7.0.2.3'
30
+ - ruby: '3.0'
31
+ rails_version: '7.0.2.3'
23
32
  env:
24
33
  RAILS_VERSION: ${{ matrix.rails_version }}
34
+ ENGINE_CART_RAILS_OPTIONS: "--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test ${{ matrix.engine_cart_rails_options }}"
25
35
  steps:
26
- - uses: actions/checkout@v2
27
- - name: Set up Ruby
28
- uses: ruby/setup-ruby@v1
29
- with:
30
- ruby-version: ${{ matrix.ruby }}
31
- - name: Install dependencies with Rails ${{ matrix.rails_version }}
32
- run: bundle install
33
- - name: Run tests
34
- run: bundle exec rake
35
- env:
36
- ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
37
- test_rails6_0:
38
- runs-on: ubuntu-latest
39
- strategy:
40
- matrix:
41
- ruby: [2.6]
42
- steps:
43
- - uses: actions/checkout@v2
44
- - name: Set up Ruby
45
- uses: ruby/setup-ruby@v1
46
- with:
47
- ruby-version: ${{ matrix.ruby }}
48
- - name: Install dependencies
49
- run: bundle install
50
- env:
51
- RAILS_VERSION: 6.0.3.4
52
- - name: Run tests
53
- run: bundle exec rake
54
- env:
55
- RAILS_VERSION: 6.0.3.4
56
- ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
57
- test_rails5_2:
58
- runs-on: ubuntu-latest
59
- strategy:
60
- matrix:
61
- ruby: [2.5]
62
- steps:
63
- - uses: actions/checkout@v2
36
+ - uses: actions/checkout@v3
64
37
  - name: Set up Ruby
65
38
  uses: ruby/setup-ruby@v1
66
39
  with:
67
40
  ruby-version: ${{ matrix.ruby }}
68
41
  - name: Install dependencies
69
42
  run: bundle install
70
- env:
71
- RAILS_VERSION: 5.2.4.2
72
43
  - name: Run tests
73
- run: bundle exec rake
74
- env:
75
- RAILS_VERSION: 5.2.4.2
76
- ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
44
+ run: bundle exec rake ci
data/README.md CHANGED
@@ -46,7 +46,7 @@ This will install some asset references in your application.js and application.c
46
46
  You have at least one solr field you want to display as a range limit, that's why you've installed this plugin. In your CatalogController, the facet configuration should look like:
47
47
 
48
48
  ```ruby
49
- config.add_facet_field 'pub_date', label: 'Publication Year', range: true
49
+ config.add_facet_field 'pub_date', label: 'Publication Year', **default_range_config
50
50
  ```
51
51
 
52
52
  You should now get range limit display. More complicated configuration is available if desired, see Range Facet Configuration below.
@@ -138,11 +138,11 @@ is probably the best touch UI anyway, if it can be made to work well.
138
138
  There are two main types of JavaScript implemented for BlacklightRangeLimit:
139
139
  - Initialization and refresh of Range Limit plugin based off of events
140
140
  - Range Limit plugin functionality called from event listeners
141
-
141
+
142
142
  The second class of range limit functionality is customizable in your local application by overriding the specified function.
143
-
143
+
144
144
  A simple example of this is overriding the display ratio used to create the histogram
145
-
145
+
146
146
  ```javascript
147
147
  BlacklightRangeLimit.display_ratio = 1
148
148
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.1.0
1
+ 8.2.0
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * Closure functions in this file are mainly concerned with initializing, resizing, and updating
5
5
  * range limit functionality based off of page load, facet opening, page resizing, and otherwise
6
- * events.
6
+ * events.
7
7
  */
8
8
 
9
9
  Blacklight.onLoad(function() {
@@ -34,6 +34,19 @@ BlacklightRangeLimit.turnIntoPlot = function turnIntoPlot(container, wait_for_vi
34
34
  }
35
35
  }
36
36
 
37
+ BlacklightRangeLimit.parseSegment = function parseSegment(el) {
38
+ if ($(el).find("span.single").first().data('blrlSingle')) {
39
+ var val = BlacklightRangeLimit.parseNum($(el).find("span.single").first().data('blrlSingle'));
40
+
41
+ return [val, val];
42
+ } else {
43
+ var from = BlacklightRangeLimit.parseNum($(el).find("span.from").first().data('blrlBegin'));
44
+ var to = BlacklightRangeLimit.parseNum($(el).find("span.to").first().data('blrlEnd'));
45
+
46
+ return [from, to];
47
+ }
48
+ }
49
+
37
50
  // Takes a div holding a ul of distribution segments produced by
38
51
  // blacklight_range_limit/_range_facets and makes it into
39
52
  // a flot area chart.
@@ -45,15 +58,16 @@ BlacklightRangeLimit.areaChart = function areaChart(container) {
45
58
  var series_data = new Array();
46
59
  var pointer_lookup = new Array();
47
60
  var x_ticks = new Array();
48
- var min = BlacklightRangeLimit.parseNum($(container).find("ul li:first-child span.from").first().data('blrlBegin'));
49
- var max = BlacklightRangeLimit.parseNum($(container).find("ul li:last-child span.to").first().data('blrlEnd'));
61
+ var min = BlacklightRangeLimit.parseSegment($(container).find("ul li:first-child").first())[0];
62
+ var max = BlacklightRangeLimit.parseSegment($(container).find("ul li:last-child").first())[1];
50
63
 
51
64
  $(container).find("ul li").each(function() {
52
- var from = BlacklightRangeLimit.parseNum($(this).find("span.from").first().data('blrlBegin'));
53
- var to = BlacklightRangeLimit.parseNum($(this).find("span.to").first().data('blrlEnd'));
54
- var count = BlacklightRangeLimit.parseNum($(this).find("span.count").text());
55
- var avg = (count / (to - from + 1));
65
+ var segment = BlacklightRangeLimit.parseSegment(this);
66
+ var from = segment[0];
67
+ var to = segment[1];
56
68
 
69
+ var count = BlacklightRangeLimit.parseNum($(this).find("span.facet-count,span.count").text());
70
+ var avg = (count / (to - from + 1));
57
71
 
58
72
  //We use the avg as the y-coord, to make the area of each
59
73
  //segment proportional to how many documents it holds.
@@ -62,12 +76,10 @@ BlacklightRangeLimit.areaChart = function areaChart(container) {
62
76
 
63
77
  x_ticks.push(from);
64
78
 
65
- pointer_lookup.push({'from': from, 'to': to, 'count': count, 'label': $(this).find(".facet_select").html() });
79
+ pointer_lookup.push({'from': from, 'to': to, 'count': count, 'label': $(this).find(".facet-select,.facet_select").html() });
66
80
  });
67
- var max_plus_one = BlacklightRangeLimit.parseNum($(container).find("ul li:last-child span.to").text())+1;
68
- x_ticks.push( max_plus_one );
69
-
70
81
 
82
+ x_ticks.push( max + 1 );
71
83
 
72
84
  var plot;
73
85
  var config = $(container).closest('.blrl-plot-config').data('plot-config') || $(container).closest('.facet-limit').data('plot-config') || {};
@@ -123,24 +135,24 @@ BlacklightRangeLimit.areaChart = function areaChart(container) {
123
135
 
124
136
  var slider_placeholder = $(container).closest(".limit_content").find("[data-slider-placeholder]");
125
137
  if (slider_placeholder) {
126
- slider_placeholder.slider("setValue", [from, to+1]);
138
+ slider_placeholder.slider("setValue", [from, to]);
127
139
  }
128
140
  }
129
141
  });
130
142
 
131
143
  var form = $(container).closest(".limit_content").find("form.range_limit");
132
- form.find("input.range_begin, input.range_end").change(function () {
133
- plot.setSelection( BlacklightRangeLimit.form_selection(form, min, max) , true );
144
+ form.find("input.range_begin, input.range_end").on('input', function () {
145
+ plot.setSelection( BlacklightRangeLimit.form_selection(form, min, max), true );
134
146
  });
135
147
  $(container).closest(".limit_content").find(".profile .range").on("slide", function(event, ui) {
136
148
  var values = $(event.target).data("slider").getValue();
137
149
  form.find("input.range_begin").val(values[0]);
138
150
  form.find("input.range_end").val(values[1]);
139
- plot.setSelection(BlacklightRangeLimit.normalized_selection(values[0], Math.max(values[0], values[1]-1)), true);
151
+ plot.setSelection(BlacklightRangeLimit.normalized_selection(values[0], Math.max(values[0], values[1])), true);
140
152
  });
141
153
 
142
154
  // initially entirely selected, to match slider
143
- plot.setSelection( {xaxis: { from:min, to:max+0.9999}} );
155
+ plot.setSelection(BlacklightRangeLimit.normalized_selection(min, max));
144
156
  }
145
157
  }
146
158
 
@@ -28,7 +28,7 @@ Blacklight.onLoad(function() {
28
28
  // returns two element array min/max as numbers. If there is a limit applied,
29
29
  // it's boundaries are are limits. Otherwise, min/max in current result
30
30
  // set as sniffed from HTML. Pass in a DOM element for a div.range
31
- // Will return NaN as min or max in case of error or other weirdness.
31
+ // Will return NaN as min or max in case of error or other weirdness.
32
32
  BlacklightRangeLimit.min_max = function min_max(range_element) {
33
33
  var current_limit = $(range_element).closest(".limit_content.range_limit").find(".current")
34
34
 
@@ -61,7 +61,7 @@ BlacklightRangeLimit.buildSlider = function buildSlider(thisContext) {
61
61
  var max = boundaries[1];
62
62
 
63
63
  if (BlacklightRangeLimit.isInt(min) && BlacklightRangeLimit.isInt(max)) {
64
- $(thisContext).contents().wrapAll('<div class="sr-only" />');
64
+ $(thisContext).contents().wrapAll('<div class="sr-only visually-hidden" />');
65
65
 
66
66
  var range_element = $(thisContext);
67
67
  var form = $(range_element).closest(".range_limit").find("form.range_limit");
@@ -74,8 +74,8 @@ BlacklightRangeLimit.buildSlider = function buildSlider(thisContext) {
74
74
  if (placeholder_input.slider !== undefined) {
75
75
  placeholder_input.slider({
76
76
  min: min,
77
- max: max + 1,
78
- value: [min, max + 1],
77
+ max: max,
78
+ value: [min, max],
79
79
  tooltip: "hide"
80
80
  });
81
81
 
@@ -114,10 +114,10 @@ BlacklightRangeLimit.buildSlider = function buildSlider(thisContext) {
114
114
  begin_el.val(min);
115
115
  end_el.val(max);
116
116
 
117
- begin_el.change(function() {
118
- var val = BlacklightRangeLimit.parseNum($(thisContext).val());
117
+ begin_el.on('input', function() {
118
+ var val = BlacklightRangeLimit.parseNum(this.value);
119
119
  if (isNaN(val) || val < min) {
120
- //for weird data, set slider at min
120
+ //for weird data, set slider at min
121
121
  val = min;
122
122
  }
123
123
  var values = placeholder_input.data("slider").getValue();
@@ -125,8 +125,8 @@ BlacklightRangeLimit.buildSlider = function buildSlider(thisContext) {
125
125
  placeholder_input.slider("setValue", values);
126
126
  });
127
127
 
128
- end_el.change(function() {
129
- var val = BlacklightRangeLimit.parseNum($(thisContext).val());
128
+ end_el.on('input', function() {
129
+ var val = BlacklightRangeLimit.parseNum(this.value);
130
130
  if (isNaN(val) || val > max) {
131
131
  //weird entry, set slider to max
132
132
  val = max;
@@ -135,4 +135,24 @@ BlacklightRangeLimit.buildSlider = function buildSlider(thisContext) {
135
135
  values[1] = val;
136
136
  placeholder_input.slider("setValue", values);
137
137
  });
138
+
139
+ begin_el.change(function() {
140
+ var val1 = BlacklightRangeLimit.parseNum(begin_el.val());
141
+ var val2 = BlacklightRangeLimit.parseNum(end_el.val());
142
+
143
+ if (val2 < val1) {
144
+ begin_el.val(val2);
145
+ end_el.val(val1);
146
+ }
147
+ });
148
+
149
+ end_el.change(function() {
150
+ var val1 = BlacklightRangeLimit.parseNum(begin_el.val());
151
+ var val2 = BlacklightRangeLimit.parseNum(end_el.val());
152
+
153
+ if (val2 < val1) {
154
+ begin_el.val(val2);
155
+ end_el.val(val1);
156
+ }
157
+ });
138
158
  }
@@ -0,0 +1,48 @@
1
+ <%= render(@layout.new(facet_field: @facet_field)) do |component| %>
2
+ <% component.label do %>
3
+ <%= @facet_field.label %>
4
+ <% end %>
5
+
6
+ <% component.body do %>
7
+ <div class="limit_content range_limit <%= @facet_field.key %>-config blrl-plot-config">
8
+ <% if @facet_field.selected_range_facet_item %>
9
+ <%= render BlacklightRangeLimit::RangeSegmentsComponent.new(facet_field: @facet_field, facet_items: [@facet_field.selected_range_facet_item], classes: ['current']) %>
10
+ <% end %>
11
+
12
+ <!-- no results profile if missing is selected -->
13
+ <% unless @facet_field.missing_selected? %>
14
+ <!-- you can hide this if you want, but it has to be on page if you want
15
+ JS slider and calculated facets to show up, JS sniffs it. -->
16
+ <div class="profile">
17
+ <% if (min = @facet_field.min) &&
18
+ (max = @facet_field.max) %>
19
+
20
+ <% if range_config[:segments] != false %>
21
+ <div class="distribution subsection <%= 'chart_js' unless range_config[:chart_js] == false %>">
22
+ <!-- if we already fetched segments from solr, display them
23
+ here. Otherwise, display a link to fetch them, which JS
24
+ will AJAX fetch. -->
25
+ <% if @facet_field.range_queries.any? %>
26
+ <%= render BlacklightRangeLimit::RangeSegmentsComponent.new(facet_field: @facet_field) %>
27
+ <% else %>
28
+ <%= link_to(t('blacklight.range_limit.view_distribution'), range_limit_url(range_start: min, range_end: max), class: "load_distribution") %>
29
+ <% end %>
30
+ </div>
31
+ <% end %>
32
+ <p class="range subsection <%= "slider_js" unless range_config[:slider_js] == false %>">
33
+ <%= t('blacklight.range_limit.results_range_html', min: min, max: max) %>
34
+ </p>
35
+ <% end %>
36
+ </div>
37
+
38
+ <%= render BlacklightRangeLimit::RangeFormComponent.new(facet_field: @facet_field, classes: @classes) %>
39
+
40
+ <%= more_link(key: @facet_field.key, label: @facet_field.label) unless @facet_field.in_modal? %>
41
+
42
+ <% if @facet_field.missing_facet_item && !request.xhr? %>
43
+ <%= render BlacklightRangeLimit::RangeSegmentsComponent.new(facet_field: @facet_field, facet_items: [@facet_field.missing_facet_item], classes: ['missing', 'subsection']) %>
44
+ <% end %>
45
+ <% end %>
46
+ </div>
47
+ <% end %>
48
+ <% end %>
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlacklightRangeLimit
4
+ class RangeFacetComponent < ::ViewComponent::Base
5
+ renders_one :more_link, ->(key:, label:) do
6
+ tag.div class: 'more_facets' do
7
+ link_to t('blacklight.range_limit.view_larger', field_name: label),
8
+ search_facet_path(id: key),
9
+ data: { blacklight_modal: 'trigger' }
10
+ end
11
+ end
12
+
13
+ delegate :search_action_path, :search_facet_path, to: :helpers
14
+
15
+ def initialize(facet_field:, layout: nil, classes: BlacklightRangeLimit.classes)
16
+ @facet_field = facet_field
17
+ @layout = layout == false ? Blacklight::FacetFieldNoLayoutComponent : Blacklight::FacetFieldComponent
18
+ @classes = classes
19
+ end
20
+
21
+ def range_config
22
+ @facet_field.range_config
23
+ end
24
+
25
+ def range_limit_url(options = {})
26
+ helpers.main_app.url_for(@facet_field.search_state.to_h.merge(range_field: @facet_field.key, action: 'range_limit').merge(options))
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ <%= form_tag search_action_path, method: :get, class: [@classes[:form], "range_#{@facet_field.key} d-flex justify-content-center"].join(' ') do %>
2
+ <%= render Blacklight::HiddenSearchStateComponent.new(params: @facet_field.search_state.params_for_search.except(:utf8, :page)) %>
3
+
4
+ <div class="input-group input-group-sm mb-3 flex-nowrap range-limit-input-group">
5
+ <%= render_range_input(:begin, begin_label) %>
6
+ <%= render_range_input(:end, end_label) %>
7
+ <div class="input-group-append visually-hidden">
8
+ <%= submit_tag t('blacklight.range_limit.submit_limit'), class: @classes[:submit] %>
9
+ </div>
10
+ <%= submit_tag t('blacklight.range_limit.submit_limit'), class: @classes[:submit] + " sr-only", "aria-hidden": "true" %>
11
+ </div>
12
+ <% end %>
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlacklightRangeLimit
4
+ class RangeFormComponent < ::ViewComponent::Base
5
+ delegate :search_action_path, to: :helpers
6
+
7
+ def initialize(facet_field:, classes: BlacklightRangeLimit.classes)
8
+ @facet_field = facet_field
9
+ @classes = classes
10
+ end
11
+
12
+ def begin_label
13
+ range_config[:input_label_range_begin] || t("blacklight.range_limit.range_begin", field_label: @facet_field.label)
14
+ end
15
+
16
+ def end_label
17
+ range_config[:input_label_range_end] || t("blacklight.range_limit.range_end", field_label: @facet_field.label)
18
+ end
19
+
20
+ def maxlength
21
+ range_config[:maxlength]
22
+ end
23
+
24
+ # type is 'begin' or 'end'
25
+ def render_range_input(type, input_label = nil, maxlength_override = nil)
26
+ type = type.to_s
27
+
28
+ default = if @facet_field.selected_range.is_a?(Range)
29
+ case type
30
+ when 'begin' then @facet_field.selected_range.first
31
+ when 'end' then @facet_field.selected_range.last
32
+ end
33
+ end
34
+
35
+ html = number_field_tag("range[#{@facet_field.key}][#{type}]", default, maxlength: maxlength_override || maxlength, class: "form-control text-center range_#{type}")
36
+ html += label_tag("range[#{@facet_field.key}][#{type}]", input_label, class: 'sr-only visually-hidden') if input_label.present?
37
+ html
38
+ end
39
+
40
+ private
41
+
42
+ def range_config
43
+ @facet_field.range_config
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ <ul class="facet-values list-unstyled <%= @classes.join(' ') %>">
2
+ <%= render @item_component.with_collection(facet_item_presenters) %>
3
+ </ul>
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlacklightRangeLimit
4
+ class RangeSegmentsComponent < ::ViewComponent::Base
5
+ def initialize(facet_field:, facet_items: nil, item_component: nil, classes: [])
6
+ super
7
+
8
+ @facet_field = facet_field
9
+ @facet_items = facet_items || facet_field.try(:range_queries) || []
10
+ @item_component = facet_field.facet_field.item_component || Blacklight::FacetItemComponent
11
+ @classes = classes
12
+ end
13
+
14
+ def facet_item_presenters
15
+ @facet_items.map { |item| facet_item_presenter(item) }
16
+ end
17
+
18
+ def facet_item_presenter(facet_item)
19
+ facet_config.item_presenter.new(facet_item, facet_config, helpers, @facet_field.key)
20
+ end
21
+
22
+ def facet_config
23
+ @facet_field.facet_field
24
+ end
25
+ end
26
+ end