blacklight 7.0.0.rc1 → 7.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +30 -18
  3. data/.rubocop_todo.yml +308 -67
  4. data/.solr_wrapper.yml +8 -1
  5. data/.travis.yml +15 -13
  6. data/Gemfile +2 -0
  7. data/README.md +2 -2
  8. data/Rakefile +2 -0
  9. data/VERSION +1 -1
  10. data/Vagrantfile +2 -0
  11. data/app/assets/javascripts/blacklight/blacklight.js +17 -17
  12. data/app/assets/stylesheets/blacklight/_blacklight_base.scss +17 -16
  13. data/app/assets/stylesheets/blacklight/_facets.scss +2 -13
  14. data/app/assets/stylesheets/blacklight/_icons.scss +8 -2
  15. data/app/assets/stylesheets/blacklight/_search_form.scss +7 -0
  16. data/app/assets/stylesheets/blacklight/blacklight.scss +1 -1
  17. data/app/builders/blacklight/action_builder.rb +1 -0
  18. data/app/controllers/concerns/blacklight/bookmarks.rb +19 -13
  19. data/app/controllers/concerns/blacklight/catalog.rb +19 -7
  20. data/app/controllers/concerns/blacklight/controller.rb +12 -18
  21. data/app/controllers/concerns/blacklight/facet.rb +3 -0
  22. data/app/controllers/concerns/blacklight/search_context.rb +7 -3
  23. data/app/controllers/concerns/blacklight/search_history.rb +1 -6
  24. data/app/controllers/concerns/blacklight/token_based_user.rb +3 -1
  25. data/app/helpers/blacklight/blacklight_helper_behavior.rb +5 -1
  26. data/app/helpers/blacklight/configuration_helper_behavior.rb +5 -3
  27. data/app/helpers/blacklight/facets_helper_behavior.rb +15 -12
  28. data/app/helpers/blacklight/icon_helper_behavior.rb +2 -0
  29. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +2 -0
  30. data/app/helpers/blacklight/render_partials_helper_behavior.rb +2 -2
  31. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +1 -0
  32. data/app/helpers/blacklight/url_helper_behavior.rb +29 -14
  33. data/app/javascript/blacklight/checkbox_submit.js +9 -8
  34. data/app/javascript/blacklight/core.js +8 -6
  35. data/app/javascript/blacklight/modal.js +1 -3
  36. data/app/javascript/blacklight/search_context.js +0 -1
  37. data/app/models/blacklight/icon.rb +3 -0
  38. data/app/models/blacklight/suggest_search.rb +3 -14
  39. data/app/models/bookmark.rb +1 -1
  40. data/app/models/concerns/blacklight/document.rb +3 -1
  41. data/app/models/concerns/blacklight/solr/document.rb +1 -0
  42. data/app/models/concerns/blacklight/suggest/response.rb +5 -3
  43. data/app/models/concerns/blacklight/user.rb +1 -0
  44. data/app/models/search.rb +1 -0
  45. data/app/presenters/blacklight/document_presenter.rb +38 -0
  46. data/app/presenters/blacklight/field_presenter.rb +2 -0
  47. data/app/presenters/blacklight/index_presenter.rb +13 -5
  48. data/app/presenters/blacklight/json_presenter.rb +5 -12
  49. data/app/presenters/blacklight/link_alternate_presenter.rb +2 -0
  50. data/app/presenters/blacklight/rendering/abstract_step.rb +2 -0
  51. data/app/presenters/blacklight/rendering/helper_method.rb +2 -0
  52. data/app/presenters/blacklight/rendering/join.rb +2 -0
  53. data/app/presenters/blacklight/rendering/link_to_facet.rb +4 -0
  54. data/app/presenters/blacklight/rendering/microdata.rb +3 -0
  55. data/app/presenters/blacklight/rendering/pipeline.rb +2 -0
  56. data/app/presenters/blacklight/rendering/terminator.rb +2 -0
  57. data/app/presenters/blacklight/search_bar_presenter.rb +2 -0
  58. data/app/presenters/blacklight/show_presenter.rb +8 -5
  59. data/app/presenters/blacklight/thumbnail_presenter.rb +2 -0
  60. data/app/services/blacklight/document_factory.rb +2 -0
  61. data/app/services/blacklight/field_retriever.rb +2 -0
  62. data/app/services/blacklight/search_service.rb +7 -9
  63. data/app/values/blacklight/types.rb +3 -0
  64. data/app/views/bookmarks/index.html.erb +12 -13
  65. data/app/views/catalog/_citation.html.erb +4 -4
  66. data/app/views/catalog/_constraints.html.erb +2 -0
  67. data/app/views/catalog/_did_you_mean.html.erb +1 -1
  68. data/app/views/catalog/_document.atom.builder +17 -16
  69. data/app/views/catalog/_document.rss.builder +2 -0
  70. data/app/views/catalog/_facet_index_navigation.html.erb +5 -4
  71. data/app/views/catalog/_facet_layout.html.erb +3 -5
  72. data/app/views/catalog/_facets.html.erb +5 -4
  73. data/app/views/catalog/_field.json.jbuilder +10 -0
  74. data/app/views/catalog/_group.html.erb +1 -1
  75. data/app/views/catalog/_home_text.html.erb +5 -5
  76. data/app/views/catalog/_index.html.erb +5 -7
  77. data/app/views/catalog/_index_header.html.erb +1 -1
  78. data/app/views/catalog/_per_page_widget.html.erb +1 -1
  79. data/app/views/catalog/_results_pagination.html.erb +2 -2
  80. data/app/views/catalog/_search_form.html.erb +1 -1
  81. data/app/views/catalog/_search_results.html.erb +2 -2
  82. data/app/views/catalog/_show.html.erb +3 -5
  83. data/app/views/catalog/_show_more_like_this.html.erb +1 -1
  84. data/app/views/catalog/_show_sidebar.html.erb +1 -1
  85. data/app/views/catalog/_show_tools.html.erb +1 -1
  86. data/app/views/catalog/_sort_widget.html.erb +1 -1
  87. data/app/views/catalog/_zero_results.html.erb +1 -1
  88. data/app/views/catalog/citation.js.erb +1 -1
  89. data/app/views/catalog/facet.html.erb +5 -4
  90. data/app/views/catalog/facet.json.jbuilder +2 -0
  91. data/app/views/catalog/index.atom.builder +4 -2
  92. data/app/views/catalog/index.json.jbuilder +29 -10
  93. data/app/views/catalog/index.rss.builder +2 -0
  94. data/app/views/catalog/opensearch.xml.builder +3 -1
  95. data/app/views/catalog/show.json.jbuilder +21 -0
  96. data/app/views/kaminari/blacklight/_first_page.html.erb +1 -1
  97. data/app/views/kaminari/blacklight/_last_page.html.erb +1 -1
  98. data/app/views/kaminari/blacklight/_next_page.html.erb +3 -3
  99. data/app/views/kaminari/blacklight/_page.html.erb +4 -2
  100. data/app/views/kaminari/blacklight/_prev_page.html.erb +2 -2
  101. data/app/views/layouts/blacklight.html.erb +4 -4
  102. data/app/views/layouts/blacklight/base.html.erb +1 -9
  103. data/app/views/search_history/index.html.erb +3 -3
  104. data/app/views/shared/_header_navbar.html.erb +1 -1
  105. data/app/views/shared/_modal.html.erb +2 -2
  106. data/blacklight.gemspec +7 -6
  107. data/config/i18n-tasks.yml +17 -0
  108. data/config/locales/blacklight.de.yml +72 -57
  109. data/config/locales/blacklight.en.yml +11 -1
  110. data/config/locales/blacklight.es.yml +15 -1
  111. data/config/locales/blacklight.fr.yml +17 -8
  112. data/config/locales/blacklight.hu.yml +3 -1
  113. data/config/locales/blacklight.it.yml +16 -1
  114. data/config/locales/blacklight.nl.yml +3 -1
  115. data/config/locales/blacklight.pt-BR.yml +19 -2
  116. data/config/locales/blacklight.sq.yml +3 -1
  117. data/config/locales/blacklight.zh.yml +3 -1
  118. data/config/routes.rb +0 -1
  119. data/lib/blacklight.rb +3 -0
  120. data/lib/blacklight/abstract_repository.rb +12 -0
  121. data/lib/blacklight/configuration.rb +21 -3
  122. data/lib/blacklight/configuration/context.rb +11 -0
  123. data/lib/blacklight/configuration/fields.rb +31 -26
  124. data/lib/blacklight/configuration/null_field.rb +2 -0
  125. data/lib/blacklight/engine.rb +4 -1
  126. data/lib/blacklight/routes/exportable.rb +1 -3
  127. data/lib/blacklight/routes/searchable.rb +2 -3
  128. data/lib/blacklight/runtime_registry.rb +2 -0
  129. data/lib/blacklight/search_builder.rb +2 -0
  130. data/lib/blacklight/search_state.rb +2 -0
  131. data/lib/blacklight/solr/repository.rb +34 -0
  132. data/lib/blacklight/solr/response/spelling.rb +1 -0
  133. data/lib/generators/blacklight/assets_generator.rb +10 -9
  134. data/lib/generators/blacklight/controller_generator.rb +1 -1
  135. data/lib/generators/blacklight/install_generator.rb +7 -14
  136. data/lib/generators/blacklight/solr_generator.rb +8 -0
  137. data/lib/generators/blacklight/templates/alternate_controller.rb +4 -4
  138. data/lib/generators/blacklight/templates/catalog_controller.rb +7 -1
  139. data/lib/generators/blacklight/templates/solr/conf/schema.xml +20 -22
  140. data/lib/generators/blacklight/user_generator.rb +2 -0
  141. data/lib/railties/blacklight.rake +9 -13
  142. data/package-lock.json +544 -406
  143. data/package.json +3 -2
  144. data/spec/controllers/alternate_controller_spec.rb +4 -3
  145. data/spec/controllers/application_controller_spec.rb +0 -4
  146. data/spec/controllers/blacklight/base_spec.rb +5 -2
  147. data/spec/controllers/blacklight/catalog/component_configuration_spec.rb +4 -4
  148. data/spec/controllers/blacklight/facet_spec.rb +0 -1
  149. data/spec/controllers/blacklight/search_fields_spec.rb +25 -22
  150. data/spec/controllers/bookmarks_controller_spec.rb +45 -10
  151. data/spec/controllers/catalog_controller_spec.rb +206 -138
  152. data/spec/controllers/search_history_controller_spec.rb +4 -4
  153. data/spec/features/alternate_controller_spec.rb +3 -3
  154. data/spec/features/autocomplete_spec.rb +2 -0
  155. data/spec/features/did_you_mean_spec.rb +4 -3
  156. data/spec/features/facets_spec.rb +7 -7
  157. data/spec/features/record_view_spec.rb +11 -12
  158. data/spec/features/search_context_spec.rb +4 -5
  159. data/spec/features/search_crawler_spec.rb +3 -5
  160. data/spec/features/search_filters_spec.rb +44 -44
  161. data/spec/features/search_history_spec.rb +5 -3
  162. data/spec/features/search_pagination_spec.rb +3 -1
  163. data/spec/features/search_results_spec.rb +11 -8
  164. data/spec/features/search_spec.rb +3 -3
  165. data/spec/features/sitelinks_search_box.rb +4 -4
  166. data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +30 -30
  167. data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +65 -59
  168. data/spec/helpers/blacklight/hash_as_hidden_fields_behavior_spec.rb +1 -1
  169. data/spec/helpers/blacklight/icon_helper_behavior_spec.rb +2 -0
  170. data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +8 -3
  171. data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +16 -4
  172. data/spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb +21 -22
  173. data/spec/helpers/blacklight/suggest_helper_behavior_spec.rb +6 -1
  174. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +49 -43
  175. data/spec/helpers/blacklight_helper_spec.rb +28 -12
  176. data/spec/helpers/catalog_helper_spec.rb +50 -47
  177. data/spec/i18n_spec.rb +18 -0
  178. data/spec/integration/generators/blacklight/solr_generator_spec.rb +18 -10
  179. data/spec/lib/blacklight/configuration/facet_field_spec.rb +2 -0
  180. data/spec/lib/blacklight/configuration/field_spec.rb +3 -0
  181. data/spec/lib/blacklight/open_struct_with_hash_access_spec.rb +15 -20
  182. data/spec/lib/blacklight/parameters_spec.rb +3 -1
  183. data/spec/lib/blacklight/search_state_spec.rb +51 -34
  184. data/spec/lib/blacklight_spec.rb +13 -14
  185. data/spec/lib/tasks/blacklight_task_spec.rb +3 -5
  186. data/spec/models/blacklight/configurable_spec.rb +11 -13
  187. data/spec/models/blacklight/configuration/context_spec.rb +9 -10
  188. data/spec/models/blacklight/configuration_spec.rb +103 -91
  189. data/spec/models/blacklight/document/active_model_shim_spec.rb +5 -6
  190. data/spec/models/blacklight/document/cache_key_spec.rb +9 -2
  191. data/spec/models/blacklight/document/dublin_core_spec.rb +16 -19
  192. data/spec/models/blacklight/document/email_spec.rb +9 -9
  193. data/spec/models/blacklight/document/sms_spec.rb +9 -9
  194. data/spec/models/blacklight/document_spec.rb +9 -8
  195. data/spec/models/blacklight/facet_paginator_spec.rb +40 -30
  196. data/spec/models/blacklight/icon_spec.rb +12 -2
  197. data/spec/models/blacklight/search_builder_spec.rb +12 -3
  198. data/spec/models/blacklight/solr/document_spec.rb +216 -219
  199. data/spec/models/blacklight/solr/facet_paginator_spec.rb +6 -4
  200. data/spec/models/blacklight/solr/repository_spec.rb +37 -34
  201. data/spec/models/blacklight/solr/request_spec.rb +17 -18
  202. data/spec/models/blacklight/solr/response/facets_spec.rb +58 -58
  203. data/spec/models/blacklight/solr/response/group_response_spec.rb +16 -22
  204. data/spec/models/blacklight/solr/response/group_spec.rb +18 -25
  205. data/spec/models/blacklight/solr/response_spec.rb +48 -50
  206. data/spec/models/blacklight/solr/search_builder_spec.rb +120 -121
  207. data/spec/models/blacklight/suggest/response_spec.rb +6 -4
  208. data/spec/models/blacklight/suggest_search_spec.rb +9 -16
  209. data/spec/models/blacklight/user_spec.rb +9 -11
  210. data/spec/models/bookmark_spec.rb +6 -5
  211. data/spec/models/record_mailer_spec.rb +22 -20
  212. data/spec/models/search_spec.rb +18 -17
  213. data/spec/models/solr_document_spec.rb +6 -2
  214. data/spec/presenters/blacklight/document_presenter_spec.rb +86 -0
  215. data/spec/presenters/blacklight/index_presenter_spec.rb +186 -0
  216. data/spec/presenters/blacklight/json_presenter_spec.rb +59 -0
  217. data/spec/presenters/blacklight/link_alternate_presenter_spec.rb +3 -0
  218. data/spec/presenters/blacklight/search_bar_presenter_spec.rb +7 -0
  219. data/spec/presenters/{show_presenter_spec.rb → blacklight/show_presenter_spec.rb} +138 -91
  220. data/spec/presenters/pipeline_spec.rb +15 -8
  221. data/spec/presenters/thumbnail_presenter_spec.rb +5 -2
  222. data/spec/routing/catalog_routing_spec.rb +12 -14
  223. data/spec/services/blacklight/search_service_spec.rb +112 -70
  224. data/spec/spec_helper.rb +6 -2
  225. data/spec/support/features.rb +1 -1
  226. data/spec/support/features/session_helpers.rb +4 -4
  227. data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -13
  228. data/spec/views/catalog/_constraints.html.erb_spec.rb +2 -3
  229. data/spec/views/catalog/_constraints_element.html.erb_spec.rb +9 -5
  230. data/spec/views/catalog/_document.html.erb_spec.rb +4 -4
  231. data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -0
  232. data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +4 -4
  233. data/spec/views/catalog/_facet_layout.html.erb_spec.rb +3 -3
  234. data/spec/views/catalog/_facets.html.erb_spec.rb +8 -10
  235. data/spec/views/catalog/_index.html.erb_spec.rb +13 -14
  236. data/spec/views/catalog/_index_header.html.erb_spec.rb +5 -8
  237. data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +3 -3
  238. data/spec/views/catalog/_show.html.erb_spec.rb +12 -13
  239. data/spec/views/catalog/_show_sidebar.erb_spec.rb +4 -7
  240. data/spec/views/catalog/_show_tools.html.erb_spec.rb +2 -2
  241. data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +0 -1
  242. data/spec/views/catalog/_sort_widget.html.erb_spec.rb +3 -1
  243. data/spec/views/catalog/_thumbnail.html.erb_spec.rb +6 -8
  244. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +7 -9
  245. data/spec/views/catalog/email_success.html.erb_spec.rb +0 -1
  246. data/spec/views/catalog/facet.html.erb_spec.rb +3 -2
  247. data/spec/views/catalog/facet.json.jbuilder_spec.rb +3 -2
  248. data/spec/views/catalog/index.atom.builder_spec.rb +9 -4
  249. data/spec/views/catalog/index.html.erb_spec.rb +2 -1
  250. data/spec/views/catalog/index.json.jbuilder_spec.rb +84 -36
  251. data/spec/views/catalog/show.html.erb_spec.rb +6 -6
  252. data/spec/views/catalog/show.json.jbuilder_spec.rb +40 -0
  253. data/spec/views/catalog/sms_success.html.erb_spec.rb +0 -1
  254. data/spec/views/shared/_user_util_links.html.erb_spec.rb +1 -4
  255. data/tasks/blacklight.rake +6 -4
  256. data/template.demo.rb +2 -0
  257. metadata +50 -24
  258. data/app/javascript/blacklight/autofocus.js +0 -20
  259. data/spec/presenters/index_presenter_spec.rb +0 -150
@@ -19,21 +19,23 @@ Blacklight = function() {
19
19
  listeners.push('turbolinks:load');
20
20
  } else {
21
21
  // Turbolinks < 5
22
- listeners.push('page:load', 'ready');
22
+ listeners.push('page:load', 'DOMContentLoaded');
23
23
  }
24
24
  } else {
25
- listeners.push('ready');
25
+ listeners.push('DOMContentLoaded');
26
26
  }
27
27
 
28
- return listeners.join(' ');
28
+ return listeners;
29
29
  }
30
30
  };
31
31
  }();
32
32
 
33
33
  // turbolinks triggers page:load events on page transition
34
34
  // If app isn't using turbolinks, this event will never be triggered, no prob.
35
- $(document).on(Blacklight.listeners(), function() {
36
- Blacklight.activate();
37
- });
35
+ Blacklight.listeners().forEach(function(listener) {
36
+ document.addEventListener(listener, function() {
37
+ Blacklight.activate()
38
+ })
39
+ })
38
40
 
39
41
  $('.no-js').removeClass('no-js').addClass('js');
@@ -1,5 +1,3 @@
1
- //= require blacklight/core
2
-
3
1
  /*
4
2
  The blacklight modal plugin can display some interactions inside a Bootstrap
5
3
  modal window, including some multi-page interactions.
@@ -119,7 +117,7 @@ Blacklight.modal.receiveAjax = function (contents) {
119
117
  // code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/master/src/ajax/load.js?source=c#L62
120
118
  var container = $('<div>').
121
119
  append( jQuery.parseHTML(contents) ).find( Blacklight.modal.containerSelector ).first();
122
- if (container.size() !== 0) {
120
+ if (container.length !== 0) {
123
121
  contents = container.html();
124
122
  }
125
123
 
@@ -1,4 +1,3 @@
1
- //= require blacklight/core
2
1
  (function($) {
3
2
  Blacklight.doSearchContextBehavior = function() {
4
3
  if (typeof Blacklight.do_search_context_behavior == 'function') {
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  class Icon
3
5
  attr_reader :icon_name
@@ -35,6 +37,7 @@ module Blacklight
35
37
  # @return [String]
36
38
  def file_source
37
39
  raise Blacklight::Exceptions::IconNotFound, "Could not find #{path}" if file.blank?
40
+
38
41
  file.source.force_encoding('UTF-8')
39
42
  end
40
43
 
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Blacklight
3
4
  class SuggestSearch
4
5
  attr_reader :request_params, :repository
5
6
 
6
7
  ##
7
8
  # @param [Hash] params
9
+ # @param [Blacklight::AbstractRepository] repository
8
10
  def initialize(params, repository)
9
11
  @request_params = { q: params[:q] }
10
12
  @repository = repository
@@ -15,20 +17,7 @@ module Blacklight
15
17
  # Blacklight::Suggest::Response
16
18
  # @return [Blacklight::Suggest::Response]
17
19
  def suggestions
18
- Blacklight::Suggest::Response.new suggest_results, request_params, suggest_handler_path
19
- end
20
-
21
- ##
22
- # Query the suggest handler using RSolr::Client::send_and_receive
23
- # @return [RSolr::HashWithResponse]
24
- def suggest_results
25
- repository.connection.send_and_receive(suggest_handler_path, params: request_params)
26
- end
27
-
28
- ##
29
- # @return [String]
30
- def suggest_handler_path
31
- repository.blacklight_config.autocomplete_path
20
+ repository.suggestions(request_params)
32
21
  end
33
22
  end
34
23
  end
@@ -13,7 +13,7 @@ class Bookmark < ApplicationRecord
13
13
  def document_type
14
14
  value = super if defined?(super)
15
15
  value &&= value.constantize
16
- value ||= default_document_type
16
+ value || default_document_type
17
17
  end
18
18
 
19
19
  def default_document_type
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
- ##
2
+
3
+ require 'globalid'
4
+
3
5
  ##
4
6
  # = Introduction
5
7
  # Blacklight::Document is the module with logic for a class representing
@@ -25,6 +25,7 @@ module Blacklight::Solr::Document
25
25
 
26
26
  def has_highlight_field? k
27
27
  return false if response['highlighting'].blank? || response['highlighting'][id].blank?
28
+
28
29
  response['highlighting'][id].key? k.to_s
29
30
  end
30
31
 
@@ -2,17 +2,19 @@
2
2
  module Blacklight
3
3
  module Suggest
4
4
  class Response
5
- attr_reader :response, :request_params, :suggest_path
5
+ attr_reader :response, :request_params, :suggest_path, :suggester_name
6
6
 
7
7
  ##
8
8
  # Creates a suggest response
9
9
  # @param [RSolr::HashWithResponse] response
10
10
  # @param [Hash] request_params
11
11
  # @param [String] suggest_path
12
- def initialize(response, request_params, suggest_path)
12
+ # @param [String] suggester_name
13
+ def initialize(response, request_params, suggest_path, suggester_name)
13
14
  @response = response
14
15
  @request_params = request_params
15
16
  @suggest_path = suggest_path
17
+ @suggester_name = suggester_name
16
18
  end
17
19
 
18
20
  ##
@@ -20,7 +22,7 @@ module Blacklight
20
22
  # present
21
23
  # @return [Array]
22
24
  def suggestions
23
- response.try(:[], suggest_path).try(:[], 'mySuggester').try(:[], request_params[:q]).try(:[], 'suggestions') || []
25
+ (response.try(:[], suggest_path).try(:[], suggester_name).try(:[], request_params[:q]).try(:[], 'suggestions') || []).uniq
24
26
  end
25
27
  end
26
28
  end
@@ -6,6 +6,7 @@ module Blacklight::User
6
6
  # is injected into the hosting application through ActiveRecord::Base extend
7
7
  def self.included(base)
8
8
  return unless base.respond_to? :has_many
9
+
9
10
  base.send :has_many, :bookmarks, dependent: :destroy, as: :user
10
11
  base.send :has_many, :searches, dependent: :destroy, as: :user
11
12
  end
@@ -14,6 +14,7 @@ class Search < ApplicationRecord
14
14
  def self.delete_old_searches(days_old)
15
15
  raise ArgumentError, 'days_old is expected to be a number' unless days_old.is_a?(Numeric)
16
16
  raise ArgumentError, 'days_old is expected to be greater than 0' if days_old <= 0
17
+
17
18
  where(['created_at < ? AND user_id IS NULL', Time.zone.today - days_old]).destroy_all
18
19
  end
19
20
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ # An abstract class that the view presenters for SolrDocuments descend from
5
+ class DocumentPresenter
6
+ attr_reader :document, :configuration, :view_context
7
+
8
+ # @return [Hash<String,Configuration::Field>] all the fields for this index view that should be rendered
9
+ def fields_to_render
10
+ fields.select do |_name, field_config|
11
+ # rubocop:disable Style/PreferredHashMethods
12
+ render_field?(field_config) && has_value?(field_config)
13
+ # rubocop:enable Style/PreferredHashMethods
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ ##
20
+ # Check to see if the given field should be rendered in this context
21
+ # @param [Blacklight::Configuration::Field] field_config
22
+ # @return [Boolean]
23
+ def render_field?(field_config)
24
+ view_context.should_render_field?(field_config, document)
25
+ end
26
+
27
+ ##
28
+ # Check if a document has (or, might have, in the case of accessor methods) a value for
29
+ # the given solr field
30
+ # @param [Blacklight::Configuration::Field] field_config
31
+ # @return [Boolean]
32
+ def has_value? field_config
33
+ document.has?(field_config.field) ||
34
+ (document.has_highlight_field? field_config.field if field_config.highlight) ||
35
+ field_config.accessor
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  # Renders a field and handles link_to_facet or helper_method if supplied
3
5
  class FieldPresenter
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight
3
- class IndexPresenter
3
+ class IndexPresenter < DocumentPresenter
4
4
  class_attribute :thumbnail_presenter
5
5
  self.thumbnail_presenter = ThumbnailPresenter
6
6
 
7
- attr_reader :document, :configuration, :view_context, :view_config
7
+ attr_reader :view_config
8
8
 
9
9
  # @param [SolrDocument] document
10
10
  # @param [ActionView::Base] view_context scope for linking and generating urls
@@ -29,8 +29,12 @@ module Blacklight
29
29
  config = field_config(field_or_string_or_proc)
30
30
  document[field_or_string_or_proc]
31
31
  when Proc
32
+ Deprecation.warn(self, "calling IndexPresenter.label with a Proc is deprecated. " \
33
+ "First argument must be a symbol. This will be removed in Blacklight 8")
32
34
  field_or_string_or_proc.call(document, opts)
33
35
  when String
36
+ Deprecation.warn(self, "calling IndexPresenter.label with a String is deprecated. " \
37
+ "First argument must be a symbol. This will be removed in Blacklight 8")
34
38
  field_or_string_or_proc
35
39
  end
36
40
 
@@ -43,12 +47,11 @@ module Blacklight
43
47
  #
44
48
  # Allow an extention point where information in the document
45
49
  # may drive the value of the field
46
- # @param [String] field
50
+ # @param [Configuration::Field] field
47
51
  # @param [Hash] options
48
52
  # @option options [String] :value
49
53
  def field_value field, options = {}
50
- field_config = field_config(field)
51
- field_values(field_config, options)
54
+ field_values(field, options)
52
55
  end
53
56
 
54
57
  def thumbnail
@@ -57,6 +60,11 @@ module Blacklight
57
60
 
58
61
  private
59
62
 
63
+ # @return [Hash<String,Configuration::Field>] all the fields for this index view
64
+ def fields
65
+ configuration.index_fields_for(document)
66
+ end
67
+
60
68
  ##
61
69
  # Get the value for a document's field, and prepare to render it.
62
70
  # - highlight_field
@@ -4,10 +4,9 @@ module Blacklight
4
4
  include Blacklight::Facet
5
5
 
6
6
  # @param [Solr::Response] response raw solr response.
7
- # @param [Array] facets list of facets
8
- def initialize(response, facets, blacklight_config)
7
+ # @param [Configuration] blacklight_config the configuration
8
+ def initialize(response, blacklight_config)
9
9
  @response = response
10
- @facets = facets
11
10
  @blacklight_config = blacklight_config
12
11
  end
13
12
 
@@ -17,15 +16,9 @@ module Blacklight
17
16
  @response.documents
18
17
  end
19
18
 
20
- def search_facets_as_json
21
- @facets.as_json.each do |f|
22
- f.stringify_keys!
23
- f.delete "options"
24
- f["label"] = facet_configuration_for_field(f["name"]).label
25
- f["items"] = f["items"].as_json.each do |i|
26
- i['label'] ||= i['value']
27
- end
28
- end
19
+ # @return [Array<Blacklight::Solr::Response::Facets::FacetField>]
20
+ def search_facets
21
+ facets_from_request.select { |display_facet| display_facet.items.present? }
29
22
  end
30
23
 
31
24
  # extract the pagination info from the response object
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  # Create <link rel="alternate"> links from a documents dynamically
3
5
  class LinkAlternatePresenter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  module Rendering
3
5
  class AbstractStep
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  module Rendering
3
5
  class HelperMethod < AbstractStep
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  module Rendering
3
5
  class Join < AbstractStep
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  module Rendering
3
5
  class LinkToFacet < AbstractStep
4
6
  extend Deprecation
5
7
  def render
6
8
  return next_step(values) unless config.link_to_facet
9
+
7
10
  next_step(render_link)
8
11
  end
9
12
 
@@ -16,6 +19,7 @@ module Blacklight
16
19
 
17
20
  def link_field
18
21
  return config.key if config.link_to_facet == true
22
+
19
23
  config.link_to_facet
20
24
  end
21
25
 
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  module Rendering
3
5
  class Microdata < AbstractStep
4
6
  include ActionView::Helpers::TagHelper
5
7
  def render
6
8
  return next_step(values) unless config.itemprop
9
+
7
10
  next_step(values.map { |x| itemprop(x, config.itemprop) })
8
11
  end
9
12
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  module Rendering
3
5
  # The field rendering pipeline
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  module Rendering
3
5
  class Terminator < AbstractStep
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  class SearchBarPresenter
3
5
  attr_reader :configuration, :view_context, :controller
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight
3
- class ShowPresenter
4
- attr_reader :document, :configuration, :view_context
5
-
3
+ class ShowPresenter < DocumentPresenter
6
4
  # @param [SolrDocument] document
7
5
  # @param [ActionView::Base] view_context scope for linking and generating urls
8
6
  # @param [Blacklight::Configuration] configuration
@@ -58,15 +56,20 @@ module Blacklight
58
56
  #
59
57
  # Allow an extention point where information in the document
60
58
  # may drive the value of the field
61
- # @param [String] field
59
+ # @param [Configuration::Field] field
62
60
  # @param [Hash] options
63
61
  # @option options [String] :value
64
62
  def field_value field, options = {}
65
- field_values(field_config(field), options)
63
+ field_values(field, options)
66
64
  end
67
65
 
68
66
  private
69
67
 
68
+ # @return [Hash<String,Configuration::Field>]
69
+ def fields
70
+ configuration.show_fields_for(document)
71
+ end
72
+
70
73
  ##
71
74
  # Get the value for a document's field, and prepare to render it.
72
75
  # - highlight_field
@@ -6,6 +6,7 @@ module Blacklight
6
6
 
7
7
  # @param [SolrDocument] document
8
8
  # @param [ActionView::Base] view_context scope for linking and generating urls
9
+ # as well as for invoking "thumbnail_method"
9
10
  # @param [Blacklight::Configuration::ViewConfig] view_config
10
11
  def initialize(document, view_context, view_config)
11
12
  @document = document
@@ -33,6 +34,7 @@ module Blacklight
33
34
  def thumbnail_tag image_options = {}, url_options = {}
34
35
  value = thumbnail_value(image_options)
35
36
  return value if value.nil? || url_options[:suppress_link]
37
+
36
38
  view_context.link_to_document document, value, url_options
37
39
  end
38
40
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blacklight
2
4
  class DocumentFactory
3
5
  def self.build(data, response, options)