blacklight 5.10.3 → 5.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -2
  3. data/VERSION +1 -1
  4. data/app/assets/stylesheets/blacklight/_catalog.scss +1 -1
  5. data/app/helpers/blacklight/catalog_helper_behavior.rb +5 -0
  6. data/app/helpers/blacklight/component_helper_behavior.rb +4 -4
  7. data/app/helpers/blacklight/configuration_helper_behavior.rb +18 -5
  8. data/app/helpers/blacklight/url_helper_behavior.rb +1 -6
  9. data/app/views/bookmarks/index.html.erb +3 -3
  10. data/app/views/catalog/_bookmark_control.html.erb +1 -1
  11. data/app/views/catalog/_document_list.html.erb +2 -2
  12. data/app/views/catalog/_facet_layout.html.erb +2 -1
  13. data/app/views/catalog/_facets.html.erb +2 -1
  14. data/app/views/catalog/_home_text.html.erb +3 -3
  15. data/app/views/catalog/_index_header_default.html.erb +20 -17
  16. data/app/views/catalog/_sms_form.html.erb +1 -1
  17. data/app/views/catalog/_view_type_group.html.erb +3 -3
  18. data/app/views/layouts/blacklight.html.erb +2 -0
  19. data/app/views/saved_searches/index.html.erb +6 -4
  20. data/app/views/search_history/index.html.erb +3 -3
  21. data/lib/blacklight/configuration/facet_field.rb +1 -1
  22. data/lib/blacklight/configuration/search_field.rb +1 -1
  23. data/lib/blacklight/document.rb +6 -24
  24. data/lib/blacklight/document_presenter.rb +4 -2
  25. data/lib/blacklight/facet.rb +11 -11
  26. data/lib/blacklight/search_builder.rb +16 -6
  27. data/lib/blacklight/solr/search_builder.rb +3 -1
  28. data/spec/helpers/blacklight_helper_spec.rb +12 -1
  29. data/spec/helpers/catalog_helper_spec.rb +18 -0
  30. data/spec/helpers/configuration_helper_spec.rb +9 -7
  31. data/spec/helpers/facets_helper_spec.rb +4 -3
  32. data/spec/helpers/url_helper_spec.rb +0 -11
  33. data/spec/lib/blacklight/configuration_spec.rb +6 -33
  34. data/spec/lib/blacklight/facet_spec.rb +34 -0
  35. data/spec/lib/blacklight/search_builder_spec.rb +8 -0
  36. data/spec/lib/blacklight/solr/search_builder_spec.rb +7 -0
  37. data/spec/lib/document_presenter_spec.rb +7 -0
  38. data/spec/views/catalog/_document_list.html.erb_spec.rb +8 -3
  39. data/spec/views/catalog/_facets.html.erb_spec.rb +3 -3
  40. data/spec/views/catalog/_index_header_default.html.erb_spec.rb +22 -6
  41. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +4 -0
  42. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d8ff5b59fd2f2f4492d6a334429e34d65eecb73
4
- data.tar.gz: 1c5518ceb4bbba537374113d4ba12830276dcb50
3
+ metadata.gz: 306445f3c792d11626c44500a5b30d974c01f5df
4
+ data.tar.gz: da7aa72df29cc2dd70ec8779d72928e8916d340a
5
5
  SHA512:
6
- metadata.gz: 56d549c7e95d7a3bc1aef93b961e8403a9697e07562c5f76e5f16da795d9545de919fec3455b31ee1453a323a16db89486f166774ce7568b84d703b5cce3ad03
7
- data.tar.gz: 51b5768632c4336d9b1242d3b3872cd97de4e8e6ecf42b7d01d3e43d052d06d515e7dba26a1d60aba9d7c61d3dfd26851298b86d9254107d7b445c788503dffe
6
+ metadata.gz: 01e02b3b3605264f5bb0517a6abeec089e4b2eb8d96e604572808e6f805e59dfd448cedd6c35a311d436e2753ef6cc780e0fdf4d3c64e86101a6bab38fae1173
7
+ data.tar.gz: b95b6dc21666c74b2ba5c6103fc555300a559340efcc5e0b9315cf5f019c8de0d098e33d72cde8bfce43a0330fbab87d226697f6530783ebbd98dc1aa79ef586
data/.travis.yml CHANGED
@@ -15,8 +15,6 @@ matrix:
15
15
  env: "RAILS_VERSION=4.1.9"
16
16
  - rvm: 2.1.5
17
17
  env: "RAILS_VERSION=4.2.0"
18
- - rvm: 2.1.5
19
- env: "RAILS_VERSION=4.2.1"
20
18
  - rvm: jruby
21
19
  env: "RAILS_VERSION=4.2.0 JRUBY_OPTS=\"-J-Xms512m -J-Xmx1024m\""
22
20
  - rvm: 1.9.3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.10.3
1
+ 5.11.0
@@ -101,7 +101,7 @@ span.constraints-label {
101
101
  border-bottom:1px dotted $table-border-color;
102
102
  @extend .clearfix;
103
103
  }
104
- }
104
+ }
105
105
 
106
106
  // Tools link on documetn show page
107
107
  .show-tools {
@@ -223,6 +223,10 @@ module Blacklight::CatalogHelperBehavior
223
223
  response ||= @response
224
224
  @current_bookmarks ||= current_or_guest_user.bookmarks_for_documents(response.documents).to_a
225
225
  end
226
+
227
+ def is_bookmarked? document
228
+ current_bookmarks.any? { |x| x.document_id == document.id and x.document_type == document.class }
229
+ end
226
230
 
227
231
  def render_marc_tools
228
232
  return unless defined? Blacklight::Marc
@@ -247,4 +251,5 @@ module Blacklight::CatalogHelperBehavior
247
251
  def render_librarian_view_control? config, options = {}
248
252
  respond_to? :librarian_view_catalog_path and options[:document] and options[:document].respond_to?(:to_marc)
249
253
  end
254
+
250
255
  end
@@ -29,8 +29,8 @@ module Blacklight
29
29
  # @return [String]
30
30
  def render_index_doc_actions(document, options={})
31
31
  wrapping_class = options.delete(:wrapping_class) || "index-document-functions"
32
- rendered = render_filtered_partials(blacklight_config.index.document_actions, { document: document }.merge(options))
33
- content_tag("div", rendered, class: wrapping_class)
32
+ rendered = render_filtered_partials(blacklight_config.view_config(document_index_view_type).document_actions, { document: document }.merge(options))
33
+ content_tag("div", rendered, class: wrapping_class) unless rendered.blank?
34
34
  end
35
35
 
36
36
  ##
@@ -42,8 +42,8 @@ module Blacklight
42
42
  # @return [String]
43
43
  def render_results_collection_tools(options = {})
44
44
  wrapping_class = options.delete(:wrapping_class) || "search-widgets"
45
- rendered = render_filtered_partials(blacklight_config.index.collection_actions, options)
46
- content_tag("div", rendered, class: wrapping_class)
45
+ rendered = render_filtered_partials(blacklight_config.view_config(document_index_view_type).collection_actions, options)
46
+ content_tag("div", rendered, class: wrapping_class) unless rendered.blank?
47
47
  end
48
48
 
49
49
  def render_filtered_partials(partials, options={}, &block)
@@ -87,11 +87,24 @@ module Blacklight::ConfigurationHelperBehavior
87
87
  # Look up the label for the facet field
88
88
  def facet_field_label field
89
89
  field_config = blacklight_config.facet_fields[field]
90
- defaults = [:"blacklight.search.fields.facet.#{field}", :"blacklight.search.fields.#{field}"]
91
- defaults << field_config.label if field_config
92
- defaults << field.to_s.humanize
93
90
 
94
- field_label *defaults
91
+ field_label(
92
+ :"blacklight.search.fields.facet.#{field}",
93
+ :"blacklight.search.fields.#{field}",
94
+ (field_config.label if field_config),
95
+ field.to_s.humanize
96
+ )
97
+ end
98
+
99
+ def view_label view
100
+ view_config = blacklight_config.view[view]
101
+ field_label(
102
+ :"blacklight.search.view_title.#{view}",
103
+ :"blacklight.search.view.#{view}",
104
+ view_config.label,
105
+ view_config.title,
106
+ view.to_s.humanize
107
+ )
95
108
  end
96
109
 
97
110
  ##
@@ -107,7 +120,7 @@ module Blacklight::ConfigurationHelperBehavior
107
120
  # @param [Symbol] any number of additional keys
108
121
  # @param [Symbol] ...
109
122
  def field_label *i18n_keys
110
- first, *rest = i18n_keys.compact
123
+ first, *rest = i18n_keys
111
124
 
112
125
  t(first, default: rest)
113
126
  end
@@ -82,15 +82,10 @@ module Blacklight::UrlHelperBehavior
82
82
  return {}
83
83
  end
84
84
 
85
- { :data => {:'context-href' => session_tracking_path(document, per_page: params.fetch(:per_page, search_session['per_page']), counter: counter, search_id: current_search_session.try(:id))}}
85
+ { :data => {:'context-href' => track_solr_document_path(document, per_page: params.fetch(:per_page, search_session['per_page']), counter: counter, search_id: current_search_session.try(:id))}}
86
86
  end
87
87
  protected :session_tracking_params
88
88
 
89
- ##
90
- # Get the URL for tracking search sessions across pages using polymorphic routing
91
- def session_tracking_path document, params = {}
92
- polymorphic_path([:track, document], params)
93
- end
94
89
 
95
90
  #
96
91
  # link based helpers ->
@@ -1,13 +1,13 @@
1
1
  <div id="content" class="col-md-12">
2
- <h1><%= t('blacklight.bookmarks.title') %></h1>
2
+ <h1 class='page-heading'><%= t('blacklight.bookmarks.title') %></h1>
3
3
 
4
4
  <%- if current_or_guest_user.blank? -%>
5
5
 
6
- <h2><%= t('blacklight.bookmarks.need_login') %></h2>
6
+ <h2 class='section-heading'><%= t('blacklight.bookmarks.need_login') %></h2>
7
7
 
8
8
  <%- elsif @document_list.blank? -%>
9
9
 
10
- <h3><%= t('blacklight.bookmarks.no_bookmarks') %></h3>
10
+ <h3 class='section-heading'><%= t('blacklight.bookmarks.no_bookmarks') %></h3>
11
11
  <% else %>
12
12
  <%= link_to t('blacklight.bookmarks.clear.action_title'), clear_bookmarks_path, :method => :delete, :data => { :confirm => t('blacklight.bookmarks.clear.action_confirm') }, :class => 'clear-bookmarks btn btn-danger pull-right' %>
13
13
  <%= render 'sort_and_per_page' %>
@@ -4,7 +4,7 @@
4
4
  # but it was simpler to leave them seperate instead of DRYing them, got confusing trying that.
5
5
  # the data-doc-id attribute is used by our JS that converts to a checkbox/label.
6
6
  -%>
7
- <% if current_bookmarks.find { |x| x.document_id == document.id and x.document_type == document.class }.blank? %>
7
+ <% unless is_bookmarked? document %>
8
8
 
9
9
  <%= form_tag( bookmark_path( document ), :method => :put, :class => "bookmark_toggle", "data-doc-id" => document.id, :'data-present' => t('blacklight.search.bookmarks.present'), :'data-absent' => t('blacklight.search.bookmarks.absent'), :'data-inprogress' => t('blacklight.search.bookmarks.inprogress')) do %>
10
10
  <%= submit_tag(t('blacklight.bookmarks.add.button'), :id => "bookmark_toggle_#{document.id.to_s.parameterize}", :class => "bookmark_add") %>
@@ -1,4 +1,4 @@
1
- <% # container for all documents in index view -%>
2
- <div id="documents">
1
+ <% # container for all documents in index list view -%>
2
+ <div id="documents" class="documents-<%= document_index_view_type %>">
3
3
  <%= render documents, :as => :document %>
4
4
  </div>
@@ -1,6 +1,7 @@
1
1
  <div class="panel panel-default facet_limit blacklight-<%= facet_field.key.parameterize %> <%= 'facet_limit-active' if facet_field_in_params?(facet_field.key) %>">
2
2
  <div class="<%= "collapsed" if should_collapse_facet?(facet_field) %> collapse-toggle panel-heading" data-toggle="collapse" data-target="#<%= facet_field_id(facet_field) %>">
3
- <h5 class="panel-title">
3
+ <h5 class="panel-title facet-field-heading">
4
+
4
5
  <%= link_to facet_field_label(facet_field.key), "#", :"data-no-turbolink" => true %>
5
6
  </h5>
6
7
  </div>
@@ -10,7 +10,8 @@
10
10
  <span class="icon-bar"></span>
11
11
  </button>
12
12
 
13
- <h4>
13
+ <h4 class='facets-heading'>
14
+
14
15
  <%= t('blacklight.search.facets.title') %>
15
16
  </h4>
16
17
  </div>
@@ -1,5 +1,5 @@
1
1
  <div class="page-header row">
2
- <h1 class="col-md-8"><%= t('blacklight.welcome') %></h1>
2
+ <h1 class="col-md-8 page-heading"><%= t('blacklight.welcome') %></h1>
3
3
 
4
4
  <ul class="nav nav-pills col-md-4">
5
5
  <li><a href="https://github.com/projectblacklight/blacklight/">Github</a></li>
@@ -11,7 +11,7 @@
11
11
  </div>
12
12
 
13
13
  <div id="getting-started">
14
- <h2>Here&rsquo;s how to get started:</h2>
14
+ <h2 class='section-heading'>Here&rsquo;s how to get started:</h2>
15
15
 
16
16
  <ol>
17
17
  <li>To modify this text, you need to <a href="http://guides.rubyonrails.org/engines.html#improving-engine-functionality">override the Blacklight-provided view</a>.
@@ -28,7 +28,7 @@ to your own application: <br />
28
28
 
29
29
  <%# This is the same panel shown in the Rails welcome template %>
30
30
  <div id="about">
31
- <h3><a href="/rails/info/properties">About your application&rsquo;s environment</a></h3>
31
+ <h3 class='section-heading'><a href="/rails/info/properties">About your application&rsquo;s environment</a></h3>
32
32
  <div id="about-content" class="well" style="display: none"></div>
33
33
  </div>
34
34
 
@@ -1,19 +1,22 @@
1
+ <%# header bar for doc items in index view -%>
2
+ <div class="documentHeader row">
3
+ <%# main title container for doc partial view
4
+ How many bootstrap columns need to be reserved
5
+ for bookmarks control depends on size.
6
+ -%>
7
+ <% document_actions = capture do %>
8
+ <% # bookmark functions for items/docs -%>
9
+ <%= render_index_doc_actions document, wrapping_class: "index-document-functions col-sm-3 col-lg-2" %>
10
+ <% end %>
1
11
 
2
- <% # header bar for doc items in index view -%>
3
- <div class="documentHeader row">
12
+ <h5 class="index_title document-title-heading <%= document_actions.present? ? "col-sm-9 col-lg-10" : "col-md-12" %>">
13
+ <% if counter = document_counter_with_offset(document_counter) %>
14
+ <span class="document-counter">
15
+ <%= t('blacklight.search.documents.counter', counter: counter) %>
16
+ </span>
17
+ <% end %>
18
+ <%= link_to_document document, document_show_link_field(document), counter: counter %>
19
+ </h5>
4
20
 
5
- <%# main title container for doc partial view
6
- How many bootstrap columns need to be reserved
7
- for bookmarks control depends on size.
8
- -%>
9
- <h5 class="index_title col-sm-9 col-lg-10">
10
- <% counter = document_counter_with_offset(document_counter) %>
11
- <span class="document-counter">
12
- <%= t('blacklight.search.documents.counter', :counter => counter) if counter %>
13
- </span>
14
- <%= link_to_document document, document_show_link_field(document), :counter => counter %>
15
- </h5>
16
-
17
- <% # bookmark functions for items/docs -%>
18
- <%= render_index_doc_actions document, :wrapping_class => "index-document-functions col-sm-3 col-lg-2" %>
19
- </div>
21
+ <%= document_actions %>
22
+ </div>
@@ -19,7 +19,7 @@
19
19
 
20
20
  </div>
21
21
  <% @documents.each do |doc| %>
22
- <%=hidden_field_tag "id[]", doc.id %>
22
+ <%=hidden_field_tag "id[]", doc.get(:id)%>
23
23
  <% end %>
24
24
  </div>
25
25
  <div class="modal-footer">
@@ -3,9 +3,9 @@
3
3
  <span class="sr-only"><%= t('blacklight.search.view_title') %></span>
4
4
  <div class="view-type-group btn-group">
5
5
  <% document_index_views.each do |view, config| %>
6
- <%= link_to url_for(params.merge(:view => view)), :title => t(:"blacklight.search.view_title.#{view}", default: [:"blacklight.search.view.#{view}", blacklight_config.view[view].title || view.to_s]), :class => "btn btn-default view-type-#{ view.to_s.parameterize } #{"active" if document_index_view_type == view}" do %>
7
- <%= render_view_type_group_icon view %>
8
- <span class="caption"><%= t(:"blacklight.search.view.#{view}", default: blacklight_config.view[view].title || view.to_s) %></span>
6
+ <%= link_to url_for(params.merge(view: view)), title: view_label(view), class: "btn btn-default view-type-#{ view.to_s.parameterize } #{"active" if document_index_view_type == view}" do %>
7
+ <%= render_view_type_group_icon view %>
8
+ <span class="caption"><%= view_label(view) %></span>
9
9
  <% end %>
10
10
  <% end %>
11
11
  </div>
@@ -36,6 +36,8 @@
36
36
  <%= render partial: 'shared/ajax_modal' %>
37
37
 
38
38
  <div id="main-container" class="container">
39
+ <%= content_tag :h1, application_name, class: 'sr-only application-heading' %>
40
+
39
41
  <%= render :partial=>'/flash_msg', layout: 'shared/flash_messages' %>
40
42
 
41
43
  <div class="row">
@@ -1,20 +1,22 @@
1
1
  <div id="content" class="col-md-9">
2
- <h1><%= t('blacklight.saved_searches.title') %></h1>
2
+
3
+ <h1 class='page-heading'><%= t('blacklight.saved_searches.title') %></h1>
3
4
 
4
5
  <%- if current_or_guest_user.blank? -%>
5
6
 
6
- <h2><%= t('blacklight.saved_searches.need_login') %></h2>
7
+ <h2 class='section-heading'><%= t('blacklight.saved_searches.need_login') %></h2>
7
8
 
8
9
  <%- elsif @searches.blank? -%>
9
10
 
10
- <h2><%= t('blacklight.saved_searches.no_searches') %></h2>
11
+ <h2 class='section-heading'><%= t('blacklight.saved_searches.no_searches') %></h2>
11
12
 
12
13
  <%- else -%>
13
14
  <p>
14
15
  <%= link_to t('blacklight.saved_searches.clear.action_title'), clear_saved_searches_path, :method => :delete, :data => { :confirm => t('blacklight.saved_searches.clear.action_confirm') } %>
15
16
  </p>
16
17
 
17
- <h2><%= t('blacklight.saved_searches.list_title') %></h2>
18
+ <h2 class='section-heading'><%= t('blacklight.saved_searches.list_title') %></h2>
19
+
18
20
  <table class="table table-striped">
19
21
  <%- @searches.each do |search| -%>
20
22
  <tr>
@@ -1,10 +1,10 @@
1
1
  <div id="content" class="col-md-12">
2
- <h1><%=t('blacklight.search_history.title')%></h1>
2
+ <h1 class='page-heading'><%=t('blacklight.search_history.title')%></h1>
3
3
  <%- if @searches.blank? -%>
4
- <h2><%=t('blacklight.search_history.no_history')%></h2>
4
+ <h2 class='section-heading'><%=t('blacklight.search_history.no_history')%></h2>
5
5
  <%- else -%>
6
6
  <%= link_to t('blacklight.search_history.clear.action_title'), clear_search_history_path, :method => :delete, :data => { :confirm => t('blacklight.search_history.clear.action_confirm') }, :class => 'btn btn-danger pull-right' %>
7
- <h3><%=t('blacklight.search_history.recent')%></h3>
7
+ <h3 class='section-heading'><%=t('blacklight.search_history.recent')%></h3>
8
8
  <table class="table table-striped search_history">
9
9
  <%- @searches.each_with_index do |search,index| -%>
10
10
  <%= content_tag :tr, :id => "document_#{index + 1}" do %>
@@ -5,7 +5,7 @@ module Blacklight
5
5
 
6
6
  self.collapse = true if self.collapse.nil?
7
7
  self.show = true if self.show.nil?
8
- self.if = self.show if self.if.nil?
8
+ self.if ||= self.show
9
9
 
10
10
  super
11
11
 
@@ -1,7 +1,7 @@
1
1
  module Blacklight
2
2
  class Configuration::SearchField < Blacklight::Configuration::Field
3
3
  def normalize! blacklight_config = nil
4
- self.if = self.include_in_simple_select if self.if.nil?
4
+ self.if ||= self.include_in_simple_select
5
5
 
6
6
  super
7
7
  self.qt ||= blacklight_config.default_solr_params[:qt] if blacklight_config && blacklight_config.default_solr_params
@@ -31,7 +31,7 @@ module Blacklight::Document
31
31
  include Blacklight::Document::Extensions
32
32
  end
33
33
 
34
- attr_reader :response, :_source
34
+ attr_reader :response
35
35
  alias_method :solr_response, :response
36
36
 
37
37
  def initialize(source_doc={}, response=nil)
@@ -52,23 +52,11 @@ module Blacklight::Document
52
52
  # If a method is missing, it gets sent to @_source
53
53
  # with all of the original params and block
54
54
  def method_missing(m, *args, &b)
55
- if _source and _source.respond_to? m
56
- _source.send(m, *args, &b)
57
- else
58
- super
59
- end
60
- end
61
-
62
- def respond_to_missing? *args
63
- (_source && _source.respond_to?(*args)) || super
55
+ @_source.send(m, *args, &b)
64
56
  end
65
57
 
66
58
  def [] *args
67
- _source.send :[], *args
68
- end
69
-
70
- def _read_attribute(attr)
71
- self[attr]
59
+ @_source.send :[], *args
72
60
  end
73
61
 
74
62
  # Helper method to check if value/multi-values exist for a given key.
@@ -93,7 +81,7 @@ module Blacklight::Document
93
81
  end
94
82
 
95
83
  def key? k
96
- _source.key? k
84
+ @_source.key? k
97
85
  end
98
86
 
99
87
  # helper
@@ -124,7 +112,7 @@ module Blacklight::Document
124
112
  end
125
113
 
126
114
  def as_json(options = nil)
127
- _source.as_json(options)
115
+ @_source.as_json(options)
128
116
  end
129
117
 
130
118
  def to_partial_path
@@ -147,12 +135,6 @@ module Blacklight::Document
147
135
  nil
148
136
  end
149
137
 
150
- ##
151
- # Implementations that support More-Like-This should override this method
152
- # to return an array of documents that are like this one.
153
- def more_like_this
154
- []
155
- end
156
138
 
157
139
  # Certain class-level methods needed for the document-specific
158
140
  # extendability architecture
@@ -171,4 +153,4 @@ module Blacklight::Document
171
153
  self
172
154
  end
173
155
  end
174
- end
156
+ end
@@ -155,9 +155,11 @@ module Blacklight
155
155
  result.send(method)
156
156
  end
157
157
  end
158
- else
158
+ when field_config
159
159
  # regular solr
160
- @document.get(field, :sep => nil) if field
160
+ @document.get(field_config.field, sep: nil)
161
+ when field
162
+ @document.get(field, sep: nil)
161
163
  end
162
164
 
163
165
  # rendering values
@@ -22,7 +22,7 @@ module Blacklight
22
22
  def facet_configuration_for_field(field)
23
23
  f = blacklight_config.facet_fields[field]
24
24
  f ||= begin
25
- _, value = blacklight_config.facet_fields.find { |k,v| v.field == field }
25
+ _, value = blacklight_config.facet_fields.find { |k,v| v.field.to_s == field.to_s }
26
26
  value
27
27
  end
28
28
  f ||= Blacklight::Configuration::FacetField.new(:field => field).normalize!
@@ -30,29 +30,29 @@ module Blacklight
30
30
 
31
31
 
32
32
  # Get a FacetField object from the @response
33
- def facet_by_field_name field
34
- case field
33
+ def facet_by_field_name field_or_field_name
34
+ case field_or_field_name
35
35
  when String, Symbol
36
- extract_facet_by_field_name(field)
36
+ facet_field = facet_configuration_for_field(field_or_field_name)
37
+ extract_facet_by_field(facet_field)
37
38
  when Blacklight::Configuration::FacetField
38
- extract_facet_by_field_name(field.key)
39
+ extract_facet_by_field(field_or_field_name)
39
40
  else
40
- field
41
+ field_or_field_name
41
42
  end
42
43
  end
43
44
 
44
45
  private
45
46
 
46
47
  # Get the solr response for the field :field
47
- def extract_facet_by_field_name field_name
48
- facet_field = facet_configuration_for_field(field_name)
48
+ def extract_facet_by_field facet_field
49
49
  case
50
50
  when (facet_field.respond_to?(:query) and facet_field.query)
51
- create_facet_field_response_for_query_facet_field field_name, facet_field
51
+ create_facet_field_response_for_query_facet_field facet_field.key, facet_field
52
52
  when (facet_field.respond_to?(:pivot) and facet_field.pivot)
53
- create_facet_field_response_for_pivot_facet_field field_name, facet_field
53
+ create_facet_field_response_for_pivot_facet_field facet_field.key, facet_field
54
54
  else
55
- @response.facet_by_field_name(field_name)
55
+ @response.facet_by_field_name(facet_field.field)
56
56
  end
57
57
  end
58
58
 
@@ -3,12 +3,20 @@ module Blacklight
3
3
  extend Deprecation
4
4
  self.deprecation_horizon = "blacklight 6.0"
5
5
 
6
+ class_attribute :default_processor_chain
7
+ self.default_processor_chain = []
8
+
6
9
  attr_reader :processor_chain, :blacklight_params
7
10
 
8
- # @param [List<Symbol>] processor_chain a list of filter methods to run
11
+ # @param [List<Symbol>,TrueClass] processor_chain a list of filter methods to run or true, to use the default methods
9
12
  # @param [Object] scope the scope where the filter methods reside in.
10
13
  def initialize(processor_chain, scope)
11
- @processor_chain = processor_chain
14
+ @processor_chain = if processor_chain === true
15
+ default_processor_chain.dup
16
+ else
17
+ processor_chain
18
+ end
19
+
12
20
  @scope = scope
13
21
  @blacklight_params = {}
14
22
  end
@@ -56,8 +64,8 @@ module Blacklight
56
64
  #
57
65
  # Incoming parameter :f is mapped to :fq solr parameter.
58
66
  def processed_parameters
59
- Blacklight::Solr::Request.new.tap do |request_parameters|
60
- @processor_chain.each do |method_name|
67
+ request.tap do |request_parameters|
68
+ processor_chain.each do |method_name|
61
69
  if scope.respond_to?(method_name, true)
62
70
  Deprecation.warn Blacklight::SearchBuilder, "Building search parameters by calling #{method_name} on #{scope.class}. This behavior will be deprecated in Blacklight 6.0. Instead, define #{method_name} on a subclass of #{self.class} and set search_builder_class in the configuration"
63
71
  scope.send(method_name, request_parameters, blacklight_params)
@@ -73,6 +81,10 @@ module Blacklight
73
81
  end
74
82
 
75
83
  protected
84
+ def request
85
+ Blacklight::Solr::Request.new
86
+ end
87
+
76
88
  def page
77
89
  if blacklight_params[:page].blank?
78
90
  1
@@ -121,10 +133,8 @@ module Blacklight
121
133
  field.include_in_request || (field.include_in_request.nil? && blacklight_config.add_field_configuration_to_solr_request)
122
134
  end
123
135
 
124
- protected
125
136
  def scope
126
137
  @scope
127
138
  end
128
-
129
139
  end
130
140
  end
@@ -1,6 +1,8 @@
1
1
  module Blacklight::Solr
2
2
  class SearchBuilder < Blacklight::SearchBuilder
3
-
3
+
4
+ self.default_processor_chain = [:default_solr_parameters, :add_query_to_solr, :add_facet_fq_to_solr, :add_facetting_to_solr, :add_solr_fields_to_query, :add_paging_to_solr, :add_sorting_to_solr, :add_group_config_to_solr ]
5
+
4
6
  ####
5
7
  # Start with general defaults from BL config. Need to use custom
6
8
  # merge to dup values, to avoid later mutating the original by mistake.
@@ -144,6 +144,17 @@ describe BlacklightHelper do
144
144
  response = helper.render_index_doc_actions(document)
145
145
  expect(response).to have_selector(".bookmark_toggle")
146
146
  end
147
+
148
+ it "should be nil if no partials are renderable" do
149
+ allow(helper).to receive(:render_bookmarks_control?).and_return(false)
150
+ expect(helper.render_index_doc_actions(document)).to be_blank
151
+ end
152
+
153
+ it "should render view type specific actions" do
154
+ allow(helper).to receive(:document_index_view_type).and_return(:custom)
155
+ config.view.custom.document_actions = []
156
+ expect(helper.render_index_doc_actions(document)).to be_blank
157
+ end
147
158
  end
148
159
 
149
160
  describe "render_show_doc_actions" do
@@ -608,7 +619,7 @@ describe BlacklightHelper do
608
619
 
609
620
  it "should ignore missing templates" do
610
621
  response = helper.render_document_index_with_view :view_type, [obj1, obj1]
611
- expect(response).to match /<div id="documents">/
622
+ expect(response).to have_selector "div#documents"
612
623
  end
613
624
  end
614
625
 
@@ -305,4 +305,22 @@ describe CatalogHelper do
305
305
  end
306
306
  end
307
307
 
308
+ describe "#is_bookmarked?" do
309
+
310
+ let(:bookmark) { Bookmark.new document: bookmarked_document }
311
+ let(:bookmarked_document) { SolrDocument.new(id: 'a') }
312
+
313
+ before do
314
+ allow(helper).to receive(:current_bookmarks).and_return([bookmark])
315
+ end
316
+
317
+ it "should be bookmarked if the document is in the bookmarks" do
318
+ expect(helper.is_bookmarked?(bookmarked_document)).to eq true
319
+ end
320
+
321
+ it "should not be bookmarked if the document is not listed in the bookmarks" do
322
+ expect(helper.is_bookmarked?(SolrDocument.new(id: 'b'))).to eq false
323
+ end
324
+ end
325
+
308
326
  end
@@ -137,6 +137,15 @@ describe BlacklightConfigurationHelper do
137
137
  end
138
138
  end
139
139
 
140
+ describe "#view_label" do
141
+ it "should look up the label to display for the view" do
142
+ allow(blacklight_config).to receive(:view).and_return({ "my_view" => double(label: "some label", title: nil) })
143
+ allow(helper).to receive(:field_label).with(:"blacklight.search.view_title.my_view", :"blacklight.search.view.my_view", "some label", nil, "My view")
144
+
145
+ helper.view_label "my_view"
146
+ end
147
+ end
148
+
140
149
  describe "#field_label" do
141
150
  it "should look up the label as an i18n string" do
142
151
  allow(helper).to receive(:t).with(:some_key, default: []).and_return "my label"
@@ -150,13 +159,6 @@ describe BlacklightConfigurationHelper do
150
159
 
151
160
  label = helper.field_label :key_a, :key_b, "default text"
152
161
  end
153
-
154
- it "should compact nil keys (fixes rails/rails#19419)" do
155
- allow(helper).to receive(:t).with(:key_a, default: [:key_b])
156
-
157
- label = helper.field_label :key_a, nil, :key_b
158
-
159
- end
160
162
  end
161
163
 
162
164
  describe "#default_per_page" do
@@ -107,7 +107,7 @@ describe FacetsHelper do
107
107
 
108
108
  describe "facet_by_field_name" do
109
109
  it "should retrieve the facet from the response given a string" do
110
- facet_config = double(:query => nil)
110
+ facet_config = double(:query => nil, field: 'a')
111
111
  facet_field = double()
112
112
  allow(helper).to receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
113
113
 
@@ -118,7 +118,7 @@ describe FacetsHelper do
118
118
  end
119
119
 
120
120
  it "should also work for facet query fields" do
121
- facet_config = double(:query => {})
121
+ facet_config = double(:query => {}, key: 'a_query_facet_field')
122
122
  allow(helper).to receive(:facet_configuration_for_field).with('a_query_facet_field').and_return(facet_config)
123
123
  allow(helper).to receive(:create_facet_field_response_for_query_facet_field).with('a_query_facet_field', facet_config)
124
124
 
@@ -128,6 +128,7 @@ describe FacetsHelper do
128
128
  describe "query facets" do
129
129
  let(:facet_config) {
130
130
  double(
131
+ key: 'my_query_facet_field',
131
132
  :query => {
132
133
  'a_simple_query' => { :fq => 'field:search', :label => 'A Human Readable label'},
133
134
  'another_query' => { :fq => 'field:different_search', :label => 'Label'},
@@ -165,7 +166,7 @@ describe FacetsHelper do
165
166
 
166
167
  describe "pivot facets" do
167
168
  let(:facet_config) {
168
- double(:pivot => ['field_a', 'field_b'])
169
+ double(key: 'my_pivot_facet_field', pivot: ['field_a', 'field_b'])
169
170
  }
170
171
 
171
172
  before(:each) do
@@ -449,15 +449,4 @@ describe BlacklightUrlHelper do
449
449
  expect(url).to eq helper.bookmarks_url(format: :html, encrypted_user_id: 'xyz')
450
450
  end
451
451
  end
452
-
453
- describe "#session_tracking_path" do
454
- let(:document) { SolrDocument.new(id: 1) }
455
- it "should determine the correct route for the document class" do
456
- expect(helper.session_tracking_path(document)).to eq helper.track_solr_document_path(document)
457
- end
458
-
459
- it "should pass through tracking parameters" do
460
- expect(helper.session_tracking_path(document, x: 1)).to eq helper.track_solr_document_path(document, x: 1)
461
- end
462
- end
463
452
  end
@@ -213,25 +213,11 @@ describe "Blacklight::Configuration" do
213
213
  "another_field_facet" => {},
214
214
  "a_facet_field" => {},
215
215
  })
216
- expect { |b| @config.add_facet_field "*_facet", &b }.to yield_control.twice
217
- expect(@config.facet_fields.keys).to eq ["some_field_facet", "another_field_facet"]
218
- end
219
-
220
- describe "if/unless conditions with legacy show parameter" do
221
- it "should be hidden if the if condition is false" do
222
- expect(@config.add_facet_field("hidden", if: false).if).to eq false
223
- expect(@config.add_facet_field("hidden_with_legacy", if: false, show: true).if).to eq false
224
- end
225
-
226
- it "should be true if the if condition is true" do
227
- expect(@config.add_facet_field("hidden", if: true).if).to eq true
228
- expect(@config.add_facet_field("hidden_with_legacy", if: true, show: false).if).to eq true
229
- end
216
+ expect { |b| @config.add_index_field "*_facet", &b }.to yield_control.twice
230
217
 
231
- it "should be true if the if condition is missing" do
232
- expect(@config.add_facet_field("hidden", show: true).if).to eq true
233
- end
218
+ expect(@config.index_fields.keys).to eq ["some_field_facet", "another_field_facet"]
234
219
  end
220
+
235
221
  end
236
222
 
237
223
  describe "add_index_field" do
@@ -275,6 +261,7 @@ describe "Blacklight::Configuration" do
275
261
 
276
262
  expect(@config.index_fields.keys).to eq ["some_field_display", "another_field_display"]
277
263
  end
264
+
278
265
  end
279
266
 
280
267
  describe "add_show_field" do
@@ -383,22 +370,8 @@ describe "Blacklight::Configuration" do
383
370
 
384
371
  expect(@config.search_fields["author_name"].label).to eq "Author Name"
385
372
  end
386
-
387
- describe "if/unless conditions with legacy include_in_simple_search" do
388
- it "should be hidden if the if condition is false" do
389
- expect(@config.add_search_field("hidden", if: false).if).to eq false
390
- expect(@config.add_search_field("hidden_with_legacy", if: false, include_in_simple_search: true).if).to eq false
391
- end
392
-
393
- it "should be true if the if condition is true" do
394
- expect(@config.add_search_field("hidden", if: true).if).to eq true
395
- expect(@config.add_search_field("hidden_with_legacy", if: true, include_in_simple_search: false).if).to eq true
396
- end
397
-
398
- it "should be true if the if condition is missing" do
399
- expect(@config.add_search_field("hidden", include_in_simple_search: true).if).to eq true
400
- end
401
- end
373
+
374
+
402
375
  end
403
376
 
404
377
  describe "add_sort_field" do
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Blacklight::Facet do
4
+ subject do
5
+ Class.new do
6
+ include Blacklight::Facet
7
+ attr_reader :blacklight_config
8
+
9
+ def initialize blacklight_config
10
+ @blacklight_config = blacklight_config
11
+ end
12
+ end.new(blacklight_config)
13
+ end
14
+
15
+ let(:blacklight_config) { Blacklight::Configuration.new }
16
+
17
+ describe "#facet_configuration_for_field" do
18
+ it "should look up fields by key" do
19
+ blacklight_config.add_facet_field 'a'
20
+ expect(subject.facet_configuration_for_field('a')).to eq blacklight_config.facet_fields['a']
21
+ end
22
+
23
+ it "should look up fields by field name" do
24
+ blacklight_config.add_facet_field 'a', field: 'b'
25
+ expect(subject.facet_configuration_for_field('b')).to eq blacklight_config.facet_fields['a']
26
+ end
27
+
28
+ it "should support both strings and symbols" do
29
+ blacklight_config.add_facet_field 'a', field: :b
30
+ expect(subject.facet_configuration_for_field('b')).to eq blacklight_config.facet_fields['a']
31
+ end
32
+ end
33
+
34
+ end
@@ -5,6 +5,14 @@ describe Blacklight::SearchBuilder do
5
5
  let(:blacklight_config) { Blacklight::Configuration.new }
6
6
  let(:scope) { double blacklight_config: blacklight_config }
7
7
  subject { described_class.new processor_chain, scope }
8
+
9
+ context "with default processor chain" do
10
+ subject { described_class.new true, scope }
11
+ it "should use the class-level default_processor_chain" do
12
+ expect(subject.processor_chain).to eq []
13
+ end
14
+ end
15
+
8
16
  describe "#with" do
9
17
  it "should set the blacklight params" do
10
18
  params = {}
@@ -17,6 +17,13 @@ describe Blacklight::Solr::SearchBuilder do
17
17
 
18
18
  subject { search_builder.with(user_params) }
19
19
 
20
+ context "with default processor chain" do
21
+ subject { described_class.new true, context }
22
+ it "should use the class-level default_processor_chain" do
23
+ expect(subject.processor_chain).to eq described_class.default_processor_chain
24
+ end
25
+ end
26
+
20
27
  context "with a complex parameter environment" do
21
28
  subject { search_builder.with(user_params).processed_parameters }
22
29
 
@@ -19,6 +19,7 @@ describe Blacklight::DocumentPresenter do
19
19
  config.add_index_field 'solr_doc_accessor', :accessor => true
20
20
  config.add_index_field 'explicit_accessor', :accessor => :solr_doc_accessor
21
21
  config.add_index_field 'explicit_accessor_with_arg', :accessor => :solr_doc_accessor_with_arg
22
+ config.add_index_field 'alias', field: 'qwer'
22
23
  end
23
24
  end
24
25
  it "should check for an explicit value" do
@@ -96,6 +97,12 @@ describe Blacklight::DocumentPresenter do
96
97
  value = subject.render_index_field_value 'explicit_accessor_with_arg'
97
98
  expect(value).to eq "123"
98
99
  end
100
+
101
+ it "should support solr field configuration" do
102
+ allow(document).to receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
103
+ value = subject.render_index_field_value 'alias'
104
+ expect(value).to eq "document qwer value"
105
+ end
99
106
  end
100
107
 
101
108
  describe "render_document_show_field_value" do
@@ -1,8 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "/catalog/_document_list.html.erb" do
4
-
5
-
3
+ describe "catalog/_document_list", type: :view do
6
4
 
5
+ before do
6
+ allow(view).to receive_messages(document_index_view_type: "some-view", documents: [])
7
+ end
7
8
 
9
+ it "should include a class for the current view" do
10
+ render
11
+ expect(rendered).to have_selector(".documents-some-view")
12
+ end
8
13
  end
@@ -31,20 +31,20 @@ describe "catalog/_facets" do
31
31
  :facet_limit_for => 10 )
32
32
 
33
33
  @response = double()
34
- allow(@response).to receive(:facet_by_field_name).with(:facet_field_1) { @mock_display_facet_1 }
34
+ allow(@response).to receive(:facet_by_field_name).with("facet_field_1") { @mock_display_facet_1 }
35
35
  end
36
36
 
37
37
  it "should have a header" do
38
38
  allow(view).to receive_messages(:render_facet_partials => '')
39
39
  render
40
- expect(rendered).to have_selector('h4')
40
+ expect(rendered).to have_selector('.facets-heading')
41
41
  end
42
42
 
43
43
 
44
44
  describe "facet display" do
45
45
  it "should have a(n accessible) header" do
46
46
  render
47
- expect(rendered).to have_selector('h5')
47
+ expect(rendered).to have_selector('.facet-field-heading')
48
48
  end
49
49
 
50
50
  it "should list values" do
@@ -9,15 +9,31 @@ describe "catalog/_index_header_default" do
9
9
  Blacklight::Configuration.new
10
10
  end
11
11
 
12
- it "should render the document header" do
13
- assign :response, double(:params => {})
14
- allow(view).to receive(:current_search_session).and_return nil
15
- allow(view).to receive(:search_session).and_return({})
12
+ before do
13
+ assign :response, double(params: {})
16
14
  allow(view).to receive(:render_grouped_response?).and_return false
17
15
  allow(view).to receive(:blacklight_config).and_return(blacklight_config)
18
- allow(view).to receive(:render_bookmarks_control?).and_return false
19
- render :partial => "catalog/index_header_default", :locals => {:document => document, :document_counter => 1}
16
+ allow(view).to receive(:current_search_session).and_return nil
17
+ allow(view).to receive(:search_session).and_return({})
18
+ end
19
+
20
+ it "should render the document header" do
21
+ allow(view).to receive(:render_index_doc_actions)
22
+ render partial: "catalog/index_header_default", locals: {document: document, document_counter: 1}
20
23
  expect(rendered).to have_selector('.document-counter', text: "2")
21
24
  end
22
25
 
26
+ it "should allow the title to take the whole space if no document tools are rendered" do
27
+ allow(view).to receive(:render_index_doc_actions)
28
+ render partial: "catalog/index_header_default", locals: {document: document, document_counter: 1}
29
+ expect(rendered).to have_selector '.index_title.col-md-12'
30
+ end
31
+
32
+ it "should give the document actions space if present" do
33
+ allow(view).to receive(:render_index_doc_actions).and_return("DOCUMENT ACTIONS")
34
+ render partial: "catalog/index_header_default", locals: {document: document, document_counter: 1}
35
+ expect(rendered).to have_selector '.index_title.col-sm-9'
36
+ expect(rendered).to have_content "DOCUMENT ACTIONS"
37
+ end
38
+
23
39
  end
@@ -7,6 +7,10 @@ describe "catalog/_view_type_group" do
7
7
  end
8
8
 
9
9
  before do
10
+ allow(view).to receive(:view_label) do |view|
11
+ view.to_s
12
+ end
13
+
10
14
  allow(view).to receive_messages(how_sort_and_per_page?: true, blacklight_config: blacklight_config)
11
15
  end
12
16
 
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.10.3
4
+ version: 5.11.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: 2015-03-24 00:00:00.000000000 Z
20
+ date: 2015-03-17 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -519,6 +519,7 @@ files:
519
519
  - spec/lib/blacklight/document/email_spec.rb
520
520
  - spec/lib/blacklight/document/sms_spec.rb
521
521
  - spec/lib/blacklight/facet_paginator_spec.rb
522
+ - spec/lib/blacklight/facet_spec.rb
522
523
  - spec/lib/blacklight/routes_spec.rb
523
524
  - spec/lib/blacklight/search_builder_spec.rb
524
525
  - spec/lib/blacklight/search_fields_spec.rb
@@ -637,6 +638,7 @@ test_files:
637
638
  - spec/lib/blacklight/document/email_spec.rb
638
639
  - spec/lib/blacklight/document/sms_spec.rb
639
640
  - spec/lib/blacklight/facet_paginator_spec.rb
641
+ - spec/lib/blacklight/facet_spec.rb
640
642
  - spec/lib/blacklight/routes_spec.rb
641
643
  - spec/lib/blacklight/search_builder_spec.rb
642
644
  - spec/lib/blacklight/search_fields_spec.rb