blacklight 7.11.1 → 7.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.solr_wrapper.yml +5 -0
  4. data/VERSION +1 -1
  5. data/app/builders/blacklight/action_builder.rb +6 -0
  6. data/app/components/blacklight/constraint_component.html.erb +5 -0
  7. data/app/components/blacklight/constraint_component.rb +13 -0
  8. data/app/components/blacklight/constraint_layout_component.rb +2 -1
  9. data/app/components/blacklight/constraints_component.html.erb +10 -0
  10. data/app/components/blacklight/constraints_component.rb +65 -0
  11. data/app/components/blacklight/document/action_component.html.erb +9 -0
  12. data/app/components/blacklight/document/action_component.rb +38 -0
  13. data/app/components/blacklight/document/actions_component.html.erb +13 -0
  14. data/app/components/blacklight/document/actions_component.rb +26 -0
  15. data/app/components/blacklight/document/bookmark_component.html.erb +1 -1
  16. data/app/components/blacklight/document/bookmark_component.rb +8 -0
  17. data/app/components/blacklight/document/citation_component.html.erb +4 -2
  18. data/app/components/blacklight/document/citation_component.rb +8 -1
  19. data/app/components/blacklight/document/group_component.html.erb +9 -0
  20. data/app/components/blacklight/document/group_component.rb +26 -0
  21. data/app/components/blacklight/document/more_like_this_component.rb +2 -0
  22. data/app/components/blacklight/document/thumbnail_component.html.erb +12 -0
  23. data/app/components/blacklight/document/thumbnail_component.rb +25 -0
  24. data/app/components/blacklight/document_component.rb +27 -26
  25. data/app/components/blacklight/facet_field_filter_component.html.erb +12 -0
  26. data/app/components/blacklight/facet_field_filter_component.rb +25 -0
  27. data/app/components/blacklight/facet_field_pagination_component.html.erb +19 -0
  28. data/app/components/blacklight/facet_field_pagination_component.rb +21 -0
  29. data/app/components/blacklight/facet_item_component.rb +4 -8
  30. data/app/components/blacklight/response/facet_group_component.html.erb +3 -1
  31. data/app/components/blacklight/response/facet_group_component.rb +8 -1
  32. data/app/components/blacklight/response/pagination_component.rb +3 -0
  33. data/app/components/blacklight/response/sort_component.html.erb +1 -1
  34. data/app/components/blacklight/response/spellcheck_component.rb +9 -2
  35. data/app/components/blacklight/response/view_type_component.html.erb +11 -0
  36. data/app/components/blacklight/response/view_type_component.rb +36 -0
  37. data/app/components/blacklight/search_bar_component.html.erb +1 -1
  38. data/app/components/blacklight/search_bar_component.rb +6 -0
  39. data/app/components/blacklight/search_context_component.rb +6 -2
  40. data/app/components/blacklight/system/dropdown_component.html.erb +1 -1
  41. data/app/components/blacklight/system/flash_message_component.html.erb +4 -0
  42. data/app/components/blacklight/system/flash_message_component.rb +24 -0
  43. data/app/controllers/concerns/blacklight/catalog.rb +7 -1
  44. data/app/controllers/concerns/blacklight/controller.rb +12 -3
  45. data/app/controllers/concerns/blacklight/facet.rb +19 -5
  46. data/app/controllers/concerns/blacklight/search_fields.rb +7 -1
  47. data/app/helpers/blacklight/blacklight_helper_behavior.rb +127 -17
  48. data/app/helpers/blacklight/catalog_helper_behavior.rb +36 -5
  49. data/app/helpers/blacklight/component_helper_behavior.rb +36 -6
  50. data/app/helpers/blacklight/configuration_helper_behavior.rb +32 -4
  51. data/app/helpers/blacklight/facets_helper_behavior.rb +31 -8
  52. data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +5 -0
  53. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +28 -11
  54. data/app/helpers/blacklight/render_partials_helper_behavior.rb +8 -3
  55. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +4 -2
  56. data/app/helpers/blacklight/suggest_helper_behavior.rb +1 -0
  57. data/app/helpers/blacklight/url_helper_behavior.rb +23 -3
  58. data/app/models/blacklight/icon.rb +0 -1
  59. data/app/models/concerns/blacklight/document.rb +1 -1
  60. data/app/models/concerns/blacklight/suggest/response.rb +1 -1
  61. data/app/models/record_mailer.rb +1 -1
  62. data/app/presenters/blacklight/document_presenter.rb +42 -1
  63. data/app/presenters/blacklight/facet_field_presenter.rb +3 -1
  64. data/app/presenters/blacklight/facet_item_presenter.rb +8 -0
  65. data/app/presenters/blacklight/field_presenter.rb +9 -6
  66. data/app/presenters/blacklight/json_presenter.rb +3 -1
  67. data/app/presenters/blacklight/show_presenter.rb +4 -30
  68. data/app/presenters/blacklight/thumbnail_presenter.rb +5 -1
  69. data/app/services/blacklight/document_factory.rb +3 -0
  70. data/app/services/blacklight/field_retriever.rb +18 -4
  71. data/app/services/blacklight/search_service.rb +0 -1
  72. data/app/views/bookmarks/_tools.html.erb +12 -7
  73. data/app/views/catalog/_bookmark_control.html.erb +1 -1
  74. data/app/views/catalog/_constraints.html.erb +12 -7
  75. data/app/views/catalog/_document.atom.builder +9 -6
  76. data/app/views/catalog/_document.rss.builder +4 -2
  77. data/app/views/catalog/_facet_index_navigation.html.erb +1 -10
  78. data/app/views/catalog/_facet_pagination.html.erb +1 -19
  79. data/app/views/catalog/_facets.html.erb +1 -1
  80. data/app/views/catalog/_group.html.erb +1 -9
  81. data/app/views/catalog/_index.html.erb +1 -1
  82. data/app/views/catalog/_search_results.html.erb +1 -1
  83. data/app/views/catalog/_show.html.erb +1 -1
  84. data/app/views/catalog/_show_header.html.erb +1 -1
  85. data/app/views/catalog/_show_main_content.html.erb +2 -2
  86. data/app/views/catalog/_show_tools.html.erb +12 -8
  87. data/app/views/catalog/_start_over.html.erb +1 -1
  88. data/app/views/catalog/_thumbnail.html.erb +1 -5
  89. data/app/views/catalog/_view_type_group.html.erb +5 -13
  90. data/app/views/catalog/index.json.jbuilder +8 -6
  91. data/app/views/catalog/show.json.jbuilder +1 -1
  92. data/app/views/shared/_flash_msg.html.erb +1 -15
  93. data/blacklight.gemspec +1 -0
  94. data/config/locales/blacklight.ca.yml +241 -0
  95. data/lib/blacklight/abstract_repository.rb +13 -4
  96. data/lib/blacklight/configuration.rb +11 -5
  97. data/lib/blacklight/configuration/display_field.rb +50 -0
  98. data/lib/blacklight/configuration/facet_field.rb +58 -1
  99. data/lib/blacklight/configuration/field.rb +13 -0
  100. data/lib/blacklight/configuration/index_field.rb +5 -0
  101. data/lib/blacklight/configuration/search_field.rb +3 -0
  102. data/lib/blacklight/configuration/show_field.rb +5 -0
  103. data/lib/blacklight/configuration/sort_field.rb +3 -0
  104. data/lib/blacklight/configuration/tool_config.rb +1 -0
  105. data/lib/blacklight/configuration/view_config.rb +25 -0
  106. data/lib/blacklight/search_state.rb +4 -2
  107. data/lib/blacklight/solr/repository.rb +1 -1
  108. data/lib/generators/blacklight/templates/catalog_controller.rb +8 -7
  109. data/spec/components/blacklight/document/action_component_spec.rb +43 -0
  110. data/spec/components/blacklight/document/group_component_spec.rb +45 -0
  111. data/spec/components/blacklight/document_component_spec.rb +8 -0
  112. data/spec/components/blacklight/facet_item_pivot_component_spec.rb +0 -1
  113. data/spec/components/blacklight/system/flash_message_component_spec.rb +54 -0
  114. data/spec/controllers/blacklight/search_fields_spec.rb +2 -0
  115. data/spec/controllers/catalog_controller_spec.rb +2 -0
  116. data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +6 -1
  117. data/spec/helpers/blacklight/hash_as_hidden_fields_behavior_spec.rb +2 -0
  118. data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +2 -0
  119. data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +3 -1
  120. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +2 -0
  121. data/spec/helpers/blacklight_helper_spec.rb +10 -0
  122. data/spec/helpers/catalog_helper_spec.rb +4 -4
  123. data/spec/lib/blacklight/configuration/facet_field_spec.rb +17 -0
  124. data/spec/models/blacklight/search_builder_spec.rb +1 -1
  125. data/spec/models/blacklight/solr/search_builder_spec.rb +8 -0
  126. data/spec/presenters/blacklight/field_presenter_spec.rb +30 -5
  127. data/spec/services/blacklight/search_service_spec.rb +1 -5
  128. data/spec/views/catalog/_constraints.html.erb_spec.rb +2 -1
  129. data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +4 -2
  130. data/spec/views/catalog/_show_tools.html.erb_spec.rb +8 -8
  131. data/spec/views/catalog/show.json.jbuilder_spec.rb +1 -0
  132. data/tasks/blacklight.rake +27 -12
  133. metadata +47 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74d6e5485343fa8fc02b71d94e374d2f2d0a49f05e9bbf2e2226fe02088213f4
4
- data.tar.gz: d1894865278720fc03af712e6cb424eaa1f3c30aa0f71666be7a301052663562
3
+ metadata.gz: 795afb3fdb4a13aa033d1b37180537e51ebfd53ab8f0ef894d05b6370b1c1238
4
+ data.tar.gz: 003ccd0c42c44636d463df31c141a7b9b6ab1276bab6d771d1637d2eb7ff17fc
5
5
  SHA512:
6
- metadata.gz: 9d40718c50283de79a47a70e77c3cdd5e13a92edf1eb657d749c96f25fd473523a09f4d68e594adf3d2f5cb3a6e249d6ebd61bf7ec349a4bc97ffad8b213fc5e
7
- data.tar.gz: d3732c39e9672c23943b01aef361d29fc7cfb3f1f9d6e243770b72cc6ac61677cee2f478ae8cf50120d51d3978eda85492d4f386a15820b04d6350bfac53219c
6
+ metadata.gz: 1e9cdd317ae4535217bc98930c09095ca8aaebe01124863b6a507a2c9bfbd4851a18d72f139bbb6c2f152094e1cb3cf3462eea26747f3212dc484c24603f6ec4
7
+ data.tar.gz: a7f142dbaaabff9a9477d116ccd283ab67b2e72fb6d5f0c0482b495ed57f69486aa73f3ef6f67b31f0d00316d1dfb0b61fffaae08ebd1208aebae18a495c9746
@@ -29,6 +29,7 @@ Layout/IndentationConsistency:
29
29
  Metrics/BlockLength:
30
30
  Exclude:
31
31
  - "app/views/catalog/index.json.jbuilder"
32
+ - "app/views/catalog/_document.atom.builder"
32
33
  - "lib/railties/blacklight.rake"
33
34
  - "tasks/blacklight.rake"
34
35
  - "spec/**/*"
@@ -42,6 +43,10 @@ Layout/LineLength:
42
43
  Exclude:
43
44
  - 'spec/**/*'
44
45
 
46
+ Metrics/ModuleLength:
47
+ Exclude:
48
+ - 'app/controllers/concerns/blacklight/catalog.rb'
49
+
45
50
  Naming/HeredocDelimiterNaming:
46
51
  Enabled: false
47
52
 
@@ -57,6 +62,9 @@ Naming/PredicateName:
57
62
  Rails:
58
63
  Enabled: true
59
64
 
65
+ Rails/ApplicationMailer:
66
+ Enabled: false
67
+
60
68
  # https://github.com/rubocop-hq/rubocop/issues/6439
61
69
  Style/AccessModifierDeclarations:
62
70
  Enabled: false
@@ -0,0 +1,5 @@
1
+ # Place any default configuration for solr_wrapper here
2
+ # port: 8983
3
+ collection:
4
+ dir: lib/generators/blacklight/templates/solr/conf
5
+ name: blacklight-core
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.11.1
1
+ 7.12.0
@@ -4,6 +4,12 @@ module Blacklight
4
4
  # Dynamically creates methods on the given controller (typically CatalogController)
5
5
  # for handling configured show tools
6
6
  class ActionBuilder
7
+ # @param [Object] klass
8
+ # @param [String] name
9
+ # @param [Hash] opts
10
+ # @option opts [Symbol] callback
11
+ # @option opts [Symbol] validator
12
+ # @option opts [Boolean] define_method
7
13
  def initialize(klass, name, opts)
8
14
  @klass = klass
9
15
  @name = name
@@ -0,0 +1,5 @@
1
+ <%= render(@layout.new(
2
+ classes: (Array(@classes) + ["filter-#{@facet_item_presenter.facet_config.key.parameterize}"]).join(' '),
3
+ label: @facet_item_presenter.field_label,
4
+ value: @facet_item_presenter.label,
5
+ remove_path: @facet_item_presenter.remove_href)) %>
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ class ConstraintComponent < ::ViewComponent::Base
5
+ with_collection_parameter :facet_item_presenter
6
+
7
+ def initialize(facet_item_presenter:, classes: 'filter', layout: Blacklight::ConstraintLayoutComponent)
8
+ @facet_item_presenter = facet_item_presenter
9
+ @classes = classes
10
+ @layout = layout
11
+ end
12
+ end
13
+ end
@@ -2,11 +2,12 @@
2
2
 
3
3
  module Blacklight
4
4
  class ConstraintLayoutComponent < ::ViewComponent::Base
5
- def initialize(value:, label: nil, remove_path: nil, classes: nil)
5
+ def initialize(value:, label: nil, remove_path: nil, classes: nil, search_state: nil)
6
6
  @value = value
7
7
  @label = label
8
8
  @remove_path = remove_path
9
9
  @classes = Array(classes).join(' ')
10
+ @search_state = search_state
10
11
  end
11
12
 
12
13
  def render?
@@ -0,0 +1,10 @@
1
+ <%= content_tag :div, id: @id, class: @classes do %>
2
+ <h2 class="sr-only"><%= t('blacklight.search.search_constraints_header') %></h2>
3
+
4
+ <%= link_to t('blacklight.search.start_over'), start_over_path, class: "catalog_startOverLink btn btn-primary" %>
5
+
6
+ <span class="constraints-label sr-only"><%= t('blacklight.search.filters.title') %></span>
7
+ <%= query_constraints_area || query_constraints %>
8
+ <%= facet_constraints_area || facet_constraints %>
9
+ <%= additional_constraints %>
10
+ <% end %>
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ class ConstraintsComponent < ::ViewComponent::Base
5
+ with_content_areas :query_constraints_area, :facet_constraints_area, :additional_constraints
6
+
7
+ def initialize(search_state:,
8
+ id: 'appliedParams', classes: 'clearfix constraints-container',
9
+ query_constraint_component: Blacklight::ConstraintLayoutComponent, facet_constraint_component: Blacklight::ConstraintComponent)
10
+ @search_state = search_state
11
+ @query_constraint_component = query_constraint_component
12
+ @facet_constraint_component = facet_constraint_component
13
+ @id = id
14
+ @classes = classes
15
+ end
16
+
17
+ def query_constraints
18
+ return if @search_state.query_param.blank?
19
+
20
+ Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
21
+ @view_context.render(
22
+ @query_constraint_component.new(
23
+ search_state: @search_state,
24
+ value: @search_state.query_param,
25
+ label: @view_context.constraint_query_label(@search_state.params),
26
+ remove_path: @view_context.remove_constraint_url(@search_state),
27
+ classes: 'query'
28
+ )
29
+ )
30
+ end
31
+ end
32
+
33
+ def facet_constraints
34
+ @view_context.render(@facet_constraint_component.with_collection(facet_item_presenters))
35
+ end
36
+
37
+ def start_over_path
38
+ Deprecation.silence(Blacklight::UrlHelperBehavior) do
39
+ @view_context.start_over_path
40
+ end
41
+ end
42
+
43
+ def render?
44
+ Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) { @view_context.query_has_constraints? }
45
+ end
46
+
47
+ private
48
+
49
+ def facet_item_presenters
50
+ @search_state.filter_params.each_pair.flat_map do |facet, values|
51
+ facet_config = @view_context.facet_configuration_for_field(facet)
52
+
53
+ Array(values).map do |val|
54
+ next if val.blank? # skip empty string
55
+
56
+ facet_item_presenter(facet_config, val, facet)
57
+ end
58
+ end
59
+ end
60
+
61
+ def facet_item_presenter(facet_config, facet_item, facet_field)
62
+ Blacklight::FacetItemPresenter.new(facet_item, facet_config, @view_context, facet_field)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,9 @@
1
+ <% if using_default_document_action? %>
2
+ <%= link_to label,
3
+ url,
4
+ id: @id,
5
+ class: 'nav-link',
6
+ data: {}.merge(({ blacklight_modal: "trigger" } if @action.modal != false) || {}) %>
7
+ <% else %>
8
+ <%= @view_context.render(partial: @action.partial || @action.name.to_s, locals: { document: @document, document_action_config: @action }.merge(@options)) %>
9
+ <% end %>
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ module Document
5
+ # Render a bookmark widget to bookmark / unbookmark a document
6
+ class ActionComponent < ::ViewComponent::Base
7
+ with_collection_parameter :action
8
+
9
+ # @param [Blacklight::Document] document
10
+ def initialize(document:, action:, options: {}, url_opts: {}, id: nil)
11
+ @document = document
12
+ @action = action
13
+ @options = options
14
+ @url_opts = url_opts
15
+ @id = id || @action.fetch(:id, "#{@action.name}Link")
16
+ end
17
+
18
+ def using_default_document_action?
19
+ return true if @action.component
20
+ return false unless @action.partial == 'document_action'
21
+
22
+ @view_context.partial_from_blacklight?(@action.partial)
23
+ end
24
+
25
+ def label
26
+ Deprecation.silence(Blacklight::ComponentHelperBehavior) do
27
+ @view_context.document_action_label(@action.name, @action)
28
+ end
29
+ end
30
+
31
+ def url
32
+ Deprecation.silence(Blacklight::ComponentHelperBehavior) do
33
+ @view_context.document_action_path(@action, @url_opts.merge(({ id: @document } if @document) || {}))
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ <%= content_tag @tag, class: @classes do %>
2
+ <% @actions.each do |action| %>
3
+ <% result = capture { @view_context.render((action.component || Blacklight::Document::ActionComponent).new(action: action, document: @document, options: @options, url_opts: @url_opts)) } %>
4
+
5
+ <% if @wrapping_tag %>
6
+ <%= content_tag(@wrapping_tag, class: Array(@wrapping_classes) + [action.key]) do %>
7
+ <%= result %>
8
+ <% end %>
9
+ <% else %>
10
+ <%= result %>
11
+ <% end %>
12
+ <% end %>
13
+ <% end %>
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ module Document
5
+ # Render a bookmark widget to bookmark / unbookmark a document
6
+ class ActionsComponent < ::ViewComponent::Base
7
+ # @param [Blacklight::Document] document
8
+ # rubocop:disable Metrics/ParameterLists
9
+ def initialize(document: nil, actions: [], options: {}, url_opts: nil, tag: :div, classes: 'index-document-functions', wrapping_tag: nil, wrapping_classes: nil)
10
+ @document = document
11
+ @actions = actions
12
+ @tag = tag
13
+ @classes = classes
14
+ @options = options
15
+ @url_opts = url_opts
16
+ @wrapping_tag = wrapping_tag
17
+ @wrapping_classes = wrapping_classes
18
+ end
19
+ # rubocop:enable Metrics/ParameterLists
20
+
21
+ def render?
22
+ @actions.any?
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,7 +1,7 @@
1
1
  <%-
2
2
  # the data-doc-id attribute is used by our JS that converts to a checkbox/label.
3
3
  -%>
4
- <%= form_tag(@bookmark_path,
4
+ <%= form_tag(bookmark_path,
5
5
  method: bookmarked? ? :delete : :put,
6
6
  class: "bookmark-toggle",
7
7
  data: {
@@ -2,7 +2,11 @@
2
2
 
3
3
  module Blacklight
4
4
  module Document
5
+ # Render a bookmark widget to bookmark / unbookmark a document
5
6
  class BookmarkComponent < ::ViewComponent::Base
7
+ # @param [Blacklight::Document] document
8
+ # @param [Boolean] checked
9
+ # @param [Object] bookmark_path the rails route to use for bookmarks
6
10
  def initialize(document:, checked: nil, bookmark_path: nil)
7
11
  @document = document
8
12
  @checked = checked
@@ -14,6 +18,10 @@ module Blacklight
14
18
 
15
19
  @view_context.bookmarked? @document
16
20
  end
21
+
22
+ def bookmark_path
23
+ @bookmark_path || @view_context.bookmark_path(@document)
24
+ end
17
25
  end
18
26
  end
19
27
  end
@@ -1,9 +1,11 @@
1
1
  <div>
2
2
  <h1 class="modal-title"><%= title %></h1>
3
3
 
4
- <%= @formats.each do |i18n_key, citation_method| %>
4
+ <% @formats.each do |i18n_key, citation_method| %>
5
5
  <h2><%= t(i18n_key) %></h2>
6
6
  <%= @document.send(citation_method).html_safe %>
7
- <% unless @formats.keys.last === i18n_key %><br/><br/><% end %>
7
+ <% unless @formats.keys.last === i18n_key %>
8
+ <br/><br/>
9
+ <% end %>
8
10
  <% end %>
9
11
  </div>
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Blacklight
4
4
  module Document
5
+ # Render citations for the document
5
6
  class CitationComponent < ::ViewComponent::Base
6
7
  DEFAULT_FORMATS = {
7
8
  'blacklight.citation.mla': :export_as_mla_citation_txt,
@@ -11,13 +12,19 @@ module Blacklight
11
12
 
12
13
  with_collection_parameter :document
13
14
 
15
+ # @param [Blacklight::Document] document
16
+ # @param [Hash<String => Symbol>] map of citation format names (suspiciously, i18n keys
17
+ # for them) to document methods that return the formatted citation.
14
18
  def initialize(document:, formats: DEFAULT_FORMATS)
15
19
  @document = document
16
20
  @formats = formats.select { |_k, v| @document.respond_to?(v) }
17
21
  end
18
22
 
23
+ # @return [String]
19
24
  def title
20
- @view_context.document_heading(@document)
25
+ Deprecation.silence(Blacklight::BlacklightHelperBehavior) do
26
+ @view_context.document_heading(@document)
27
+ end
21
28
  end
22
29
  end
23
30
  end
@@ -0,0 +1,9 @@
1
+ <div class="group">
2
+ <h2 class="group-key"><%= @group.key %></h2>
3
+ <div class="grouped-documents">
4
+ <%= grouped_documents %>
5
+ </div>
6
+ <%- if @group_limit > 0 && @group.total > @group_limit %>
7
+ <%= @view_context.link_to t('blacklight.search.group.more'), add_group_facet_params_and_redirect(@group), class: 'more-in-group' %>
8
+ <%- end %>
9
+ </div>
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ module Document
5
+ # Render the 'more like this' results from the response
6
+ class GroupComponent < ::ViewComponent::Base
7
+ with_collection_parameter :group
8
+
9
+ # @param [Blacklight::Document] document
10
+ def initialize(group:, group_limit: -1)
11
+ @group = group
12
+ @group_limit = group_limit
13
+ end
14
+
15
+ def grouped_documents
16
+ @view_context.render_document_index @group.docs
17
+ end
18
+
19
+ def add_group_facet_params_and_redirect(group)
20
+ Deprecation.silence(Blacklight::UrlHelperBehavior) do
21
+ @view_context.search_action_path(@view_context.add_group_facet_params_and_redirect(group))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -2,9 +2,11 @@
2
2
 
3
3
  module Blacklight
4
4
  module Document
5
+ # Render the 'more like this' results from the response
5
6
  class MoreLikeThisComponent < ::ViewComponent::Base
6
7
  with_collection_parameter :document
7
8
 
9
+ # @param [Blacklight::Document] document
8
10
  def initialize(document:)
9
11
  @document = document
10
12
  end
@@ -0,0 +1,12 @@
1
+ <% value = @use_thumbnail_tag ? @presenter.thumbnail.thumbnail_tag({ alt: '' }, 'aria-hidden': true, tabindex: -1, counter: @counter) : @presenter.thumbnail.render({ alt: '' }) %>
2
+
3
+ <% if value %>
4
+ <div class="document-thumbnail">
5
+ <% if @use_thumbnail_tag %>
6
+ <% warn_about_deprecated_behavior %>
7
+ <%= value %>
8
+ <% else %>
9
+ <%= @view_context.link_to_document(@presenter.document, value, 'aria-hidden': true, tabindex: -1, counter: @counter) %>
10
+ <% end %>
11
+ </div>
12
+ <% end %>
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ module Document
5
+ # Render the thumbnail for the document
6
+ class ThumbnailComponent < ::ViewComponent::Base
7
+ with_collection_parameter :presenter
8
+
9
+ # @param [Blacklight::DocumentPresenter] presenter
10
+ def initialize(presenter:, counter:)
11
+ @presenter = presenter
12
+ @counter = counter
13
+ @use_thumbnail_tag = @presenter.thumbnail != Blacklight::ThumbnailPresenter
14
+ end
15
+
16
+ def render?
17
+ @presenter.thumbnail.exists?
18
+ end
19
+
20
+ def warn_about_deprecated_behavior
21
+ Deprecation.warn(Blacklight::Document::ThumbnailComponent, 'Detected as custom thumbnail presenter; make sure it has a #render method that returns just the thumbnail image tag')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -18,9 +18,15 @@ module Blacklight
18
18
  # @param component [Symbol, String] HTML tag type to use for the root element
19
19
  # @param title_component [Symbol, String] HTML tag type to use for the title element
20
20
  # @param metadata_component [Blacklight::DocumentMetadataComponent]
21
- # @param counter [Number, nil]
21
+ # @param counter [Number, nil] a pre-computed counter for the position of this document in a search result set
22
+ # @param document_counter [Number, nil] alternatively, the document's position in a collection and,
23
+ # @param counter_offset [Number] with `document_counter`, the offset of the start of that collection counter to the overall result set
22
24
  # @param show [Boolean] are we showing only a single document (vs a list of search results); used for backwards-compatibility
23
- def initialize(document: nil, presenter: nil, id: nil, classes: [], component: :article, title_component: :h4, metadata_component: Blacklight::DocumentMetadataComponent, counter: nil, show: false)
25
+ def initialize(document: nil, presenter: nil,
26
+ id: nil, classes: [], component: :article, title_component: :h4,
27
+ metadata_component: Blacklight::DocumentMetadataComponent,
28
+ counter: nil, document_counter: nil, counter_offset: 0,
29
+ show: false)
24
30
  if presenter.nil? && document.nil?
25
31
  raise ArgumentError, 'missing keyword: :document or :presenter'
26
32
  end
@@ -36,6 +42,7 @@ module Blacklight
36
42
  @metadata_component = metadata_component
37
43
 
38
44
  @counter = counter
45
+ @counter ||= document_counter + 1 + counter_offset if document_counter.present?
39
46
 
40
47
  @show = show
41
48
  end
@@ -53,44 +60,44 @@ module Blacklight
53
60
 
54
61
  # Content for the document title area; should be an inline element
55
62
  def title
56
- @title || begin
57
- if show?
58
- content_tag('span', presenter.heading, itemprop: "name")
59
- else
60
- @view_context.link_to_document @document, counter: @counter, itemprop: 'name'
61
- end
62
- end
63
+ return super if block_given?
64
+
65
+ @title || if show?
66
+ content_tag('span', presenter.heading, itemprop: "name")
67
+ else
68
+ @view_context.link_to_document @document, counter: @counter, itemprop: 'name'
69
+ end
63
70
  end
64
71
 
65
72
  # Content for the document actions area
66
73
  def actions
74
+ return super if block_given?
75
+
67
76
  return if @show
68
77
 
69
- @actions || begin
70
- @view_context.render_index_doc_actions @document, wrapping_class: "index-document-functions col-sm-3 col-lg-2"
71
- end
78
+ @actions ||
79
+ @view_context.render_index_doc_actions(@document, wrapping_class: "index-document-functions col-sm-3 col-lg-2")
72
80
  end
73
81
 
74
82
  # Content for the document thumbnail area
75
83
  def thumbnail
84
+ return super if block_given?
76
85
  return if @show
77
86
 
78
- @thumbnail || begin
79
- return unless presenter.thumbnail.exists?
80
-
81
- content_tag :div, class: "document-thumbnail" do
82
- presenter.thumbnail.thumbnail_tag({ alt: '' }, 'aria-hidden': true, tabindex: -1, counter: @counter)
83
- end
84
- end
87
+ @thumbnail || render(Blacklight::Document::ThumbnailComponent.new(presenter: presenter, counter: @counter))
85
88
  end
86
89
 
87
90
  # Content for the document metadata area
88
91
  def metadata
92
+ return super if block_given?
93
+
89
94
  @metadata || @view_context.render(@metadata_component.new(fields: presenter.field_presenters, show: show?))
90
95
  end
91
96
 
92
97
  # Content that goes before the document title (e.g. the counter)
93
98
  def before_title
99
+ return super if block_given?
100
+
94
101
  @before_title || counter
95
102
  end
96
103
 
@@ -105,13 +112,7 @@ module Blacklight
105
112
  end
106
113
 
107
114
  def presenter
108
- @presenter ||= begin
109
- if show?
110
- @view_context.presenter(@document)
111
- else
112
- @view_context.index_presenter(@document)
113
- end
114
- end
115
+ @presenter ||= @view_context.document_presenter(@document)
115
116
  end
116
117
 
117
118
  def show?