blacklight 5.4.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c37c9845bc5cd732386ab0fc43bbf2935022e25
4
- data.tar.gz: f8aebbe56c4b6f9f7120d1e9901896da3dc0b71f
3
+ metadata.gz: fac08d13bf67f849e356efeeea75395d3dd66b44
4
+ data.tar.gz: 1ed742c6ae84f16f1361950eb4fdcdc7dbfb38f1
5
5
  SHA512:
6
- metadata.gz: 5318ae2e9e5507c0afd82e057eeef478df545c8f17c2ba817ba0e216a455222392ab1a093ceca2d2223ac51d8be18386ec4b453693f1e4c2016ede24fdaea6a6
7
- data.tar.gz: c4969efe9347576951e642bd6f9506624ea35a03eaf5dbf14fd1d428c9760de80481e3fc97d6fc0e5cc2dca4a0f22cb2e57f7566714e037340ee504cd19cb1c6
6
+ metadata.gz: b8106b0abf9286780e5446572ac0d47e375d75f628981086cd9101f6b994688ba9cc4f3329319be812edece3723c974be889f2a488cda8ae60929383bf1ff775
7
+ data.tar.gz: 5addaec1c1bfaf038aa6b1c010ec4942c40059345d344a805c4f062e47cce95eff2e15969ec6ddc3c7288ce0790453f06da79bab42ceca5b64964b7c4ff3e014
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.4.0
1
+ 5.5.0
@@ -102,27 +102,44 @@ Blacklight.ajaxModal.containerSelector = "[data-ajax-modal~=container]";
102
102
 
103
103
  Blacklight.ajaxModal.modalCloseSelector = "[data-ajax-modal~=close], span.ajax-close-modal";
104
104
 
105
- Blacklight.ajaxModal.receiveAjax = function (data) {
106
- var contents = data.responseText;
107
-
108
- // does it have a data- selector for container?
109
- // important we don't execute script tags, we shouldn't.
110
- // code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/master/src/ajax/load.js?source=c#L62
111
- var container = $("<div>").
112
- append( jQuery.parseHTML(contents) ).find( Blacklight.ajaxModal.containerSelector ).first();
113
- if (container.size() !== 0) {
114
- contents = container.html();
115
- }
116
-
117
- $(Blacklight.ajaxModal.modalSelector).find('.modal-content').html(contents);
118
-
119
- // send custom event with the modal dialog div as the target
120
- var e = $.Event('loaded.blacklight.ajax-modal')
121
- $(Blacklight.ajaxModal.modalSelector).trigger(e);
122
- // if they did preventDefault, don't show the dialog
123
- if (e.isDefaultPrevented()) return;
105
+ // Called on fatal failure of ajax load, function returns content
106
+ // to show to user in modal. Right now called only for extreme
107
+ // network errors.
108
+ Blacklight.ajaxModal.onFailure = function(data) {
109
+ var contents = "<div class='modal-header'>" +
110
+ "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>" +
111
+ "Network Error</div>";
112
+ $(Blacklight.ajaxModal.modalSelector).find('.modal-content').html(contents);
113
+ $(Blacklight.ajaxModal.modalSelector).modal('show');
114
+ }
124
115
 
125
- $(Blacklight.ajaxModal.modalSelector).modal('show');
116
+ Blacklight.ajaxModal.receiveAjax = function (data) {
117
+ if (data.readyState == 0) {
118
+ // Network error, could not contact server.
119
+ Blacklight.ajaxModal.onFailure(data)
120
+ }
121
+ else {
122
+ var contents = data.responseText;
123
+
124
+ // does it have a data- selector for container?
125
+ // important we don't execute script tags, we shouldn't.
126
+ // code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/master/src/ajax/load.js?source=c#L62
127
+ var container = $("<div>").
128
+ append( jQuery.parseHTML(contents) ).find( Blacklight.ajaxModal.containerSelector ).first();
129
+ if (container.size() !== 0) {
130
+ contents = container.html();
131
+ }
132
+
133
+ $(Blacklight.ajaxModal.modalSelector).find('.modal-content').html(contents);
134
+
135
+ // send custom event with the modal dialog div as the target
136
+ var e = $.Event('loaded.blacklight.ajax-modal')
137
+ $(Blacklight.ajaxModal.modalSelector).trigger(e);
138
+ // if they did preventDefault, don't show the dialog
139
+ if (e.isDefaultPrevented()) return;
140
+
141
+ $(Blacklight.ajaxModal.modalSelector).modal('show');
142
+ }
126
143
  };
127
144
 
128
145
 
@@ -13,6 +13,8 @@
13
13
  attribute (HTML5-style doc-*) that contains the id/primary key
14
14
  of the object in question -- used by plugin for a unique value for
15
15
  DOM id's.
16
+
17
+ Uses HTML for a checkbox compatible with Bootstrap 3.
16
18
 
17
19
  Pass in options for your class name and labels:
18
20
  $("form.something").bl_checkbox_submit({
@@ -54,7 +56,6 @@
54
56
  .attr("id", options.css_class + "_" + unique_id);
55
57
  var label = $('<label>')
56
58
  .addClass( options.css_class )
57
- .addClass('checkbox')
58
59
  .attr("for", options.css_class + '_' + unique_id)
59
60
  .attr("title", form.attr("title") || "");
60
61
  var span = $('<span>');
@@ -62,6 +63,10 @@
62
63
  label.append(checkbox);
63
64
  label.append(" ");
64
65
  label.append(span);
66
+
67
+ var checkbox_div = $("<div class='checkbox' />")
68
+ .addClass(options.css_class)
69
+ .append(label);
65
70
 
66
71
  function update_state_for(state) {
67
72
  checkbox.prop("checked", state);
@@ -77,7 +82,7 @@
77
82
  }
78
83
  }
79
84
 
80
- form.append(label);
85
+ form.append(checkbox_div);
81
86
  update_state_for(checked);
82
87
 
83
88
  checkbox.click(function() {
@@ -56,13 +56,17 @@ span.constraints-label {
56
56
  &:hover, &:active {
57
57
  background-color: $btn-default-bg;
58
58
  border-color: $btn-default-border;
59
+ box-shadow: none;
59
60
  }
60
61
  }
61
62
 
62
63
  .filterName:after
63
64
  {
64
65
  @extend .text-muted;
65
- content: "\276F";
66
+ font-family: 'Glyphicons Halflings';
67
+ /* glyphicon-chevron-right */
68
+ content: "\e080";
69
+ font-size: 70%;
66
70
  padding-left: $caret-width-base;
67
71
  }
68
72
 
@@ -185,4 +189,4 @@ label.toggle_bookmark
185
189
  .caption {
186
190
  @extend .sr-only;
187
191
  }
188
- }
192
+ }
@@ -505,7 +505,9 @@ module Blacklight::BlacklightHelperBehavior
505
505
  # XXX rather than handling this logic through exceptions, maybe there's a Rails internals method
506
506
  # for determining if a partial template exists..
507
507
  begin
508
- return render :partial => (str % { :action_name => base_name, :format => format, :index_view_type => document_index_view_type }), :locals=>locals.merge(:document=>doc)
508
+ partial = str % { action_name: base_name, format: format, index_view_type: document_index_view_type }
509
+ logger.debug "Looking for document partial #{partial}"
510
+ return render partial: partial, locals: locals.merge(document: doc)
509
511
  rescue ActionView::MissingTemplate
510
512
  nil
511
513
  end
@@ -37,6 +37,24 @@ module Blacklight::ConfigurationHelperBehavior
37
37
  blacklight_config.show_fields
38
38
  end
39
39
 
40
+ ##
41
+ # Return a label for the currently selected search field.
42
+ # If no "search_field" or the default (e.g. "all_fields") is selected, then return nil
43
+ # Otherwise grab the label of the selected search field.
44
+ # @param [Hash] query parameters
45
+ # @return [String]
46
+ def constraint_query_label(localized_params = params)
47
+ label_for_search_field(localized_params[:search_field]) unless default_search_field?(localized_params[:search_field])
48
+ end
49
+
50
+ ##
51
+ # Is the search form using the default search field ("all_fields" by default)?
52
+ # @param [String] the currently selected search_field
53
+ # @return [Boolean]
54
+ def default_search_field?(selected_search_field)
55
+ selected_search_field.blank? || (default_search_field && selected_search_field == default_search_field[:key])
56
+ end
57
+
40
58
  ##
41
59
  # Look up the label for the index field
42
60
  def index_field_label document, field
@@ -50,6 +50,27 @@ module Blacklight::FacetsHelperBehavior
50
50
  render(options)
51
51
  end
52
52
 
53
+ ##
54
+ # Renders the list of values
55
+ # removes any elements where render_facet_item returns a nil value. This enables an application
56
+ # to filter undesireable facet items so they don't appear in the UI
57
+ def render_facet_limit_list(paginator, solr_field, wrapping_element=:li)
58
+ safe_join(paginator.items.
59
+ map { |item| render_facet_item(solr_field, item) }.compact.
60
+ map { |item| content_tag(wrapping_element,item)}
61
+ )
62
+ end
63
+
64
+ ##
65
+ # Renders a single facet item
66
+ def render_facet_item(solr_field, item)
67
+ if facet_in_params?( solr_field, item.value )
68
+ render_selected_facet_value(solr_field, item)
69
+ else
70
+ render_facet_value(solr_field, item)
71
+ end
72
+ end
73
+
53
74
  ##
54
75
  # Determine if Blacklight should render the display_facet or not
55
76
  #
@@ -77,7 +98,10 @@ module Blacklight::FacetsHelperBehavior
77
98
  end
78
99
 
79
100
  ##
80
- # the name of the partial to use to render a facet field.
101
+ # The name of the partial to use to render a facet field.
102
+ # uses the value of the "partial" field if set in the facet configuration
103
+ # otherwise uses "facet_pivot" if this facet is a pivot facet
104
+ # defaults to 'facet_limit'
81
105
  #
82
106
  # @return [String]
83
107
  def facet_partial_name(display_facet = nil)
@@ -33,21 +33,12 @@ module Blacklight::RenderConstraintsHelperBehavior
33
33
  # @return [String]
34
34
  def render_constraints_query(localized_params = params)
35
35
  # So simple don't need a view template, we can just do it here.
36
- if (!localized_params[:q].blank?)
37
- label =
38
- if (localized_params[:search_field].blank? || (default_search_field && localized_params[:search_field] == default_search_field[:key] ) )
39
- nil
40
- else
41
- label_for_search_field(localized_params[:search_field])
42
- end
43
-
44
- render_constraint_element(label,
45
- localized_params[:q],
46
- :classes => ["query"],
47
- :remove => url_for(localized_params.merge(:q=>nil, :action=>'index')))
48
- else
49
- "".html_safe
50
- end
36
+ return "".html_safe if localized_params[:q].blank?
37
+
38
+ render_constraint_element(constraint_query_label(localized_params),
39
+ localized_params[:q],
40
+ :classes => ["query"],
41
+ :remove => url_for(localized_params.merge(:q=>nil, :action=>'index')))
51
42
  end
52
43
 
53
44
  ##
@@ -76,8 +67,8 @@ module Blacklight::RenderConstraintsHelperBehavior
76
67
  facet_config = facet_configuration_for_field(facet)
77
68
 
78
69
  safe_join(values.map do |val|
79
- render_constraint_element( blacklight_config.facet_fields[facet].label,
80
- facet_display_value(facet, val),
70
+ next if val.blank? # skip empty string
71
+ render_constraint_element( facet_field_label(facet), facet_display_value(facet, val),
81
72
  :remove => search_action_path(remove_facet_params(facet, val, localized_params)),
82
73
  :classes => ["filter", "filter-" + facet.parameterize]
83
74
  )
@@ -1,34 +1,33 @@
1
- <%- # local params:
2
- # label
1
+ <% # local params:
2
+ # label
3
3
  # value
4
4
  # options =>
5
5
  # :remove => url for a remove constraint link
6
6
  # :classes => array of classes to add to container span
7
7
  options ||= {}
8
- -%>
8
+ %>
9
9
 
10
10
  <span class="btn-group appliedFilter constraint <%= options[:classes].join(" ") if options[:classes] %>">
11
- <a href="#" class="constraint-value btn btn-sm btn-default btn-disabled">
12
- <%- unless label.blank? -%>
13
- <span class="filterName"><%= label %></span>
14
- <%- end -%>
15
- <%- unless value.blank? -%>
16
- <span class="filterValue"><%= value %></span>
17
- <%- end -%>
18
- </a>
11
+ <span class="constraint-value btn btn-sm btn-default btn-disabled">
12
+ <% unless label.blank? %>
13
+ <span class="filterName"><%= label %></span>
14
+ <% end %>
15
+ <% unless value.blank? %>
16
+ <span class="filterValue"><%= value %></span>
17
+ <% end %>
18
+ </span>
19
+ <% unless options[:remove].blank? %>
20
+ <% accessible_remove_label = content_tag :span, class: 'sr-only' do
21
+ if label.blank?
22
+ t('blacklight.search.filters.remove.value', value: value)
23
+ else
24
+ t('blacklight.search.filters.remove.label_value', label: label, value: value)
25
+ end
26
+ end
27
+ %>
19
28
 
20
- <%- unless options[:remove].blank? -%>
21
- <% accessible_remove_label = content_tag :span, :class => 'sr-only' do
22
- if label.blank?
23
- t('blacklight.search.filters.remove.value', :value => value)
24
- else
25
- t('blacklight.search.filters.remove.label_value', :label => label, :value => value)
26
- end
27
- end
28
- %>
29
-
30
- <%= link_to(content_tag(:span, '', :class => 'glyphicon glyphicon-remove') + accessible_remove_label,
31
- options[:remove], :class => 'btn btn-default btn-sm remove dropdown-toggle'
32
- ) %>
33
- <%- end -%>
29
+ <%= link_to(content_tag(:span, '', class: 'glyphicon glyphicon-remove') + accessible_remove_label,
30
+ options[:remove], class: 'btn btn-default btn-sm remove dropdown-toggle'
31
+ ) %>
32
+ <%- end -%>
34
33
  </span>
@@ -1,18 +1,9 @@
1
1
  <ul class="facet-values list-unstyled">
2
- <% paginator = facet_paginator(facet_field, display_facet)
3
- %>
4
- <% paginator.items.each do |item| -%>
5
- <li>
6
- <% if facet_in_params?( solr_field, item.value ) %>
7
- <%= render_selected_facet_value(solr_field, item) %>
8
- <% else %>
9
- <%= render_facet_value(solr_field, item) %>
10
- <% end -%>
11
- </li>
12
- <% end %>
2
+ <% paginator = facet_paginator(facet_field, display_facet) %>
3
+ <%= render_facet_limit_list paginator, solr_field %>
13
4
 
14
- <% if paginator.has_next? and params[:action] != "facet" %>
15
- <li class="more_facets_link"><%= link_to(t('blacklight.search.facets.more'), params.merge(:id => solr_field, :action=>"facet", :page => nil), :class => "more_facets_link") %></li>
5
+ <% unless paginator.last_page? || params[:action] == "facet" %>
6
+ <li class="more_facets_link"><%= link_to t('blacklight.search.facets.more'),
7
+ params.merge(id: solr_field, action: "facet", page: nil), class: "more_facets_link" %></li>
16
8
  <% end %>
17
-
18
9
  </ul>
@@ -0,0 +1,25 @@
1
+ <h2 class="sr-only top-content-title"><%= t('blacklight.search.search_results_header') %></h2>
2
+
3
+ <% @page_title = t('blacklight.search.title', :application_name => application_name) %>
4
+
5
+
6
+ <% content_for(:head) do -%>
7
+ <%= render_opensearch_response_metadata %>
8
+ <%= auto_discovery_link_tag(:rss, url_for(params.merge(:format => 'rss')), :title => t('blacklight.search.rss_feed') ) %>
9
+ <%= auto_discovery_link_tag(:atom, url_for(params.merge(:format => 'atom')), :title => t('blacklight.search.atom_feed') ) %>
10
+ <% end -%>
11
+
12
+
13
+ <%= render 'search_header' %>
14
+
15
+ <h2 class="sr-only"><%= t('blacklight.search.search_results') %></h2>
16
+
17
+ <%- if @response.empty? %>
18
+ <%= render "zero_results" %>
19
+ <%- elsif render_grouped_response? %>
20
+ <%= render_grouped_document_index %>
21
+ <%- else %>
22
+ <%= render_document_index %>
23
+ <%- end %>
24
+
25
+ <%= render 'results_pagination' %>
@@ -1,41 +1,12 @@
1
- <div id="sidebar" class="col-md-3">
2
- <%= render 'search_sidebar' %>
1
+ <div id="sidebar" class="col-md-3 col-sm-4">
2
+ <%= render 'search_sidebar' %>
3
3
  </div>
4
4
 
5
- <div id="content" class="col-md-9">
6
-
7
- <% unless has_search_parameters? %>
8
- <%# if there are no input/search related params, display the "home" partial -%>
9
- <%= render 'home' %>
10
- <% else %>
11
-
12
- <h2 class="sr-only top-content-title"><%= t('blacklight.search.search_results_header') %></h2>
13
-
14
- <% @page_title = t('blacklight.search.title', :application_name => application_name) %>
15
-
16
-
17
- <% content_for(:head) do -%>
18
- <%= render_opensearch_response_metadata %>
19
- <%= auto_discovery_link_tag(:rss, url_for(params.merge(:format => 'rss')), :title => t('blacklight.search.rss_feed') ) %>
20
- <%= auto_discovery_link_tag(:atom, url_for(params.merge(:format => 'atom')), :title => t('blacklight.search.atom_feed') ) %>
21
- <% end -%>
22
-
23
-
24
- <%= render 'search_header' %>
25
-
26
- <h2 class="sr-only"><%= t('blacklight.search.search_results') %></h2>
27
-
28
- <%- if @response.empty? %>
29
- <%= render "zero_results" %>
30
- <%- elsif render_grouped_response? %>
31
- <%= render_grouped_document_index %>
32
- <%- else %>
33
- <%= render_document_index %>
34
- <%- end %>
35
-
36
- <%= render 'results_pagination' %>
37
-
38
-
39
- <% end %>
40
-
5
+ <div id="content" class="col-md-9 col-sm-8">
6
+ <% unless has_search_parameters? %>
7
+ <%# if there are no input/search related params, display the "home" partial -%>
8
+ <%= render 'home' %>
9
+ <% else %>
10
+ <%= render 'search_results' %>
11
+ <% end %>
41
12
  </div>
data/blacklight.gemspec CHANGED
@@ -26,7 +26,8 @@ Gem::Specification.new do |s|
26
26
 
27
27
  s.add_development_dependency "jettywrapper", ">= 1.7.0"
28
28
  s.add_development_dependency "blacklight-marc", "~> 5.0"
29
- s.add_development_dependency "rspec-rails"
29
+ s.add_development_dependency "rspec-rails", "~> 2.99"
30
+ s.add_development_dependency "rspec-its"
30
31
  s.add_development_dependency "capybara"
31
32
  s.add_development_dependency "poltergeist"
32
33
  s.add_development_dependency 'engine_cart', ">= 0.1.0"
@@ -121,6 +121,7 @@ module Blacklight
121
121
 
122
122
  f_request_params.each_pair do |facet_field, value_list|
123
123
  Array(value_list).each do |value|
124
+ next if value.blank? # skip empty strings
124
125
  solr_parameters.append_filter_query facet_value_to_fq_string(facet_field, value)
125
126
  end
126
127
  end
@@ -12,6 +12,10 @@ module Blacklight::Solr
12
12
  # so we cannot know how many "pages" there are.
13
13
  #
14
14
  class FacetPaginator
15
+ extend Deprecation
16
+
17
+ self.deprecation_horizon = 'blacklight version 6.0.0'
18
+
15
19
  # What request keys will we use for the parameters need. Need to
16
20
  # make sure they do NOT conflict with catalog/index request params,
17
21
  # and need to make them accessible in a list so we can easily
@@ -21,7 +25,7 @@ module Blacklight::Solr
21
25
  class << self; attr_accessor :request_keys end # create a class method
22
26
  def request_keys ; self.class.request_keys ; end # shortcut
23
27
 
24
- attr_reader :total, :items, :offset, :limit, :sort
28
+ attr_reader :total_count, :items, :offset, :limit, :sort
25
29
 
26
30
  # all_facet_values is a list of facet value objects returned by solr,
27
31
  # asking solr for n+1 facet values.
@@ -33,54 +37,72 @@ module Blacklight::Solr
33
37
  def initialize(all_facet_values, arguments)
34
38
  # to_s.to_i will conveniently default to 0 if nil
35
39
  @offset = arguments[:offset].to_s.to_i
36
- @limit = arguments[:limit].to_s.to_i if arguments[:limit]
40
+ @limit = arguments[:limit].to_s.to_i
37
41
  # count is solr's default
38
42
  @sort = arguments[:sort] || "count"
39
-
40
- total = all_facet_values.size
41
- if (@limit)
42
- @items = all_facet_values.slice(0, @limit)
43
- @has_next = total > @limit
44
- @has_previous = @offset > 0
45
- else # nil limit
46
- @items = all_facet_values
47
- @has_next = false
48
- @has_previous = false
49
- end
43
+ @total_count = all_facet_values.size
44
+ @items = items_for_limit(all_facet_values)
45
+ end
46
+
47
+ def prev_page
48
+ current_page - 1 unless first_page?
50
49
  end
51
50
 
52
51
  def current_page
53
- 1 + @offset/@limit
52
+ if limit == 0 #check for divide by zero
53
+ 1
54
+ else
55
+ @offset / limit + 1
56
+ end
57
+ end
58
+
59
+ def next_page
60
+ current_page + 1 unless last_page?
54
61
  end
55
62
 
63
+ #@deprecated
56
64
  def has_next?
57
- @has_next
65
+ !last_page?
58
66
  end
67
+ deprecation_deprecate :has_next?
59
68
 
69
+ #@deprecated
60
70
  def has_previous?
61
- @has_previous
71
+ !first_page?
62
72
  end
73
+ deprecation_deprecate :has_next?
63
74
 
64
75
  def last_page?
65
- !has_next?
76
+ current_page >= total_pages
66
77
  end
67
78
 
68
79
  def first_page?
69
- !has_previous?
80
+ current_page == 1
70
81
  end
71
82
 
83
+ def total_pages
84
+ if limit == 0 #check for divide by zero
85
+ 1
86
+ else
87
+ (total_count.to_f / limit).ceil
88
+ end
89
+ end
72
90
 
73
- # Pass in a desired solr facet solr key ('count' or 'index', see
74
- # http://wiki.apache.org/solr/SimpleFacetParameters#facet.limit
75
- # under facet.sort ), and your current request params.
76
- # Get back params suitable to passing to an ActionHelper method for
77
- # creating a url, to resort by that method.
78
- def params_for_resort_url(sort_method, params)
79
- # When resorting, we've got to reset the offset to start at beginning,
80
- # no way to make it make sense otherwise.
81
- return params.merge(request_keys[:sort] => sort_method, request_keys[:page] => nil)
82
- end
83
-
91
+ # Pass in a desired solr facet solr key ('count' or 'index', see
92
+ # http://wiki.apache.org/solr/SimpleFacetParameters#facet.limit
93
+ # under facet.sort ), and your current request params.
94
+ # Get back params suitable to passing to an ActionHelper method for
95
+ # creating a url, to resort by that method.
96
+ def params_for_resort_url(sort_method, params)
97
+ # When resorting, we've got to reset the offset to start at beginning,
98
+ # no way to make it make sense otherwise.
99
+ params.merge(request_keys[:sort] => sort_method, request_keys[:page] => nil)
100
+ end
101
+
102
+ private
103
+ # setting limit to 0 implies no limit
104
+ def items_for_limit(values)
105
+ limit != 0 ? values.slice(offset, limit) : values
106
+ end
84
107
  end
85
-
86
108
  end
@@ -17,7 +17,7 @@ describe FacetsHelper do
17
17
  empty = double(:items => [])
18
18
 
19
19
  fields = [a,b,empty]
20
- expect(helper.has_facet_values?(fields)).to be_true
20
+ expect(helper.has_facet_values?(fields)).to be true
21
21
  end
22
22
 
23
23
  it "should be false if all facets are empty" do
@@ -25,7 +25,7 @@ describe FacetsHelper do
25
25
  empty = double(:items => [])
26
26
 
27
27
  fields = [empty]
28
- expect(helper.has_facet_values?(fields)).to be_false
28
+ expect(helper.has_facet_values?(fields)).to be false
29
29
  end
30
30
  end
31
31
 
@@ -45,37 +45,37 @@ describe FacetsHelper do
45
45
 
46
46
  it "should render facets with items" do
47
47
  a = double(:items => [1,2], :name=>'basic_field')
48
- expect(helper.should_render_facet?(a)).to be_true
48
+ expect(helper.should_render_facet?(a)).to be true
49
49
  end
50
50
  it "should not render facets without items" do
51
51
  empty = double(:items => [], :name=>'basic_field')
52
- expect(helper.should_render_facet?(empty)).to be_false
52
+ expect(helper.should_render_facet?(empty)).to be false
53
53
  end
54
54
 
55
55
  it "should not render facets where show is set to false" do
56
56
  a = double(:items => [1,2], :name=>'no_show')
57
- expect(helper.should_render_facet?(a)).to be_false
57
+ expect(helper.should_render_facet?(a)).to be false
58
58
  end
59
59
 
60
60
  it "should call a helper to determine if it should render a field" do
61
61
  helper.stub(:my_helper => true)
62
62
  a = double(:items => [1,2], :name=>'helper_show')
63
- expect(helper.should_render_facet?(a)).to be_true
63
+ expect(helper.should_render_facet?(a)).to be true
64
64
  end
65
65
 
66
66
  it "should call a helper to determine if it should render a field" do
67
67
  a = double(:items => [1,2], :name=>'helper_with_an_arg_show')
68
68
  helper.should_receive(:my_helper_with_an_arg).with(@config.facet_fields['helper_with_an_arg_show'], a).and_return(true)
69
- expect(helper.should_render_facet?(a)).to be_true
69
+ expect(helper.should_render_facet?(a)).to be true
70
70
  end
71
71
 
72
72
 
73
73
  it "should evaluate a Proc to determine if it should render a field" do
74
74
  a = double(:items => [1,2], :name=>'lambda_show')
75
- expect(helper.should_render_facet?(a)).to be_true
75
+ expect(helper.should_render_facet?(a)).to be true
76
76
 
77
77
  a = double(:items => [1,2], :name=>'lambda_no_show')
78
- expect(helper.should_render_facet?(a)).to be_false
78
+ expect(helper.should_render_facet?(a)).to be false
79
79
  end
80
80
  end
81
81
 
@@ -90,17 +90,17 @@ describe FacetsHelper do
90
90
  end
91
91
 
92
92
  it "should be collapsed by default" do
93
- expect(helper.should_collapse_facet?(@config.facet_fields['basic_field'])).to be_true
93
+ expect(helper.should_collapse_facet?(@config.facet_fields['basic_field'])).to be true
94
94
  end
95
95
 
96
96
  it "should not be collapsed if the configuration says so" do
97
- expect(helper.should_collapse_facet?(@config.facet_fields['no_collapse'])).to be_false
97
+ expect(helper.should_collapse_facet?(@config.facet_fields['no_collapse'])).to be false
98
98
  end
99
99
 
100
100
  it "should not be collapsed if it is in the params" do
101
101
  params[:f] = { basic_field: [1], no_collapse: [2] }.with_indifferent_access
102
- expect(helper.should_collapse_facet?(@config.facet_fields['basic_field'])).to be_false
103
- expect(helper.should_collapse_facet?(@config.facet_fields['no_collapse'])).to be_false
102
+ expect(helper.should_collapse_facet?(@config.facet_fields['basic_field'])).to be false
103
+ expect(helper.should_collapse_facet?(@config.facet_fields['no_collapse'])).to be false
104
104
  end
105
105
 
106
106
  end
@@ -152,7 +152,7 @@ describe FacetsHelper do
152
152
  field.should be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
153
153
 
154
154
  expect(field.name).to eq'my_query_facet_field'
155
- expect(field.items).to have(2).items
155
+ expect(field.items.size).to eq 2
156
156
  expect(field.items.map { |x| x.value }).to_not include 'field:not_appearing_in_the_config'
157
157
 
158
158
  facet_item = field.items.select { |x| x.value == 'a_simple_query' }.first
@@ -180,11 +180,11 @@ describe FacetsHelper do
180
180
 
181
181
  expect(field.name).to eq 'my_pivot_facet_field'
182
182
 
183
- expect(field.items).to have(1).item
183
+ expect(field.items.size).to eq 1
184
184
 
185
185
  expect(field.items.first).to respond_to(:items)
186
186
 
187
- expect(field.items.first.items).to have(1).item
187
+ expect(field.items.first.items.size).to eq 1
188
188
  expect(field.items.first.items.first.fq).to eq({ 'field_a' => 'a' })
189
189
  end
190
190
  end
@@ -281,11 +281,40 @@ describe FacetsHelper do
281
281
  end
282
282
  end
283
283
 
284
+ describe "render_facet_limit_list" do
285
+ let(:f1) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '792', value: 'Book') }
286
+ let(:f2) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '65', value: 'Musical Score') }
287
+ let(:paginator) { Blacklight::Solr::FacetPaginator.new([f1, f2], limit: 10) }
288
+ subject { helper.render_facet_limit_list(paginator, 'type_solr_field') }
289
+ before do
290
+ allow(helper).to receive(:search_action_path) do |*args|
291
+ catalog_index_path *args
292
+ end
293
+ end
294
+ it "should draw a list of elements" do
295
+ expect(subject).to have_selector 'li', count: 2
296
+ expect(subject).to have_selector 'li:first-child a.facet_select', text: 'Book'
297
+ expect(subject).to have_selector 'li:nth-child(2) a.facet_select', text: 'Musical Score'
298
+ end
299
+
300
+ context "when one of the facet items is rendered as nil" do
301
+ # An app may override render_facet_item to filter out some undesired facet items by returning nil.
302
+
303
+ before { allow(helper).to receive(:render_facet_item).and_return("<a class=\"facet_select\">Book</a>".html_safe, nil) }
304
+
305
+ it "should draw a list of elements" do
306
+ expect(subject).to have_selector 'li', count: 1
307
+ expect(subject).to have_selector 'li:first-child a.facet_select', text: 'Book'
308
+ end
309
+
310
+ end
311
+ end
312
+
284
313
  describe "facet_field_in_params?" do
285
314
  it "should check if the facet field is selected in the user params" do
286
315
  helper.stub(:params => { :f => { "some-field" => ["x"]}})
287
- expect(helper.facet_field_in_params?("some-field")).to be_true
288
- expect(helper.facet_field_in_params?("other-field")).to_not be_true
316
+ expect(helper.facet_field_in_params?("some-field")).to be_truthy
317
+ expect(helper.facet_field_in_params?("other-field")).to_not be true
289
318
  end
290
319
  end
291
320
 
@@ -300,7 +329,7 @@ describe FacetsHelper do
300
329
  helper.should_receive(:facet_display_value).and_return('Z')
301
330
  helper.should_receive(:add_facet_params_and_redirect).and_return({controller:'catalog'})
302
331
 
303
- helper.stub(:search_action_path) do |*args|
332
+ allow(helper).to receive(:search_action_path) do |*args|
304
333
  catalog_index_path *args
305
334
  end
306
335
  end
@@ -2,6 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe RenderConstraintsHelper do
4
4
 
5
+ let(:config) do
6
+ Blacklight::Configuration.new do |config|
7
+ config.add_facet_field 'type'
8
+ end
9
+ end
10
+
5
11
  before do
6
12
  # the helper methods below infer paths from the current route
7
13
  controller.request.path_parameters["controller"] = 'catalog'
@@ -18,15 +24,25 @@ describe RenderConstraintsHelper do
18
24
 
19
25
  describe '#render_filter_element' do
20
26
  before do
21
- @config = Blacklight::Configuration.new do |config|
22
- config.add_facet_field 'type'
23
- end
24
- helper.stub(:blacklight_config => @config)
27
+ allow(helper).to receive(:blacklight_config).and_return(config)
28
+ expect(helper).to receive(:facet_field_label).with('type').and_return("Item Type")
25
29
  end
30
+ subject { helper.render_filter_element('type', ['journal'], {:q=>'biz'}) }
31
+
26
32
  it "should have a link relative to the current url" do
27
- result = helper.render_filter_element('type', ['journal'], {:q=>'biz'})
28
- expect(result).to have_link "Remove constraint Type: journal", href: "/catalog?q=biz"
33
+ expect(subject).to have_link "Remove constraint Item Type: journal", href: "/catalog?q=biz"
34
+ expect(subject).to have_selector ".filterName", text: 'Item Type'
29
35
  end
30
36
  end
31
37
 
38
+ describe "#render_constraints_filters" do
39
+ before do
40
+ allow(helper).to receive(:blacklight_config).and_return(config)
41
+ end
42
+ subject { helper.render_constraints_filters(:f=>{'type'=>['']}) }
43
+
44
+ it "should render nothing for empty facet limit param" do
45
+ expect(subject).to be_blank
46
+ end
47
+ end
32
48
  end
@@ -1,75 +1,67 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Blacklight::Solr::FacetPaginator' do
4
- before(:all) do
5
- require 'yaml'
6
- @seven_facet_values = YAML::load("--- \n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 792\n value: Book\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 65\n value: Musical Score\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 58\n value: Serial\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 48\n value: Musical Recording\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 37\n value: Microform\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 27\n value: Thesis\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 0\n value: \n")
7
- @six_facet_values = @seven_facet_values.slice(1,6)
8
- @limit = 6
9
4
 
10
- @sort_key = Blacklight::Solr::FacetPaginator.request_keys[:sort]
11
- @page_key = Blacklight::Solr::FacetPaginator.request_keys[:page]
12
- end
13
- context 'when there are limit+1 results' do
14
- before(:each) do
15
- @paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :limit => 6)
16
- end
17
- it 'should have next' do
18
- expect(@paginator).to have_next
19
- end
5
+ let(:f1) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '792', value: 'Book') }
6
+ let(:f2) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '65', value: 'Musical Score') }
7
+ let(:f3) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '58', value: 'Serial') }
8
+ let(:f4) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '48', value: 'Musical Recording') }
9
+ let(:f5) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '37', value: 'Microform') }
10
+ let(:f6) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '27', value: 'Thesis') }
11
+ let(:f7) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '0') }
12
+ let(:seven_facet_values) { [f1, f2, f3, f4, f5, f6, f7] }
13
+ let(:six_facet_values) { [f1, f2, f3, f4, f5, f6] }
14
+ let(:limit) { 6 }
20
15
 
16
+ context 'on the first page of two pages' do
17
+ subject { Blacklight::Solr::FacetPaginator.new(seven_facet_values, limit: limit) }
18
+ it { should be_first_page }
19
+ it { should_not be_last_page }
20
+ its(:current_page) { should eq 1 }
21
+ its(:prev_page) { should be_nil }
22
+ its(:next_page) { should eq 2 }
23
+ it 'should limit items to limit, if limit is smaller than items.length' do
24
+ expect(subject.items.size).to eq 6
25
+ end
21
26
  end
22
- it 'should not have next when there are fewer results' do
23
- paginator = Blacklight::Solr::FacetPaginator.new(@six_facet_values, :offset => 0, :limit => @limit)
24
27
 
25
- expect(paginator).not_to have_next
26
- end
27
- context 'when offset is greater than 0' do
28
- before(:each) do
29
- @offset = 100
30
- @paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => @offset, :limit => @limit)
31
- end
32
-
33
- it 'should have previous' do
34
- expect(@paginator).to have_previous
28
+ context 'on the last page of two pages' do
29
+ subject { Blacklight::Solr::FacetPaginator.new(seven_facet_values, offset: 6, limit: limit) }
30
+ it { should_not be_first_page }
31
+ it { should be_last_page }
32
+ its(:current_page) { should eq 2 }
33
+ its(:prev_page) { should eq 1 }
34
+ its(:next_page) { should be_nil }
35
+ it 'should return all items when limit is greater than items.length' do
36
+ expect(subject.items.size).to eq 1
35
37
  end
36
-
37
38
  end
38
- it 'should not have previous when offset is 0' do
39
- paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 0, :limit => @limit)
40
39
 
41
- expect(paginator).not_to have_previous
40
+ context 'on the first page of one page' do
41
+ subject { Blacklight::Solr::FacetPaginator.new(six_facet_values, offset: 0, limit: limit) }
42
+ it { should be_first_page }
43
+ it { should be_last_page }
42
44
  end
43
- it 'should know a manually set sort, and produce proper sort url' do
44
- paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 100, :limit => @limit, :sort => 'index')
45
45
 
46
- expect(paginator.sort).to eq 'index'
47
-
48
- click_params = paginator.params_for_resort_url('count', {})
46
+ describe "params_for_resort_url" do
47
+ let(:sort_key) { Blacklight::Solr::FacetPaginator.request_keys[:sort] }
48
+ let(:page_key) { Blacklight::Solr::FacetPaginator.request_keys[:page] }
49
+ let(:paginator) { Blacklight::Solr::FacetPaginator.new(seven_facet_values, offset: 100, limit: limit, sort: 'index') }
49
50
 
50
- expect(click_params[ @sort_key ]).to eq 'count'
51
- expect(click_params[ @page_key ]).to be_nil
52
- end
53
- it 'should limit items to limit, if limit is smaller than items.length' do
54
- paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 100, :limit => 6, :sort => 'index')
55
- expect(paginator.items).to have(6).items
56
- end
57
- it 'should return all items when limit is greater than items.length' do
58
- paginator = Blacklight::Solr::FacetPaginator.new(@six_facet_values, :offset => 100, :limit => 6, :sort => 'index')
59
- expect(paginator.items).to have(6).items
60
- end
61
- describe "for a nil :limit" do
62
- before(:all) do
63
- @paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 100, :limit => nil, :sort => 'index')
64
- end
65
- it 'should return all items' do
66
- expect(@paginator.items).to eq @seven_facet_values
67
- end
68
- it 'should not has_next?' do
69
- expect(@paginator).not_to have_next
51
+ it 'should know a manually set sort, and produce proper sort url' do
52
+ expect(paginator.sort).to eq 'index'
53
+
54
+ click_params = paginator.params_for_resort_url('count', {})
55
+
56
+ expect(click_params[ sort_key ]).to eq 'count'
57
+ expect(click_params[ page_key ]).to be_nil
70
58
  end
71
- it 'should not has_previous?' do
72
- expect(@paginator).not_to have_previous
59
+ end
60
+
61
+ context "for a nil :limit" do
62
+ subject { Blacklight::Solr::FacetPaginator.new(seven_facet_values, offset: 0, limit: nil) }
63
+ it "should return all the items" do
64
+ expect(subject.items).to eq seven_facet_values
73
65
  end
74
66
  end
75
67
 
@@ -191,6 +191,14 @@ describe Blacklight::SolrHelper do
191
191
  end
192
192
  end
193
193
 
194
+ describe "for an empty facet limit param" do
195
+ it "should not add any fq to solr" do
196
+ solr_params = subject.solr_search_params(:f => {"format" => [""]})
197
+
198
+ expect(solr_params[:fq]).to be_blank
199
+ end
200
+ end
201
+
194
202
  describe "with Multi Facets, No Query" do
195
203
  it 'should have fq set properly' do
196
204
  solr_params = subject.solr_search_params(:f => @multi_facets)
data/spec/spec_helper.rb CHANGED
@@ -22,6 +22,7 @@ require 'engine_cart'
22
22
  EngineCart.load_application!
23
23
 
24
24
  require 'rspec/rails'
25
+ require 'rspec/its'
25
26
  require 'capybara/rspec'
26
27
  require 'capybara/poltergeist'
27
28
 
@@ -43,15 +44,6 @@ end
43
44
  Dir[Pathname.new(File.expand_path("../support/**/*.rb", __FILE__))].each {|f| require f}
44
45
 
45
46
  RSpec.configure do |config|
46
- # == Mock Framework
47
- #
48
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
49
- #
50
- # config.mock_with :mocha
51
- # config.mock_with :flexmock
52
- # config.mock_with :rr
53
- config.mock_with :rspec
54
-
55
47
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
56
48
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
57
49
 
@@ -61,4 +53,5 @@ RSpec.configure do |config|
61
53
  config.use_transactional_fixtures = true
62
54
 
63
55
  config.include Devise::TestHelpers, type: :controller
56
+ config.infer_spec_type_from_file_location!
64
57
  end
@@ -7,8 +7,10 @@ describe "catalog/_constraints_element.html.erb" do
7
7
  end
8
8
  it "should render label and value" do
9
9
  expect(rendered).to have_selector("span.appliedFilter.constraint") do |s|
10
+ expect(s).to have_css("span.constraint-value")
11
+ expect(s).to_not have_css("a.constraint-value")
10
12
  expect(s).to have_selector "span.filterName", :content => "my label"
11
- expect(s).to have_selector "span.filterValue", :content => "my value"
13
+ expect(s).to have_selector "span.filterValue", :content => "my value"
12
14
  end
13
15
  end
14
16
  end
@@ -20,7 +22,7 @@ describe "catalog/_constraints_element.html.erb" do
20
22
  it "should include remove link" do
21
23
  expect(rendered).to have_selector("span.appliedFilter") do |s|
22
24
  expect(s).to have_selector(".remove[href='http://remove']")
23
- end
25
+ end
24
26
  end
25
27
 
26
28
  it "should have an accessible remove label" do
@@ -37,7 +39,7 @@ describe "catalog/_constraints_element.html.erb" do
37
39
  it "should not include checkmark" do
38
40
  expect(rendered).to have_selector("span.appliedFilter") do |s|
39
41
  expect(s).to_not have_selector("img[src$='checkmark.gif']")
40
- end
42
+ end
41
43
  end
42
44
  end
43
45
 
@@ -60,6 +62,6 @@ describe "catalog/_constraints_element.html.erb" do
60
62
  end
61
63
 
62
64
  end
63
-
65
+
64
66
 
65
67
  end
data/template.demo.rb CHANGED
@@ -3,13 +3,17 @@ gem "blacklight", ">= 5.3.0"
3
3
  run "bundle install"
4
4
 
5
5
  # run the blacklight install generator
6
- generate 'blacklight:install', '--devise --marc --jettywrapper'
6
+ options = ENV.fetch("BLACKLIGHT_INSTALL_OPTIONS", '--devise --marc --jettywrapper')
7
+
8
+ generate 'blacklight:install', options
7
9
 
8
10
  # run the database migrations
9
11
  rake "db:migrate"
10
12
 
11
13
  # index some data
12
- rake "jetty:clean"
13
- rake "jetty:start"
14
- rake "blacklight:solr:seed"
15
- rake "jetty:stop"
14
+ if options =~ /jettywrapper/
15
+ rake "jetty:clean"
16
+ rake "jetty:start"
17
+ rake "blacklight:solr:seed"
18
+ rake "jetty:stop"
19
+ end
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: 5.4.0
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
- date: 2014-05-05 00:00:00.000000000 Z
20
+ date: 2014-07-07 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -139,6 +139,20 @@ dependencies:
139
139
  version: '5.0'
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: rspec-rails
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '2.99'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '2.99'
154
+ - !ruby/object:Gem::Dependency
155
+ name: rspec-its
142
156
  requirement: !ruby/object:Gem::Requirement
143
157
  requirements:
144
158
  - - ">="
@@ -308,6 +322,7 @@ files:
308
322
  - app/views/catalog/_results_pagination.html.erb
309
323
  - app/views/catalog/_search_form.html.erb
310
324
  - app/views/catalog/_search_header.html.erb
325
+ - app/views/catalog/_search_results.html.erb
311
326
  - app/views/catalog/_search_sidebar.html.erb
312
327
  - app/views/catalog/_show_default.html.erb
313
328
  - app/views/catalog/_show_header_default.html.erb