blacklight 7.5.1 → 7.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.docker/app/Dockerfile +26 -0
  3. data/.docker/app/entrypoint.sh +6 -0
  4. data/.env +5 -0
  5. data/.gitignore +0 -1
  6. data/.rubocop_todo.yml +25 -36
  7. data/.travis.yml +15 -23
  8. data/Gemfile +4 -1
  9. data/README.md +4 -0
  10. data/VERSION +1 -1
  11. data/app/assets/stylesheets/blacklight/_facets.scss +20 -4
  12. data/app/assets/stylesheets/blacklight/_pagination.scss +4 -0
  13. data/app/components/blacklight/constraint_layout_component.html.erb +23 -0
  14. data/app/components/blacklight/constraint_layout_component.rb +16 -0
  15. data/app/components/blacklight/facet_field_component.html.erb +25 -0
  16. data/app/components/blacklight/facet_field_component.rb +11 -0
  17. data/app/components/blacklight/facet_field_list_component.html.erb +18 -0
  18. data/app/components/blacklight/facet_field_list_component.rb +22 -0
  19. data/app/components/blacklight/facet_field_no_layout_component.rb +13 -0
  20. data/app/components/blacklight/facet_item_component.rb +120 -0
  21. data/app/components/blacklight/facet_item_pivot_component.rb +84 -0
  22. data/app/helpers/blacklight/blacklight_helper_behavior.rb +4 -2
  23. data/app/helpers/blacklight/catalog_helper_behavior.rb +2 -4
  24. data/app/helpers/blacklight/configuration_helper_behavior.rb +3 -2
  25. data/app/helpers/blacklight/facets_helper_behavior.rb +92 -49
  26. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +64 -33
  27. data/app/javascript/blacklight/modal.js +1 -1
  28. data/app/models/blacklight/icon.rb +13 -11
  29. data/app/models/concerns/blacklight/document.rb +0 -10
  30. data/app/models/concerns/blacklight/document/extensions.rb +3 -0
  31. data/app/models/concerns/blacklight/document/semantic_fields.rb +0 -4
  32. data/app/presenters/blacklight/document_presenter.rb +27 -36
  33. data/app/presenters/blacklight/facet_field_presenter.rb +57 -0
  34. data/app/presenters/blacklight/facet_item_presenter.rb +81 -0
  35. data/app/presenters/blacklight/field_presenter.rb +31 -6
  36. data/app/presenters/blacklight/index_presenter.rb +2 -2
  37. data/app/presenters/blacklight/show_presenter.rb +3 -3
  38. data/app/views/catalog/_citation.html.erb +1 -1
  39. data/app/views/catalog/_constraints.html.erb +3 -3
  40. data/app/views/catalog/_constraints_element.html.erb +5 -24
  41. data/app/views/catalog/_email_form.html.erb +1 -1
  42. data/app/views/catalog/_facet_layout.html.erb +8 -17
  43. data/app/views/catalog/_facet_limit.html.erb +3 -12
  44. data/app/views/catalog/_facet_pagination.html.erb +2 -2
  45. data/app/views/catalog/_facet_pivot.html.erb +3 -18
  46. data/app/views/catalog/_field.json.jbuilder +2 -2
  47. data/app/views/catalog/_index.html.erb +3 -3
  48. data/app/views/catalog/_previous_next_doc.html.erb +5 -5
  49. data/app/views/catalog/_search_form.html.erb +1 -1
  50. data/app/views/catalog/_show.html.erb +3 -3
  51. data/app/views/catalog/_sms_form.html.erb +1 -1
  52. data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
  53. data/app/views/catalog/_start_over.html.erb +1 -0
  54. data/app/views/catalog/_thumbnail.html.erb +1 -1
  55. data/app/views/catalog/index.json.jbuilder +2 -1
  56. data/app/views/catalog/show.html.erb +1 -1
  57. data/app/views/catalog/show.json.jbuilder +2 -1
  58. data/app/views/layouts/blacklight/base.html.erb +2 -2
  59. data/blacklight.gemspec +1 -0
  60. data/config/locales/blacklight.ar.yml +33 -24
  61. data/config/locales/blacklight.de.yml +5 -0
  62. data/config/locales/blacklight.en.yml +5 -0
  63. data/config/locales/blacklight.es.yml +5 -0
  64. data/config/locales/blacklight.fr.yml +5 -0
  65. data/config/locales/blacklight.hu.yml +5 -0
  66. data/config/locales/blacklight.it.yml +5 -0
  67. data/config/locales/blacklight.nl.yml +5 -0
  68. data/config/locales/blacklight.pt-BR.yml +5 -0
  69. data/config/locales/blacklight.sq.yml +5 -0
  70. data/config/locales/blacklight.zh.yml +5 -0
  71. data/docker-compose.yml +35 -0
  72. data/lib/blacklight/configuration.rb +35 -8
  73. data/lib/blacklight/configuration/field.rb +5 -4
  74. data/lib/blacklight/engine.rb +2 -6
  75. data/lib/blacklight/search_state.rb +52 -0
  76. data/lib/blacklight/solr/response/facets.rb +2 -0
  77. data/lib/generators/blacklight/assets_generator.rb +10 -0
  78. data/lib/generators/blacklight/templates/catalog_controller.rb +1 -1
  79. data/package-lock.json +4 -4
  80. data/package.json +2 -2
  81. data/spec/{views/catalog/_constraints_element.html.erb_spec.rb → components/blacklight/constraint_layout_component_spec.rb} +22 -12
  82. data/spec/components/blacklight/facet_field_list_component_spec.rb +108 -0
  83. data/spec/components/blacklight/facet_item_component_spec.rb +50 -0
  84. data/spec/components/blacklight/facet_item_pivot_component_spec.rb +66 -0
  85. data/spec/features/facets_spec.rb +21 -1
  86. data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +3 -0
  87. data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +24 -12
  88. data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +4 -23
  89. data/spec/helpers/blacklight_helper_spec.rb +17 -0
  90. data/spec/helpers/catalog_helper_spec.rb +0 -7
  91. data/spec/lib/blacklight/search_state_spec.rb +50 -0
  92. data/spec/models/blacklight/configuration_spec.rb +4 -0
  93. data/spec/models/blacklight/icon_spec.rb +11 -10
  94. data/spec/models/blacklight/solr/response/facets_spec.rb +30 -1
  95. data/spec/presenters/blacklight/document_presenter_spec.rb +22 -62
  96. data/spec/presenters/blacklight/facet_field_presenter_spec.rb +109 -0
  97. data/spec/presenters/blacklight/facet_item_presenter_spec.rb +92 -0
  98. data/spec/presenters/blacklight/field_presenter_spec.rb +268 -0
  99. data/spec/presenters/blacklight/index_presenter_spec.rb +0 -142
  100. data/spec/presenters/blacklight/show_presenter_spec.rb +0 -177
  101. data/spec/spec_helper.rb +3 -0
  102. data/spec/support/presenter_test_helpers.rb +11 -0
  103. data/spec/views/catalog/_facet_group.html.erb_spec.rb +1 -0
  104. data/spec/views/catalog/_previous_next_doc.html.erb_spec.rb +18 -0
  105. data/tasks/blacklight.rake +30 -23
  106. metadata +51 -7
  107. data/Vagrantfile +0 -79
  108. data/provision.sh +0 -30
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ class FacetFieldComponent < ::ViewComponent::Base
5
+ with_content_areas :label, :body
6
+
7
+ def initialize(facet_field:)
8
+ @facet_field = facet_field
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ <%= render(@layout.new(facet_field: @facet_field)) do |component| %>
2
+ <% component.with(:label) do %>
3
+ <%= @facet_field.label %>
4
+ <% end %>
5
+ <% component.with(:body) do %>
6
+ <ul class="facet-values list-unstyled">
7
+ <%= render_facet_limit_list @facet_field.paginator, @facet_field.key %>
8
+ </ul>
9
+ <%# backwards compatibility, ugh %>
10
+ <% if @layout == Blacklight::FacetFieldNoLayoutComponent && !@facet_field.in_modal? && @facet_field.modal_path %>
11
+ <div class="more_facets">
12
+ <%= link_to t("more_#{@facet_field.key}_html", scope: 'blacklight.search.facets', default: :more_html, field_name: @facet_field.label),
13
+ @facet_field.modal_path,
14
+ data: { blacklight_modal: 'trigger' } %>
15
+ </div>
16
+ <% end %>
17
+ <% end %>
18
+ <% end %>
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ class FacetFieldListComponent < ::ViewComponent::Base
5
+ def initialize(facet_field:, layout: nil)
6
+ @facet_field = facet_field
7
+ @layout = layout == false ? FacetFieldNoLayoutComponent : Blacklight::FacetFieldComponent
8
+ end
9
+
10
+ # Here for backwards compatibility only.
11
+ # @private
12
+ def render_facet_limit_list(*args)
13
+ Deprecation.silence(Blacklight::FacetsHelperBehavior) do
14
+ @view_context.render_facet_limit_list(*args)
15
+ end
16
+ end
17
+
18
+ def render?
19
+ @facet_field.paginator.items.any?
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ class FacetFieldNoLayoutComponent < ::ViewComponent::Base
5
+ with_content_areas :label, :body
6
+
7
+ def initialize(**); end
8
+
9
+ def call
10
+ body
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ class FacetItemComponent < ::ViewComponent::Base
5
+ with_collection_parameter :facet_item
6
+
7
+ def initialize(facet_item:, wrapping_element: 'li', suppress_link: false)
8
+ @facet_item = facet_item
9
+ @label = facet_item.label
10
+ @hits = facet_item.hits
11
+ @href = facet_item.href
12
+ @selected = facet_item.selected?
13
+ @wrapping_element = wrapping_element
14
+ @suppress_link = suppress_link
15
+ end
16
+
17
+ def call
18
+ # if the downstream app has overridden the helper methods we'd usually call,
19
+ # use the helpers to preserve compatibility
20
+ content = if overridden_helper_methods?
21
+ content_from_legacy_view_helper
22
+ elsif @selected
23
+ render_selected_facet_value
24
+ else
25
+ render_facet_value
26
+ end
27
+
28
+ return if content.blank?
29
+ return content unless @wrapping_element
30
+
31
+ content_tag @wrapping_element, content
32
+ end
33
+
34
+ # This is a little shim to let us call the render methods below outside the
35
+ # usual component rendering cycle (for backward compatibility)
36
+ # @private
37
+ # @deprecated
38
+ def with_view_context(view_context)
39
+ @view_context = view_context
40
+ self
41
+ end
42
+
43
+ # Check if the downstream application has overridden these methods
44
+ # @deprecated
45
+ # @private
46
+ def overridden_helper_methods?
47
+ return false if explicit_component_configuration?
48
+
49
+ @view_context.method(:render_facet_item).owner != Blacklight::FacetsHelperBehavior ||
50
+ @view_context.method(:render_facet_value).owner != Blacklight::FacetsHelperBehavior ||
51
+ @view_context.method(:render_selected_facet_value).owner != Blacklight::FacetsHelperBehavior
52
+ end
53
+
54
+ # Call out to the helper method equivalent of this component
55
+ # @deprecated
56
+ # @private
57
+ def content_from_legacy_view_helper
58
+ Deprecation.warn('Calling out to the #render_facet_item helper for backwards compatibility.')
59
+ Deprecation.silence(Blacklight::FacetsHelperBehavior) do
60
+ @view_context.render_facet_item(@facet_item.facet_field, @facet_item.facet_item)
61
+ end
62
+ end
63
+
64
+ ##
65
+ # Standard display of a facet value in a list. Used in both _facets sidebar
66
+ # partial and catalog/facet expanded list. Will output facet value name as
67
+ # a link to add that to your restrictions, with count in parens.
68
+ #
69
+ # @param [Blacklight::Solr::Response::Facets::FacetField] facet_field
70
+ # @param [Blacklight::Solr::Response::Facets::FacetItem] item
71
+ # @param [Hash] options
72
+ # @option options [Boolean] :suppress_link display the facet, but don't link to it
73
+ # @return [String]
74
+ # @private
75
+ def render_facet_value
76
+ content_tag(:span, class: "facet-label") do
77
+ link_to_unless(@suppress_link, @label, @href, class: "facet-select")
78
+ end + render_facet_count
79
+ end
80
+
81
+ ##
82
+ # Standard display of a SELECTED facet value (e.g. without a link and with a remove button)
83
+ # @see #render_facet_value
84
+ # @param [Blacklight::Solr::Response::Facets::FacetField] facet_field
85
+ # @param [String] item
86
+ # @private
87
+ def render_selected_facet_value
88
+ content_tag(:span, class: "facet-label") do
89
+ content_tag(:span, @label, class: "selected") +
90
+ # remove link
91
+ link_to(@href, class: "remove") do
92
+ content_tag(:span, '✖', class: "remove-icon") +
93
+ content_tag(:span, '[remove]', class: 'sr-only')
94
+ end
95
+ end + render_facet_count(classes: ["selected"])
96
+ end
97
+
98
+ ##
99
+ # Renders a count value for facet limits. Can be over-ridden locally
100
+ # to change style. And can be called by plugins to get consistent display.
101
+ #
102
+ # @param [Integer] num number of facet results
103
+ # @param [Hash] options
104
+ # @option options [Array<String>] an array of classes to add to count span.
105
+ # @return [String]
106
+ # @private
107
+ def render_facet_count(options = {})
108
+ return @view_context.render_facet_count(@hits, options) unless @view_context.method(:render_facet_count).owner == Blacklight::FacetsHelperBehavior || explicit_component_configuration?
109
+
110
+ classes = (options[:classes] || []) << "facet-count"
111
+ content_tag("span", t('blacklight.search.facets.count', number: number_with_delimiter(@hits)), class: classes)
112
+ end
113
+
114
+ private
115
+
116
+ def explicit_component_configuration?
117
+ @facet_item.facet_config.item_component.present?
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ # Render facet items and any subtree
5
+ class FacetItemPivotComponent < ::ViewComponent::Base
6
+ # Somewhat arbitrary number; the only important thing is that
7
+ # it is bigger than the number of leaf nodes in any collapsing
8
+ # pivot facet on the page.
9
+ ID_COUNTER_MAX = 2**20 - 1
10
+
11
+ # Mint a (sufficiently) unique identifier, so we can associate
12
+ # the expand/collapse control with labels
13
+ def self.mint_id
14
+ @id_counter = ((@id_counter || 0) + 1) % ID_COUNTER_MAX
15
+
16
+ # We convert the ID to hex for markup compactness
17
+ @id_counter.to_s(16)
18
+ end
19
+
20
+ with_collection_parameter :facet_item
21
+
22
+ def initialize(facet_item:, wrapping_element: 'li', suppress_link: false, collapsing: nil)
23
+ @facet_item = facet_item
24
+ @wrapping_element = wrapping_element
25
+ @suppress_link = suppress_link
26
+ @collapsing = collapsing.nil? ? facet_item.facet_config.collapsing : collapsing
27
+ @icons = { show: '⊞', hide: '⊟' }.merge(facet_item.facet_config.icons || {})
28
+ end
29
+
30
+ def call
31
+ facet = Blacklight::FacetItemComponent.new(facet_item: @facet_item, wrapping_element: nil, suppress_link: @suppress_link)
32
+
33
+ id = "h-#{self.class.mint_id}" if @collapsing && has_items?
34
+
35
+ content_tag @wrapping_element, role: 'treeitem' do
36
+ concat facet_toggle_button(id) if has_items? && @collapsing
37
+ concat content_tag('span', render_component(facet), class: "facet-values #{'facet-leaf-node' if has_items? && @collapsing}", id: id && "#{id}_label")
38
+
39
+ if has_items?
40
+ concat(content_tag('ul', class: "pivot-facet list-unstyled #{'collapse' if @collapsing}", id: id, role: 'group') do
41
+ render_component(
42
+ self.class.with_collection(
43
+ @facet_item.items.map { |i| facet_item_presenter(i) }
44
+ )
45
+ )
46
+ end)
47
+ end
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def has_items?
54
+ @facet_item.items.present?
55
+ end
56
+
57
+ def facet_toggle_button(id)
58
+ content_tag 'button', class: 'btn facet-toggle-handle collapsed',
59
+ data: { toggle: 'collapse', target: "##{id}" },
60
+ aria: { expanded: false, controls: id, describedby: "#{id}_label" } do
61
+ concat toggle_icon(:show)
62
+ concat toggle_icon(:hide)
63
+ end
64
+ end
65
+
66
+ def toggle_icon(type)
67
+ content_tag 'span', class: type do
68
+ concat @icons[type]
69
+ concat content_tag('span', t(type, scope: 'blacklight.search.facets.pivot'), class: 'sr-only')
70
+ end
71
+ end
72
+
73
+ # This is a little convoluted in Blacklight 7 in order to maintain backwards-compat
74
+ # with overrides of deprecated helpers. In 8.x, we can just call Component#render_in
75
+ # and call it a day
76
+ def render_component(component)
77
+ @view_context.render(component)
78
+ end
79
+
80
+ def facet_item_presenter(facet_item)
81
+ Blacklight::FacetItemPresenter.new(facet_item, @facet_item.facet_config, @view_context, @facet_item.facet_field, @facet_item.search_state)
82
+ end
83
+ end
84
+ end
@@ -148,7 +148,8 @@ module Blacklight::BlacklightHelperBehavior
148
148
  document = args.first
149
149
 
150
150
  field = options[:field]
151
- html_escape t(:"blacklight.search.index.#{document_index_view_type}.label", default: :'blacklight.search.index.label', label: index_field_label(document, field))
151
+ label = options[:label] || index_field_label(document, field)
152
+ html_escape t(:"blacklight.search.index.#{document_index_view_type}.label", default: :'blacklight.search.index.label', label: label)
152
153
  end
153
154
 
154
155
  ##
@@ -169,8 +170,9 @@ module Blacklight::BlacklightHelperBehavior
169
170
  document = args.first
170
171
 
171
172
  field = options[:field]
173
+ label = options[:label] || document_show_field_label(document, field)
172
174
 
173
- t(:'blacklight.search.show.label', label: document_show_field_label(document, field))
175
+ t(:'blacklight.search.show.label', label: label)
174
176
  end
175
177
 
176
178
  ##
@@ -40,8 +40,6 @@ module Blacklight::CatalogHelperBehavior
40
40
  # @param [RSolr::Resource] collection (or other Kaminari-compatible objects)
41
41
  # @return [String]
42
42
  def page_entries_info(collection, entry_name: nil)
43
- return unless show_pagination? collection
44
-
45
43
  entry_name = if entry_name
46
44
  entry_name.pluralize(collection.size, I18n.locale)
47
45
  else
@@ -153,7 +151,7 @@ module Blacklight::CatalogHelperBehavior
153
151
  # @return [String]
154
152
  def render_document_sidebar_partial(document = nil)
155
153
  unless document
156
- Deprecation.warn(self, 'render_document_sidebar_partial expects one argument ' /
154
+ Deprecation.warn(self, 'render_document_sidebar_partial expects one argument ' \
157
155
  '(@document) and you passed none. This behavior will be removed in version 8')
158
156
  document = @document
159
157
  end
@@ -279,7 +277,7 @@ module Blacklight::CatalogHelperBehavior
279
277
  facet_config = facet_configuration_for_field(facet)
280
278
  filter_label = facet_field_label(facet_config.key)
281
279
  filter_value = if values.size < 3
282
- values.map { |value| facet_display_value(facet, value) }.to_sentence
280
+ values.map { |value| facet_item_presenter(facet_config, value, facet).label }.to_sentence
283
281
  else
284
282
  t('blacklight.search.page_title.many_constraint_values', values: values.size)
285
283
  end
@@ -91,10 +91,11 @@ module Blacklight::ConfigurationHelperBehavior
91
91
  end
92
92
 
93
93
  # Shortcut for commonly needed operation, look up display
94
- # label for the key specified. Returns "Keyword" if a label
95
- # can't be found.
94
+ # label for the key specified.
96
95
  def label_for_search_field(key)
97
96
  field_config = blacklight_config.search_fields[key]
97
+ return if key.nil? && field_config.nil?
98
+
98
99
  field_config ||= Blacklight::Configuration::NullField.new(key: key)
99
100
 
100
101
  field_config.display_label('search')
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight::FacetsHelperBehavior
3
+ extend Deprecation
4
+ self.deprecation_horizon = 'blacklight 8.0'
5
+
3
6
  include Blacklight::Facet
4
7
 
5
8
  ##
@@ -14,7 +17,9 @@ module Blacklight::FacetsHelperBehavior
14
17
  '8.0.0')
15
18
  response = @response
16
19
  end
17
- facets_from_request(fields, response).any? { |display_facet| should_render_facet?(display_facet) }
20
+ Deprecation.silence(Blacklight::FacetsHelperBehavior) do
21
+ facets_from_request(fields, response).any? { |display_facet| should_render_facet?(display_facet) }
22
+ end
18
23
  end
19
24
 
20
25
  ##
@@ -58,10 +63,29 @@ module Blacklight::FacetsHelperBehavior
58
63
  # @return [String]
59
64
  def render_facet_limit(display_facet, options = {})
60
65
  field_config = facet_configuration_for_field(display_facet.name)
61
- return unless should_render_facet?(display_facet, field_config)
62
66
 
67
+ if field_config.component
68
+ component = field_config.component == true ? Blacklight::FacetFieldListComponent : field_config.component
69
+ return render(
70
+ component.new(
71
+ facet_field: facet_field_presenter(field_config, display_facet),
72
+ layout: (params[:action] == 'facet' ? false : options[:layout])
73
+ )
74
+ )
75
+ end
76
+
77
+ Deprecation.warn(Blacklight::FacetsHelperBehavior, 'Calling #render_facet_limit on a non-componentized'\
78
+ ' facet is deprecated and will be removed in Blacklight 8')
79
+
80
+ Deprecation.silence(Blacklight::FacetsHelperBehavior) do
81
+ return unless should_render_facet?(display_facet, field_config)
82
+ end
63
83
  options = options.dup
64
- options[:partial] ||= facet_partial_name(display_facet)
84
+
85
+ Deprecation.silence(Blacklight::FacetsHelperBehavior) do
86
+ options[:partial] ||= facet_partial_name(display_facet)
87
+ end
88
+
65
89
  options[:layout] ||= "facet_layout" unless options.key?(:layout)
66
90
  options[:locals] ||= {}
67
91
  options[:locals][:field_name] ||= display_facet.name
@@ -76,12 +100,20 @@ module Blacklight::FacetsHelperBehavior
76
100
  # removes any elements where render_facet_item returns a nil value. This enables an application
77
101
  # to filter undesireable facet items so they don't appear in the UI
78
102
  def render_facet_limit_list(paginator, facet_field, wrapping_element = :li)
79
- safe_join(paginator.items.map { |item| render_facet_item(facet_field, item) }.compact.map { |item| content_tag(wrapping_element, item) })
103
+ facet_config ||= facet_configuration_for_field(facet_field)
104
+
105
+ collection = paginator.items.map do |item|
106
+ facet_item_presenter(facet_config, item, facet_field)
107
+ end
108
+
109
+ render(facet_item_component_class(facet_config).with_collection(collection, wrapping_element: wrapping_element))
80
110
  end
111
+ deprecation_deprecate :render_facet_limit_list
81
112
 
82
113
  ##
83
114
  # Renders a single facet item
84
115
  def render_facet_item(facet_field, item)
116
+ deprecated_method(:render_facet_item)
85
117
  if facet_in_params?(facet_field, item.value)
86
118
  render_selected_facet_value(facet_field, item)
87
119
  else
@@ -104,6 +136,7 @@ module Blacklight::FacetsHelperBehavior
104
136
  facet_config ||= facet_configuration_for_field(display_facet.name)
105
137
  should_render_field?(facet_config, display_facet)
106
138
  end
139
+ deprecation_deprecate :should_render_facet?
107
140
 
108
141
  ##
109
142
  # Determine whether a facet should be rendered as collapsed or not.
@@ -114,8 +147,11 @@ module Blacklight::FacetsHelperBehavior
114
147
  # @param [Blacklight::Configuration::FacetField] facet_field
115
148
  # @return [Boolean]
116
149
  def should_collapse_facet? facet_field
117
- !facet_field_in_params?(facet_field.key) && facet_field.collapse
150
+ Deprecation.silence(Blacklight::FacetsHelperBehavior) do
151
+ !facet_field_in_params?(facet_field.key) && facet_field.collapse
152
+ end
118
153
  end
154
+ deprecation_deprecate :should_collapse_facet?
119
155
 
120
156
  ##
121
157
  # The name of the partial to use to render a facet field.
@@ -130,6 +166,11 @@ module Blacklight::FacetsHelperBehavior
130
166
  name ||= "facet_pivot" if config.pivot
131
167
  name || "facet_limit"
132
168
  end
169
+ deprecation_deprecate :facet_partial_name
170
+
171
+ def facet_field_presenter(facet_config, display_facet)
172
+ Blacklight::FacetFieldPresenter.new(facet_config, display_facet, self)
173
+ end
133
174
 
134
175
  ##
135
176
  # Standard display of a facet value in a list. Used in both _facets sidebar
@@ -142,13 +183,9 @@ module Blacklight::FacetsHelperBehavior
142
183
  # @option options [Boolean] :suppress_link display the facet, but don't link to it
143
184
  # @return [String]
144
185
  def render_facet_value(facet_field, item, options = {})
145
- path = path_for_facet(facet_field, item)
146
- content_tag(:span, class: "facet-label") do
147
- link_to_unless(options[:suppress_link],
148
- facet_display_value(facet_field, item),
149
- path,
150
- class: "facet-select")
151
- end + render_facet_count(item.hits)
186
+ deprecated_method(:render_facet_value)
187
+ facet_config = facet_configuration_for_field(facet_field)
188
+ facet_item_component(facet_config, item, facet_field, **options).render_facet_value
152
189
  end
153
190
 
154
191
  ##
@@ -158,12 +195,9 @@ module Blacklight::FacetsHelperBehavior
158
195
  # @return [String]
159
196
  def path_for_facet(facet_field, item, path_options = {})
160
197
  facet_config = facet_configuration_for_field(facet_field)
161
- if facet_config.url_method
162
- send(facet_config.url_method, facet_field, item)
163
- else
164
- search_action_path(search_state.add_facet_params_and_redirect(facet_field, item).merge(path_options))
165
- end
198
+ facet_item_presenter(facet_config, item, facet_field).href(path_options)
166
199
  end
200
+ deprecation_deprecate :path_for_facet
167
201
 
168
202
  ##
169
203
  # Standard display of a SELECTED facet value (e.g. without a link and with a remove button)
@@ -171,15 +205,9 @@ module Blacklight::FacetsHelperBehavior
171
205
  # @param [Blacklight::Solr::Response::Facets::FacetField] facet_field
172
206
  # @param [String] item
173
207
  def render_selected_facet_value(facet_field, item)
174
- remove_href = search_action_path(search_state.remove_facet_params(facet_field, item))
175
- content_tag(:span, class: "facet-label") do
176
- content_tag(:span, facet_display_value(facet_field, item), class: "selected") +
177
- # remove link
178
- link_to(remove_href, class: "remove") do
179
- content_tag(:span, '✖', class: "remove-icon") +
180
- content_tag(:span, '[remove]', class: 'sr-only')
181
- end
182
- end + render_facet_count(item.hits, classes: ["selected"])
208
+ deprecated_method(:render_selected_facet_value)
209
+ facet_config = facet_configuration_for_field(facet_field)
210
+ facet_item_component(facet_config, item, facet_field).render_selected_facet_value
183
211
  end
184
212
 
185
213
  ##
@@ -191,18 +219,22 @@ module Blacklight::FacetsHelperBehavior
191
219
  # @option options [Array<String>] an array of classes to add to count span.
192
220
  # @return [String]
193
221
  def render_facet_count(num, options = {})
222
+ deprecated_method(:render_facet_count)
194
223
  classes = (options[:classes] || []) << "facet-count"
195
224
  content_tag("span", t('blacklight.search.facets.count', number: number_with_delimiter(num)), class: classes)
196
225
  end
197
226
 
198
227
  ##
199
228
  # Are any facet restrictions for a field in the query parameters?
200
- #
229
+ # @private
201
230
  # @param [String] field
202
231
  # @return [Boolean]
203
232
  def facet_field_in_params? field
204
- facet_params(field).present?
233
+ config = facet_configuration_for_field(field)
234
+ search_state.has_facet? config
205
235
  end
236
+ # Left undeprecated for the sake of temporary backwards compatibility
237
+ # deprecation_deprecate :facet_field_in_params?
206
238
 
207
239
  ##
208
240
  # Check if the query parameters have the given facet field with the
@@ -212,18 +244,19 @@ module Blacklight::FacetsHelperBehavior
212
244
  # @param [String] item facet value
213
245
  # @return [Boolean]
214
246
  def facet_in_params?(field, item)
215
- value = facet_value_for_facet_item(item)
216
-
217
- (facet_params(field) || []).include? value
247
+ config = facet_configuration_for_field(field)
248
+ search_state.has_facet? config, value: facet_value_for_facet_item(item)
218
249
  end
250
+ deprecation_deprecate :facet_in_params?
219
251
 
220
252
  ##
221
253
  # Get the values of the facet set in the blacklight query string
222
254
  def facet_params field
223
255
  config = facet_configuration_for_field(field)
224
256
 
225
- params[:f][config.key] if params[:f]
257
+ search_state.params.dig(:f, config.key)
226
258
  end
259
+ deprecation_deprecate :facet_params
227
260
 
228
261
  ##
229
262
  # Get the displayable version of a facet's value
@@ -231,30 +264,17 @@ module Blacklight::FacetsHelperBehavior
231
264
  # @param [Object] field
232
265
  # @param [String] item value
233
266
  # @return [String]
267
+ # @deprecated
234
268
  def facet_display_value field, item
269
+ deprecated_method(:facet_display_value)
235
270
  facet_config = facet_configuration_for_field(field)
236
-
237
- value = if item.respond_to? :label
238
- item.label
239
- else
240
- facet_value_for_facet_item(item)
241
- end
242
-
243
- if facet_config.helper_method
244
- send facet_config.helper_method, value
245
- elsif facet_config.query && facet_config.query[value]
246
- facet_config.query[value][:label]
247
- elsif facet_config.date
248
- localization_options = facet_config.date == true ? {} : facet_config.date
249
- l(Time.zone.parse(value), localization_options)
250
- else
251
- value
252
- end
271
+ facet_item_presenter(facet_config, item, field).label
253
272
  end
254
273
 
255
274
  def facet_field_id facet_field
256
275
  "facet-#{facet_field.key.parameterize}"
257
276
  end
277
+ deprecation_deprecate :facet_field_id
258
278
 
259
279
  private
260
280
 
@@ -265,4 +285,27 @@ module Blacklight::FacetsHelperBehavior
265
285
  item
266
286
  end
267
287
  end
288
+
289
+ def facet_item_presenter(facet_config, facet_item, facet_field)
290
+ Blacklight::FacetItemPresenter.new(facet_item, facet_config, self, facet_field)
291
+ end
292
+
293
+ def facet_item_component(facet_config, facet_item, facet_field, **args)
294
+ facet_item_component_class(facet_config).new(facet_item: facet_item_presenter(facet_config, facet_item, facet_field), **args).with_view_context(self)
295
+ end
296
+
297
+ def facet_item_component_class(facet_config)
298
+ default_component = facet_config.pivot ? Blacklight::FacetItemPivotComponent : Blacklight::FacetItemComponent
299
+ facet_config.fetch(:item_component, default_component)
300
+ end
301
+
302
+ # We can't use .deprecation_deprecate here, because the new components need to
303
+ # see the originally defined location for these methods in order to properly
304
+ # call back into the helpers for backwards compatibility
305
+ def deprecated_method(method_name)
306
+ Deprecation.warn(Blacklight::FacetsHelperBehavior,
307
+ Deprecation.deprecated_method_warning(Blacklight::FacetsHelperBehavior,
308
+ method_name, {}),
309
+ caller)
310
+ end
268
311
  end