blacklight_range_limit 7.2.0 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/app/assets/javascripts/blacklight_range_limit.js +7 -0
  4. data/app/assets/javascripts/blacklight_range_limit/range_limit_distro_facets.js +23 -11
  5. data/app/assets/javascripts/blacklight_range_limit/range_limit_slider.js +83 -76
  6. data/app/assets/stylesheets/blacklight_range_limit/blacklight_range_limit.css +26 -1
  7. data/app/helpers/range_limit_helper.rb +3 -3
  8. data/app/views/blacklight_range_limit/_range_limit_panel.html.erb +30 -27
  9. data/app/views/blacklight_range_limit/_range_segments.html.erb +6 -6
  10. data/app/views/blacklight_range_limit/range_limit_panel.html.erb +10 -0
  11. data/config/locales/blacklight_range_limit.en.yml +7 -0
  12. data/lib/blacklight_range_limit.rb +2 -4
  13. data/lib/blacklight_range_limit/controller_override.rb +28 -0
  14. data/lib/blacklight_range_limit/routes.rb +1 -1
  15. data/lib/blacklight_range_limit/routes/range_searchable.rb +1 -0
  16. data/lib/blacklight_range_limit/view_helper_override.rb +0 -13
  17. data/spec/features/a_javascript_spec.rb +11 -4
  18. data/spec/spec_helper.rb +12 -1
  19. data/vendor/assets/javascripts/flot/jquery.canvaswrapper.js +550 -0
  20. data/vendor/assets/javascripts/flot/jquery.colorhelpers.js +199 -0
  21. data/vendor/assets/javascripts/flot/jquery.flot.browser.js +98 -0
  22. data/vendor/assets/javascripts/flot/jquery.flot.drawSeries.js +663 -0
  23. data/vendor/assets/javascripts/flot/jquery.flot.hover.js +360 -0
  24. data/vendor/assets/javascripts/flot/jquery.flot.js +1610 -1928
  25. data/vendor/assets/javascripts/flot/jquery.flot.saturated.js +43 -0
  26. data/vendor/assets/javascripts/flot/jquery.flot.selection.js +237 -68
  27. data/vendor/assets/javascripts/flot/jquery.flot.uiConstants.js +10 -0
  28. metadata +10 -3
  29. data/vendor/assets/javascripts/flot/excanvas.min.js +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddb716f6bce403a2d7f369337d8f4a8da47dc279895c8c5bb3996a9ac2edcdae
4
- data.tar.gz: f758c04d42477a7650b4f164c5ee4889a4edc903d22ddff3639c71ed216c3d70
3
+ metadata.gz: 2734b8690264ccc35bd5b2e2f494fb108027154597e2e03789c7b969e86342f2
4
+ data.tar.gz: 4dc2cb49b054401e6696fdd7a2f118edf1d686004a1a2f97ae294a4bc0cc19d2
5
5
  SHA512:
6
- metadata.gz: 1cb56737784cf18e63e857494d5f7b41216a4238ae7b02f2080f82146403e7e523d43beb1ad0e353d942df03fe4b5292a92d02fcfee53ab19c755c0da2e5e5e1
7
- data.tar.gz: 6bb5e1f046e4db352ca9d9f0fcfe809af4d61bc75b75be55318bc40463f14be4421839669c60e7e9442cd8c51585ac76ee164c81eaa5b2af4c9b1f2bc16b75c6
6
+ metadata.gz: 5e533e776139bf3a7d18d2387c0d56a50b199a7b3879cfb6c1e56056ea138f514d4d1d17c9aa491b8f10c8c6b0b9d9ae4e5f89c1487567af88aad36eceddf589
7
+ data.tar.gz: 55e9cf4e8f6a34ae8d2f35be0ba4df53cfd996c9e2cc1b532796c337b956e28fa6c2ca6780eae75338c2e1ad2a15afe33183ec860a6c96d009d4f3b610908e9b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.2.0
1
+ 7.3.0
@@ -6,7 +6,14 @@
6
6
  // JS to work, expect host app to load it.
7
7
 
8
8
 
9
+ //= require 'flot/jquery.canvaswrapper.js'
10
+ //= require 'flot/jquery.colorhelpers.js'
9
11
  //= require 'flot/jquery.flot.js'
12
+ //= require 'flot/jquery.flot.browser.js'
13
+ //= require 'flot/jquery.flot.saturated.js'
14
+ //= require 'flot/jquery.flot.drawSeries.js'
15
+ //= require 'flot/jquery.flot.hover.js'
16
+ //= require 'flot/jquery.flot.uiConstants.js'
10
17
  //= require 'flot/jquery.flot.selection.js'
11
18
  //= require 'bootstrap-slider'
12
19
 
@@ -17,17 +17,7 @@ Blacklight.onLoad(function() {
17
17
  turnIntoPlot($(this).parent());
18
18
  });
19
19
 
20
-
21
- // Add AJAX fetched range facets if needed, and add a chart to em
22
- $(".range_limit .profile .distribution a.load_distribution").each(function() {
23
- var container = $(this).parent('div.distribution');
24
-
25
- $(container).load($(this).attr('href'), function(response, status) {
26
- if ($(container).hasClass("chart_js") && status == "success" ) {
27
- turnIntoPlot(container);
28
- }
29
- });
30
- });
20
+ checkForNeededFacetsToFetch();
31
21
 
32
22
  // Listen for twitter bootstrap collapsible open events, to render flot
33
23
  // in previously hidden divs on open, if needed.
@@ -45,6 +35,28 @@ Blacklight.onLoad(function() {
45
35
  }
46
36
  });
47
37
 
38
+ // When loaded in a modal
39
+ $(Blacklight.modal.modalSelector).on('shown.bs.modal', function() {
40
+ $(this).find(".range_limit .profile .distribution.chart_js ul").each(function() {
41
+ turnIntoPlot($(this).parent());
42
+ });
43
+
44
+ // Case when there is no currently selected range
45
+ checkForNeededFacetsToFetch();
46
+ });
47
+
48
+ // Add AJAX fetched range facets if needed, and add a chart to em
49
+ function checkForNeededFacetsToFetch() {
50
+ $(".range_limit .profile .distribution a.load_distribution").each(function() {
51
+ var container = $(this).parent('div.distribution');
52
+
53
+ $(container).load($(this).attr('href'), function(response, status) {
54
+ if ($(container).hasClass("chart_js") && status == "success" ) {
55
+ turnIntoPlot(container);
56
+ }
57
+ });
58
+ });
59
+ }
48
60
 
49
61
 
50
62
  // after a collapsible facet contents is fully shown,
@@ -1,85 +1,16 @@
1
1
  // for Blacklight.onLoad:
2
2
 
3
3
  Blacklight.onLoad(function() {
4
-
5
- $(".range_limit .profile .range.slider_js").each(function() {
6
- var range_element = $(this);
7
-
8
- var boundaries = min_max(this);
9
- var min = boundaries[0];
10
- var max = boundaries[1];
11
-
12
- if (isInt(min) && isInt(max)) {
13
- $(this).contents().wrapAll('<div style="display:none" />');
14
-
15
- var range_element = $(this);
16
- var form = $(range_element).closest(".range_limit").find("form.range_limit");
17
- var begin_el = form.find("input.range_begin");
18
- var end_el = form.find("input.range_end");
19
-
20
- var placeholder_input = $('<input type="text" data-slider-placeholder="true" style="width:100%;">').appendTo(range_element);
21
-
22
- // make sure slider is loaded
23
- if (placeholder_input.slider !== undefined) {
24
- placeholder_input.slider({
25
- min: min,
26
- max: max+1,
27
- value: [min, max+1],
28
- tooltip: "hide"
29
- });
30
4
 
31
- // try to make slider width/orientation match chart's
32
- var container = range_element.closest(".range_limit");
33
- var plot = container.find(".chart_js").data("plot");
34
- var slider_el = container.find(".slider");
35
-
36
- if (plot && slider_el) {
37
- slider_el.width(plot.width());
38
- slider_el.css("display", "block")
39
- slider_el.css('margin-right', 'auto');
40
- slider_el.css('margin-left', 'auto');
41
- }
42
- else if (slider_el) {
43
- slider_el.css("width", "100%");
44
- }
45
- }
46
-
47
- // Slider change should update text input values.
48
- var parent = $(this).parent();
49
- var form = $(parent).closest(".limit_content").find("form.range_limit");
50
- $(parent).closest(".limit_content").find(".profile .range").on("slide", function(event, ui) {
51
- var values = $(event.target).data("slider").getValue();
52
- form.find("input.range_begin").val(values[0]);
53
- form.find("input.range_end").val(values[1]);
54
- });
55
- }
5
+ $(".range_limit .profile .range.slider_js").each(function() {
6
+ buildSlider(this);
7
+ });
56
8
 
57
- begin_el.val(min);
58
- end_el.val(max);
59
-
60
- begin_el.change( function() {
61
- var val = BlacklightRangeLimit.parseNum($(this).val());
62
- if ( isNaN(val) || val < min) {
63
- //for weird data, set slider at min
64
- val = min;
65
- }
66
- var values = placeholder_input.data("slider").getValue();
67
- values[0] = val;
68
- placeholder_input.slider("setValue", values);
9
+ $(Blacklight.modal.modalSelector).on('shown.bs.modal', function() {
10
+ $(this).find(".range_limit .profile .range.slider_js").each(function() {
11
+ buildSlider(this);
12
+ });
69
13
  });
70
-
71
- end_el.change( function() {
72
- var val = BlacklightRangeLimit.parseNum($(this).val());
73
- if ( isNaN(val) || val > max ) {
74
- //weird entry, set slider to max
75
- val = max;
76
- }
77
- var values = placeholder_input.data("slider").getValue();
78
- values[1] = val;
79
- placeholder_input.slider("setValue", values);
80
- });
81
-
82
- });
83
14
 
84
15
  // catch event for redrawing chart, to redraw slider to match width
85
16
  $("body").on("plotDrawn.blacklight.rangeLimit", function(event) {
@@ -126,4 +57,80 @@ function isInt(n) {
126
57
  return n % 1 === 0;
127
58
  }
128
59
 
60
+ function buildSlider(thisContext) {
61
+ var range_element = $(thisContext);
62
+
63
+ var boundaries = min_max(thisContext);
64
+ var min = boundaries[0];
65
+ var max = boundaries[1];
66
+
67
+ if (isInt(min) && isInt(max)) {
68
+ $(thisContext).contents().wrapAll('<div style="display:none" />');
69
+
70
+ var range_element = $(thisContext);
71
+ var form = $(range_element).closest(".range_limit").find("form.range_limit");
72
+ var begin_el = form.find("input.range_begin");
73
+ var end_el = form.find("input.range_end");
74
+
75
+ var placeholder_input = $('<input type="text" data-slider-placeholder="true" style="width:100%;">').appendTo(range_element);
76
+
77
+ // make sure slider is loaded
78
+ if (placeholder_input.slider !== undefined) {
79
+ placeholder_input.slider({
80
+ min: min,
81
+ max: max + 1,
82
+ value: [min, max + 1],
83
+ tooltip: "hide"
84
+ });
85
+
86
+ // try to make slider width/orientation match chart's
87
+ var container = range_element.closest(".range_limit");
88
+ var plot = container.find(".chart_js").data("plot");
89
+ var slider_el = container.find(".slider");
90
+
91
+ if (plot && slider_el) {
92
+ slider_el.width(plot.width());
93
+ slider_el.css("display", "block")
94
+ slider_el.css('margin-right', 'auto');
95
+ slider_el.css('margin-left', 'auto');
96
+ } else if (slider_el) {
97
+ slider_el.css("width", "100%");
98
+ }
99
+ }
100
+
101
+ // Slider change should update text input values.
102
+ var parent = $(thisContext).parent();
103
+ var form = $(parent).closest(".limit_content").find("form.range_limit");
104
+ $(parent).closest(".limit_content").find(".profile .range").on("slide", function(event, ui) {
105
+ var values = $(event.target).data("slider").getValue();
106
+ form.find("input.range_begin").val(values[0]);
107
+ form.find("input.range_end").val(values[1]);
108
+ });
109
+ }
110
+
111
+ begin_el.val(min);
112
+ end_el.val(max);
113
+
114
+ begin_el.change(function() {
115
+ var val = BlacklightRangeLimit.parseNum($(thisContext).val());
116
+ if (isNaN(val) || val < min) {
117
+ //for weird data, set slider at min
118
+ val = min;
119
+ }
120
+ var values = placeholder_input.data("slider").getValue();
121
+ values[0] = val;
122
+ placeholder_input.slider("setValue", values);
123
+ });
124
+
125
+ end_el.change(function() {
126
+ var val = BlacklightRangeLimit.parseNum($(thisContext).val());
127
+ if (isNaN(val) || val > max) {
128
+ //weird entry, set slider to max
129
+ val = max;
130
+ }
131
+ var values = placeholder_input.data("slider").getValue();
132
+ values[1] = val;
133
+ placeholder_input.slider("setValue", values);
134
+ });
135
+ }
129
136
  });
@@ -19,4 +19,29 @@ form.range_limit {
19
19
  .slider_js .slider-selection {
20
20
  /* color from flot selection */
21
21
  background: #e8cfac;
22
- }
22
+ }
23
+
24
+ .modal-body .view_larger, .facet-values {
25
+ display: none;
26
+ }
27
+
28
+ form .range_limit_label {
29
+ display: none;
30
+ }
31
+
32
+ .modal-body .range_limit_label {
33
+ display: flex;
34
+ }
35
+
36
+ .modal-body .range_limit {
37
+ justify-content: center;
38
+ }
39
+
40
+ .view_larger {
41
+ display: block;
42
+ text-align: center;
43
+ }
44
+
45
+ .range_limit .chart_js {
46
+ min-height: 80px;
47
+ }
@@ -32,12 +32,12 @@ module RangeLimitHelper
32
32
  hash = my_params[:range][solr_field]
33
33
 
34
34
  if hash["missing"]
35
- return BlacklightRangeLimit.labels[:missing]
35
+ return t('blacklight.range_limit.missing')
36
36
  elsif hash["begin"] || hash["end"]
37
37
  if hash["begin"] == hash["end"]
38
- return "<span class='single'>#{h(hash["begin"])}</span>".html_safe
38
+ return t('blacklight.range_limit.single_html', begin: h(hash['begin']))
39
39
  else
40
- return "<span class='from'>#{h(hash['begin'])}</span> to <span class='to'>#{h(hash['end'])}</span>".html_safe
40
+ return t('blacklight.range_limit.range_html', begin: h(hash['begin']), end: h(hash['end']))
41
41
  end
42
42
  end
43
43
 
@@ -13,7 +13,7 @@
13
13
  <li class="selected">
14
14
  <span class="facet-label">
15
15
  <span class="selected"><%= range_display(field_name) %></span>
16
- <%= link_to remove_range_param(field_name), :class=>"remove", :title => t('blacklight.range_limit.remove_limit') do %>
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
17
  <span class="remove-icon">✖</span>
18
18
  <span class="sr-only">[<%= t('blacklight.range_limit.remove_limit') %>]</span>
19
19
  <% end %>
@@ -24,15 +24,6 @@
24
24
 
25
25
  <% end %>
26
26
 
27
- <% unless selected_missing_for_range_limit?(field_name) %>
28
- <%= form_tag search_action_path, :method => :get, class: [BlacklightRangeLimit.classes[:form], "range_#{field_name}"].join(' ') do %>
29
- <%= render_hash_as_hidden_fields(search_state.params_for_search.except(:page)) %>
30
-
31
- <%= render_range_input(field_name, :begin, input_label_range_begin, maxlength) %> – <%= render_range_input(field_name, :end, input_label_range_end, maxlength) %>
32
- <%= submit_tag t('blacklight.range_limit.submit_limit'), class: BlacklightRangeLimit.classes[:submit] %>
33
- <% end %>
34
- <% end %>
35
-
36
27
  <!-- no results profile if missing is selected -->
37
28
  <% unless selected_missing_for_range_limit?(field_name) %>
38
29
  <!-- you can hide this if you want, but it has to be on page if you want
@@ -44,9 +35,6 @@
44
35
 
45
36
  <% if (min = range_results_endpoint(field_name, :min)) &&
46
37
  (max = range_results_endpoint(field_name, :max)) %>
47
- <p class="range subsection <%= "slider_js" unless field_config[:slider_js] == false %>">
48
- Current results range from <span class="min"><%= range_results_endpoint(field_name, :min) %></span> to <span class="max"><%= range_results_endpoint(field_name, :max) %></span>
49
- </p>
50
38
 
51
39
  <% if field_config[:segments] != false %>
52
40
  <div class="distribution subsection <%= 'chart_js' unless field_config[:chart_js] == false %>">
@@ -58,24 +46,39 @@
58
46
  <%= render(:partial => "blacklight_range_limit/range_segments", :locals => {:solr_field => field_name}) %>
59
47
 
60
48
  <% else %>
61
- <%= link_to('View distribution', main_app.url_for(search_state.to_h.merge(action: 'range_limit', range_field: field_name, range_start: min, range_end: max)), :class => "load_distribution") %>
49
+ <%= link_to(t('blacklight.range_limit.view_distribution'), search_action_url(search_state.to_h.merge(action: 'range_limit', range_field: field_name, range_start: min, range_end: max)), :class => "load_distribution") %>
62
50
  <% end %>
63
51
  </div>
64
52
  <% end %>
65
- <% end %>
66
-
67
- <% if (stats = stats_for_field(field_name)) && stats["missing"] > 0 %>
68
- <ul class="missing list-unstyled facet-values subsection">
69
- <li>
70
- <span class="facet-label">
71
- <%= link_to BlacklightRangeLimit.labels[:missing], add_range_missing(field_name) %>
72
- </span>
73
- <%# note important there be no whitespace inside facet-count to avoid
74
- bug in some versions of Blacklight (including 7.1.0.alpha) %>
75
- <span class="facet-count"><%= number_with_delimiter(stats["missing"]) %></span>
76
- </li>
77
- </ul>
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>
78
56
  <% end %>
79
57
  </div>
58
+
59
+ <%= form_tag search_action_path, :method => :get, class: [BlacklightRangeLimit.classes[:form], "range_#{field_name}"].join(' ') do %>
60
+ <%= render_hash_as_hidden_fields(search_state.params_for_search.except(:page)) %>
61
+ <%= content_tag :label, t('blacklight.range_limit.date_range_label'), class: 'range_limit_label' %>
62
+ <%= render_range_input(field_name, :begin, input_label_range_begin, maxlength) %> – <%= render_range_input(field_name, :end, input_label_range_end, maxlength) %>
63
+ <%= submit_tag t('blacklight.range_limit.submit_limit'), class: BlacklightRangeLimit.classes[:submit] %>
64
+ <% end %>
65
+
66
+ <%= link_to t('blacklight.range_limit.view_larger', field_name: label),
67
+ search_action_url(search_state.to_h.merge(action: 'range_limit_panel', id: field_name, range_start: 0, range_end: 2019)),
68
+ class: 'view_larger mt-1',
69
+ data: { blacklight_modal: 'trigger' } %>
70
+
71
+ <% if (stats = stats_for_field(field_name)) && stats["missing"] > 0 %>
72
+ <ul class="missing list-unstyled facet-values subsection">
73
+ <li>
74
+ <span class="facet-label">
75
+ <%= link_to t('blacklight.range_limit.missing'), search_action_url(add_range_missing(field_name).except(:controller, :action)) %>
76
+ </span>
77
+ <%# note important there be no whitespace inside facet-count to avoid
78
+ bug in some versions of Blacklight (including 7.1.0.alpha) %>
79
+ <span class="facet-count"><%= number_with_delimiter(stats["missing"]) %></span>
80
+ </li>
81
+ </ul>
82
+ <% end %>
80
83
  <% end %>
81
84
  </div>
@@ -6,12 +6,12 @@
6
6
  <li>
7
7
  <span class="facet-label">
8
8
  <%= link_to(
9
- content_tag("span", facet_display_value(solr_field, hash[:from]), :class => "from") +
10
- " to " +
11
- content_tag("span", facet_display_value(solr_field, hash[:to]), :class => "to"),
12
- add_range(solr_field, hash[:from], hash[:to]).merge(:action => "index"),
13
- :class => "facet_select"
14
- ) %>
9
+ t('blacklight.range_limit.range_html',
10
+ begin: facet_display_value(solr_field, hash[:from]),
11
+ end: facet_display_value(solr_field, hash[:to])),
12
+ search_action_url(add_range(solr_field, hash[:from], hash[:to]).except(:controller, :action)),
13
+ class: 'facet_select'
14
+ ) %>
15
15
  </span>
16
16
  <%= render_facet_count hash[:count], classes: ['count'] %>
17
17
  </li>
@@ -0,0 +1,10 @@
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">&times;</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>
@@ -5,3 +5,10 @@ en:
5
5
  range_end: "%{field_label} range end"
6
6
  submit_limit: 'Limit'
7
7
  remove_limit: 'remove'
8
+ missing: 'Unknown'
9
+ view_distribution: 'View distribution'
10
+ view_larger: 'View larger »'
11
+ date_range_label: 'Date range:'
12
+ results_range_html: 'Current results range from <span class="min">%{min}</span> to <span class="max">%{max}</span>'
13
+ single_html: '<span class="single">%{begin}</span>'
14
+ range_html: '<span class="from">%{begin}</span> to <span class="to">%{end}</span>'
@@ -13,10 +13,8 @@ module BlacklightRangeLimit
13
13
  # Raised when an invalid range is encountered
14
14
  class InvalidRange < TypeError; end
15
15
 
16
- mattr_accessor :labels, :classes
17
- self.labels = {
18
- :missing => "Unknown"
19
- }
16
+ mattr_accessor :classes
17
+
20
18
  self.classes = {
21
19
  form: 'range_limit subsection form-inline',
22
20
  submit: 'submit btn btn-secondary'