blacklight-spotlight 3.0.0.rc5 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spotlight/base.rb +1 -1
  3. data/app/controllers/spotlight/browse_controller.rb +5 -16
  4. data/app/controllers/spotlight/catalog_controller.rb +7 -5
  5. data/app/controllers/spotlight/dashboards_controller.rb +3 -3
  6. data/app/controllers/spotlight/pages_controller.rb +6 -7
  7. data/app/helpers/spotlight/application_helper.rb +1 -1
  8. data/app/helpers/spotlight/main_app_helpers.rb +3 -4
  9. data/app/helpers/spotlight/meta_helper.rb +2 -2
  10. data/app/helpers/spotlight/searches_helper.rb +1 -1
  11. data/app/jobs/spotlight/process_bulk_updates_csv_job.rb +1 -1
  12. data/app/models/concerns/spotlight/browse_category_search_builder.rb +59 -0
  13. data/app/models/concerns/spotlight/search_builder.rb +11 -0
  14. data/app/models/sir_trevor_rails/blocks/browse_block.rb +1 -1
  15. data/app/models/sir_trevor_rails/blocks/featured_pages_block.rb +1 -1
  16. data/app/models/sir_trevor_rails/blocks/solr_documents_block.rb +9 -0
  17. data/app/models/spotlight/blacklight_configuration.rb +14 -5
  18. data/app/models/spotlight/featured_image.rb +33 -0
  19. data/app/models/spotlight/page_configurations.rb +10 -9
  20. data/app/models/spotlight/search.rb +3 -1
  21. data/app/presenters/spotlight/iiif_manifest_presenter.rb +1 -1
  22. data/app/views/catalog/_add_tags.html.erb +1 -1
  23. data/app/views/catalog/_change_visibility.html.erb +1 -1
  24. data/app/views/catalog/_remove_tags.html.erb +1 -1
  25. data/app/views/catalog/_save_search.html.erb +1 -1
  26. data/app/views/spotlight/about_pages/_sidebar.html.erb +2 -2
  27. data/app/views/spotlight/browse/_search.html.erb +3 -3
  28. data/app/views/spotlight/browse/_search_box.html.erb +9 -9
  29. data/app/views/spotlight/browse/_search_title.html.erb +1 -1
  30. data/app/views/spotlight/catalog/_admin_index_header_default.html.erb +1 -1
  31. data/app/views/spotlight/catalog/_admin_thumbnail_default.html.erb +3 -2
  32. data/app/views/spotlight/catalog/index.iiif_json.jbuilder +1 -1
  33. data/app/views/spotlight/feature_pages/_sidebar.html.erb +1 -1
  34. data/app/views/spotlight/featured_images/_form.html.erb +1 -1
  35. data/app/views/spotlight/metadata_configurations/_metadata_field.html.erb +2 -2
  36. data/app/views/spotlight/pages/_order_pages.html.erb +2 -2
  37. data/app/views/spotlight/pages/_view_type_group.html.erb +3 -3
  38. data/app/views/spotlight/pages/show.html.erb +1 -1
  39. data/app/views/spotlight/search_configurations/_document_index_view_types.html.erb +2 -2
  40. data/app/views/spotlight/searches/_form.html.erb +2 -2
  41. data/app/views/spotlight/sir_trevor/blocks/_search_results_block.html.erb +1 -1
  42. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_block.html.erb +5 -5
  43. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_carousel_block.html.erb +5 -5
  44. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_features_block.html.erb +7 -5
  45. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_grid_block.html.erb +3 -3
  46. data/config/routes.rb +1 -0
  47. data/db/migrate/20210308090000_migrate_caption_values_for_title_key.rb +29 -0
  48. data/db/migrate/20210506070809_add_indexes_for_featured_images.rb +9 -0
  49. data/lib/generators/spotlight/install_generator.rb +2 -2
  50. data/lib/spotlight/version.rb +1 -1
  51. data/spec/controllers/spotlight/browse_controller_spec.rb +0 -6
  52. data/spec/examples.txt +1491 -1488
  53. data/spec/factories/bulk_updates.rb +6 -0
  54. data/spec/features/javascript/blocks/search_result_block_spec.rb +1 -1
  55. data/spec/features/javascript/blocks/solr_documents_block_spec.rb +1 -1
  56. data/spec/fixtures/updated-bulk-update-template-no-cols.csv +4 -0
  57. data/spec/helpers/spotlight/application_helper_spec.rb +5 -5
  58. data/spec/jobs/spotlight/process_bulk_updates_csv_job_spec.rb +8 -0
  59. data/spec/models/spotlight/access_controls_enforcement_search_builder_spec.rb +1 -2
  60. data/spec/models/spotlight/blacklight_configuration_spec.rb +14 -14
  61. data/spec/models/spotlight/browse_category_search_builder_spec.rb +49 -0
  62. data/spec/models/spotlight/featured_image_spec.rb +12 -0
  63. data/spec/presenters/spotlight/iiif_manifest_presenter_spec.rb +1 -1
  64. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
  65. data/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb +3 -4
  66. data/spec/views/spotlight/sir_trevor/blocks/_browse_block.html.erb_spec.rb +1 -1
  67. data/spec/views/spotlight/sir_trevor/blocks/_iframe_block.html.erb_spec.rb +1 -1
  68. data/spec/views/spotlight/sir_trevor/blocks/_link_to_search_block.html.erb_spec.rb +1 -1
  69. data/spec/views/spotlight/sir_trevor/blocks/_rule_block.html.erb_spec.rb +1 -1
  70. data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_block.html.erb_spec.rb +8 -4
  71. data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_carousel_block.html.erb_spec.rb +7 -2
  72. data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_embed_block.html.erb_spec.rb +8 -5
  73. data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_features_block.html.erb_spec.rb +3 -2
  74. data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_grid_block.html.erb_spec.rb +9 -4
  75. metadata +14 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e21e66d81a96d330d76726b9a41e44ea7495653b75d9d5b211f4a607cc4afec
4
- data.tar.gz: 9f6cc613d234db387773a9b80ae7a72e7c3610ab01996a116df4997668dc0703
3
+ metadata.gz: 931e772ae7165aea85c6664c6c1fcbb615d0397d42d2000b2bc4f7038288ff91
4
+ data.tar.gz: 5eac236663178ff5476f8b58213f8da5757bd7120108b801792247cc194392b4
5
5
  SHA512:
6
- metadata.gz: dc889b0bf136bde52dcb6e8d99776be47261cff5e4310ad3297018e77d5d25818f46df0d874ac379dfa91f8177a648135e84f4ef0ee5810c30bc3d87c90caed8
7
- data.tar.gz: efe143a5c7125d9b6d18aa972d2a1c4357cf2c42f34ed62c0b2b402af4d16c6473087c63b3cb605a07127edb2f65a0d038772037bb7560ca5497a734f6b89bfd
6
+ metadata.gz: 528286f83609189237af8feef3e40048357b37de3770fdf772bc2672c3b0a52230cb1ab9f2ddfb31b59932aba9a0fafdc44ef2d2f79a333db9618ccf34746acf
7
+ data.tar.gz: 16900b7cbc3278b6be875cb0e91441f33860dc13200c36898e36f545d236557eddada90fe99536ed2fecd72538c076f6dd0edadeea9e481b5d7d025b470b93b6
@@ -32,7 +32,7 @@ module Spotlight
32
32
  def autocomplete_json_response_for_document(doc)
33
33
  {
34
34
  id: doc.id,
35
- title: CGI.unescapeHTML(view_context.presenter(doc).heading.to_str),
35
+ title: CGI.unescapeHTML(view_context.document_presenter(doc).heading.to_str),
36
36
  thumbnail: doc.first(blacklight_config.index.thumbnail_field),
37
37
  full_image_url: doc.first(Spotlight::Engine.config.full_image_field),
38
38
  description: doc.id,
@@ -15,13 +15,15 @@ module Spotlight
15
15
  before_action :attach_search_breadcrumb, only: :show
16
16
  record_search_parameters only: :show
17
17
 
18
- helper_method :should_render_spotlight_search_bar?, :presenter
18
+ helper_method :should_render_spotlight_search_bar?
19
19
 
20
20
  before_action :swap_actions_configuration, only: :show
21
21
 
22
22
  before_action do
23
23
  blacklight_config.track_search_session = false
24
- blacklight_config.view.gallery.classes = 'row-cols-2 row-cols-md-4'
24
+ blacklight_config.view.gallery.classes = 'row-cols-2 row-cols-md-4' if blacklight_config.view.key? :gallery
25
+ blacklight_config.action_mapping.default = blacklight_config.index
26
+ blacklight_config.action_mapping.show = blacklight_config.index
25
27
  end
26
28
 
27
29
  def index
@@ -31,15 +33,11 @@ module Spotlight
31
33
 
32
34
  def show
33
35
  @response, @document_list = search_service.search_results do |builder|
34
- builder.with(search_query)
36
+ builder.with(params.merge(browse_category_id: @search.id))
35
37
  end
36
38
 
37
39
  respond_to do |format|
38
40
  format.html
39
- format.json do
40
- @presenter = Blacklight::JsonPresenter.new(@response, blacklight_config)
41
- render template: 'catalog/index'
42
- end
43
41
  end
44
42
  end
45
43
 
@@ -50,11 +48,6 @@ module Spotlight
50
48
  blacklight_config.action_mapping.show.top_level_config = :index if blacklight_config.key?(:action_mapping)
51
49
  end
52
50
 
53
- def search_query
54
- @search.query_params['q'] = [@search.query_params['q'], params[:browse_q]].join(' ')
55
- @search.merge_params_for_search(params, blacklight_config)
56
- end
57
-
58
51
  ##
59
52
  # Browsing an exhibit should start a new search session
60
53
  def start_new_search_session?
@@ -128,10 +121,6 @@ module Spotlight
128
121
  Spotlight::Engine.config.default_browse_index_view_type
129
122
  end
130
123
 
131
- def presenter(document)
132
- view_context.index_presenter(document)
133
- end
134
-
135
124
  def render_save_this_search?
136
125
  false
137
126
  end
@@ -27,8 +27,7 @@ module Spotlight
27
27
 
28
28
  before_action only: :admin do
29
29
  blacklight_config.view.select! { |k, _v| k == :admin_table }
30
- blacklight_config.view.admin_table.partials = [:index_compact]
31
- blacklight_config.view.admin_table.document_actions = []
30
+ blacklight_config.view.admin_table(partials: [:index_compact], document_actions: []) unless blacklight_config.view.key? :admin_table
32
31
  blacklight_config.track_search_session = false
33
32
 
34
33
  unless blacklight_config.sort_fields.key? :timestamp
@@ -38,8 +37,7 @@ module Spotlight
38
37
  end
39
38
 
40
39
  before_action only: :edit do
41
- blacklight_config.view.edit.partials = blacklight_config.view_config(:show).partials.dup
42
- blacklight_config.view.edit.partials.insert(2, :edit)
40
+ blacklight_config.view.edit(partials: blacklight_config.view_config(:show).partials.dup.insert(2, :edit)) unless blacklight_config.view.key? :edit
43
41
  end
44
42
 
45
43
  def show
@@ -199,6 +197,10 @@ module Spotlight
199
197
  redirect_to spotlight.exhibit_root_path(@exhibit) unless has_search_parameters?
200
198
  end
201
199
 
200
+ def has_search_parameters? # rubocop:disable Naming/PredicateName
201
+ super || params[:browse_category_id].present?
202
+ end
203
+
202
204
  def add_breadcrumb_with_search_params
203
205
  return unless has_search_parameters?
204
206
 
@@ -216,7 +218,7 @@ module Spotlight
216
218
  add_breadcrumb t(:'spotlight.catalog.breadcrumb.index'), search_action_url(current_search_session.query_params)
217
219
  end
218
220
 
219
- add_breadcrumb view_context.show_presenter(document).heading, polymorphic_path([current_exhibit, document])
221
+ add_breadcrumb view_context.document_presenter(document).heading, polymorphic_path([current_exhibit, document])
220
222
  end
221
223
  # rubocop:enable Metrics/AbcSize
222
224
 
@@ -11,9 +11,9 @@ module Spotlight
11
11
  include Spotlight::SearchHelper
12
12
 
13
13
  before_action only: [:show] do
14
- blacklight_config.view.reject! { |_k, _v| true }
15
- blacklight_config.view.admin_table.partials = ['index_compact']
16
- blacklight_config.view.admin_table.document_actions = []
14
+ blacklight_config.action_mapping&.delete(:show)
15
+ blacklight_config.view.clear
16
+ blacklight_config.view.admin_table(partials: ['index_compact'], document_actions: [])
17
17
  blacklight_config.track_search_session = false
18
18
  blacklight_config.action_mapping.show.top_level_config = :index if blacklight_config.key?(:action_mapping)
19
19
  end
@@ -17,9 +17,11 @@ module Spotlight
17
17
  include Spotlight::Base
18
18
  include Blacklight::SearchContext
19
19
 
20
- helper_method :get_search_results, :search_results, :fetch, :page_collection_name, :presenter
20
+ helper_method :get_search_results, :search_results, :fetch, :page_collection_name
21
21
 
22
22
  before_action do
23
+ blacklight_config.action_mapping.default = blacklight_config.index
24
+ blacklight_config.action_mapping.show = blacklight_config.index
23
25
  blacklight_config.view.gallery.classes = 'row-cols-2 row-cols-md-4' unless @page&.display_sidebar
24
26
  end
25
27
 
@@ -63,7 +65,8 @@ module Spotlight
63
65
  @page.last_edited_by = @page.created_by = current_user
64
66
 
65
67
  if @page.save
66
- redirect_to [spotlight, @page.exhibit, page_collection_name], notice: t(:'helpers.submit.page.created', model: @page.class.model_name.human.downcase)
68
+ redirect_to [spotlight, @page.exhibit, page_collection_name.to_sym],
69
+ notice: t(:'helpers.submit.page.created', model: @page.class.model_name.human.downcase)
67
70
  else
68
71
  render action: 'new'
69
72
  end
@@ -84,7 +87,7 @@ module Spotlight
84
87
  def destroy
85
88
  @page.destroy
86
89
 
87
- redirect_to [spotlight, @page.exhibit, page_collection_name], flash: { html_safe: true }, notice: undo_notice(:destroyed)
90
+ redirect_to [spotlight, @page.exhibit, page_collection_name.to_sym], flash: { html_safe: true }, notice: undo_notice(:destroyed)
88
91
  end
89
92
 
90
93
  def update_all
@@ -204,10 +207,6 @@ module Spotlight
204
207
  raise ActiveRecord::RecordNotFound
205
208
  end
206
209
  end
207
-
208
- def presenter(document)
209
- view_context.index_presenter(document)
210
- end
211
210
  end
212
211
  # rubocop:enable Metrics/ClassLength
213
212
  end
@@ -92,7 +92,7 @@ module Spotlight
92
92
  # Helper to turn tag data into facets
93
93
  def url_to_tag_facet(tag)
94
94
  if current_exhibit
95
- search_action_url(search_state.reset.add_facet_params(:exhibit_tags, tag))
95
+ search_action_url(search_state.reset.filter(:exhibit_tags).add(tag).params)
96
96
  else
97
97
  search_action_url(q: tag)
98
98
  end
@@ -28,12 +28,11 @@ module Spotlight
28
28
  super
29
29
  end
30
30
 
31
- def presenter(document)
32
- case action_name
33
- when 'index'
31
+ def document_presenter_class(_document)
32
+ if action_name == 'index'
34
33
  super
35
34
  else
36
- show_presenter(document)
35
+ blacklight_config.view_config(action_name: :show).document_presenter_class
37
36
  end
38
37
  end
39
38
 
@@ -81,7 +81,7 @@ module Spotlight
81
81
  end
82
82
 
83
83
  def document_twitter_card_content(document)
84
- presenter = show_presenter(document)
84
+ presenter = document_presenter(document)
85
85
 
86
86
  twitter_card('summary_large_image') do |card|
87
87
  card.title presenter.heading
@@ -90,7 +90,7 @@ module Spotlight
90
90
  end
91
91
 
92
92
  def document_opengraph_content(document)
93
- presenter = show_presenter(document)
93
+ presenter = document_presenter(document)
94
94
 
95
95
  opengraph do |graph|
96
96
  graph.site_name application_name
@@ -4,7 +4,7 @@ module Spotlight
4
4
  # Saved search helpers
5
5
  module SearchesHelper
6
6
  def available_document_index_views
7
- blacklight_config.view.to_h.reject { |_k, v| v.if == false }.keys
7
+ blacklight_config.view.to_h.reject { |_k, v| v.if == false }
8
8
  end
9
9
  end
10
10
  end
@@ -43,7 +43,7 @@ module Spotlight
43
43
  needs_reindex = false
44
44
 
45
45
  begin
46
- if sidecar.public != to_bool(row[config.csv_visibility])
46
+ if row.headers.include?(config.csv_visibility) && sidecar.public != to_bool(row[config.csv_visibility])
47
47
  sidecar.update(public: to_bool(row[config.csv_visibility]))
48
48
  needs_reindex = true
49
49
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ # Enforce exhibit visibility for index queries
5
+ module BrowseCategorySearchBuilder
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ self.default_processor_chain = %i[apply_browse_category_defaults] +
10
+ default_processor_chain +
11
+ %i[fix_up_browse_category_defaults fix_up_browse_category_queries]
12
+ end
13
+
14
+ # Adds a filter that excludes resources that have been marked as not-visible
15
+ def apply_browse_category_defaults(solr_params)
16
+ return unless current_browse_category
17
+
18
+ solr_params.merge!(browse_category_search_builder.to_hash)
19
+ end
20
+
21
+ def fix_up_browse_category_defaults(solr_params)
22
+ return if current_browse_category.nil? || search_state.send(:sort_field_key).present?
23
+
24
+ solr_params[:sort] = browse_category_search_builder.sort
25
+ end
26
+
27
+ def fix_up_browse_category_queries(solr_params)
28
+ return unless solr_params.dig(:json, :query, :bool, :must) && blacklight_params[:q]
29
+
30
+ # This replicates existing spotlight 2.x search behavior, more or less. It
31
+ # doesn't take into account the possibility that the browse category query
32
+ # could use a different search field (which.. doesn't have an existing UI
33
+ # control.. and may require additional upstream work to properly encapsulate
34
+ # the two query parameters)
35
+ solr_params[:json][:query][:bool][:must].map! do |q|
36
+ q.is_a?(String) ? { edismax: { query: q } } : q
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def current_exhibit
43
+ blacklight_config.current_exhibit
44
+ end
45
+
46
+ def current_browse_category
47
+ return unless current_exhibit && blacklight_params[:browse_category_id].present?
48
+
49
+ @current_browse_category ||= current_exhibit.searches.find(blacklight_params[:browse_category_id])
50
+ end
51
+
52
+ def browse_category_search_builder
53
+ @browse_category_search_builder ||= begin
54
+ search_builder = self.class.new(@processor_chain, @scope)
55
+ search_builder.with(current_browse_category.query_params)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ # Enforce exhibit visibility for index queries
5
+ module SearchBuilder
6
+ extend ActiveSupport::Concern
7
+
8
+ include Spotlight::AccessControlsEnforcementSearchBuilder
9
+ include Spotlight::BrowseCategorySearchBuilder
10
+ end
11
+ end
@@ -31,7 +31,7 @@ module SirTrevorRails
31
31
  send(:'display-item-counts') == 'true'
32
32
  end
33
33
 
34
- def as_json
34
+ def as_json(*)
35
35
  result = super
36
36
 
37
37
  result[:data][:item] ||= {}
@@ -22,7 +22,7 @@ module SirTrevorRails
22
22
  end
23
23
 
24
24
  # rubocop:disable Metrics/MethodLength
25
- def as_json
25
+ def as_json(*)
26
26
  result = super
27
27
  result[:data][:item] ||= {}
28
28
 
@@ -43,6 +43,15 @@ module SirTrevorRails
43
43
  ActiveModel::Type::Boolean.new.cast(send(:'show-primary-caption'))
44
44
  end
45
45
 
46
+ def document_caption(presenter, caption_field, default: nil)
47
+ caption_field ||= default
48
+
49
+ return unless caption_field
50
+ return presenter.heading if caption_field == Spotlight::PageConfigurations::DOCUMENT_TITLE_KEY
51
+
52
+ presenter.field_value(solr_helper.blacklight_config.index_fields[caption_field] || Blacklight::Configuration::NullField.new(caption_field))
53
+ end
54
+
46
55
  def secondary_caption?
47
56
  secondary_caption_field.present? && show_secondary_caption?
48
57
  end
@@ -74,6 +74,14 @@ module Spotlight
74
74
 
75
75
  config.current_exhibit = exhibit
76
76
 
77
+ config.document_presenter_class = lambda do |context|
78
+ if context.action_name == 'index'
79
+ config.index.document_presenter_class
80
+ else
81
+ config.show.document_presenter_class
82
+ end
83
+ end
84
+
77
85
  config.show.merge! show unless show.blank?
78
86
  config.index.merge! index unless index.blank?
79
87
  config.index.respond_to[:iiif_json] = true
@@ -84,22 +92,23 @@ module Spotlight
84
92
 
85
93
  unless config.curator_actions
86
94
  config.curator_actions ||= Blacklight::NestedOpenStructWithHashAccess.new(Blacklight::Configuration::ToolConfig)
87
- config.curator_actions.save_search
88
- config.curator_actions.bulk_actions
95
+ config.curator_actions.save_search!
96
+ config.curator_actions.bulk_actions!
89
97
  end
90
98
 
91
99
  unless config.bulk_actions
92
100
  config.bulk_actions ||= Blacklight::NestedOpenStructWithHashAccess.new(Blacklight::Configuration::ToolConfig)
93
101
 
94
- config.bulk_actions.change_visibility
95
- config.bulk_actions.add_tags
96
- config.bulk_actions.remove_tags
102
+ config.bulk_actions.change_visibility!
103
+ config.bulk_actions.add_tags!
104
+ config.bulk_actions.remove_tags!
97
105
  end
98
106
 
99
107
  config.default_solr_params = config.default_solr_params.merge(default_solr_params)
100
108
 
101
109
  config.default_per_page = default_per_page if default_per_page
102
110
 
111
+ config.view.embed!
103
112
  config.view.embed.partials ||= ['openseadragon']
104
113
  config.view.embed.if = false
105
114
  config.view.embed.locals ||= { osd_container_class: '' }
@@ -31,6 +31,8 @@ module Spotlight
31
31
  end
32
32
  end
33
33
 
34
+ after_save :bust_containing_resource_caches
35
+
34
36
  attr_accessor :upload_id
35
37
 
36
38
  def iiif_url
@@ -87,5 +89,36 @@ module Spotlight
87
89
  def iiif_service_base
88
90
  iiif_tilesource&.sub('/info.json', '')
89
91
  end
92
+
93
+ # This is an unfortunate work-around because:
94
+ # - when this instance is updated through accepts_nested_attributes_for on a parent model,
95
+ # the parent model is not necessarily updated (to bust caches, etc)
96
+ # - this model doesn't have an association back to where it is being used
97
+ # - these images can be used by multiple model instances (e.g. various translations of a feature page)
98
+ # - this model is used by different types of models (polymorphic use), so belongs_to/has_many doesn't help
99
+ # - potentially a problem with https://github.com/rails/rails/issues/26726
100
+ #
101
+ # Ideally, we might create a join table to connect this model to where it is used, but 🤷‍♂️
102
+ # Instead, we check each place this might be used and touch it
103
+ def bust_containing_resource_caches
104
+ if Rails.version > '6'
105
+ Spotlight::Search.where(thumbnail: self).or(Spotlight::Search.where(masthead: self)).touch_all
106
+ Spotlight::Page.where(thumbnail: self).touch_all
107
+ Spotlight::Exhibit.where(thumbnail: self).or(Spotlight::Exhibit.where(masthead: self)).touch_all
108
+ Spotlight::Contact.where(avatar: self).touch_all
109
+ Spotlight::Resources::Upload.where(upload: self).touch_all
110
+ else
111
+ bust_containing_resource_caches_rails5
112
+ end
113
+ end
114
+
115
+ # Rails 5 doesn't support touch_all.
116
+ def bust_containing_resource_caches_rails5
117
+ Spotlight::Search.where(thumbnail: self).or(Spotlight::Search.where(masthead: self)).find_each(&:touch)
118
+ Spotlight::Page.where(thumbnail: self).find_each(&:touch)
119
+ Spotlight::Exhibit.where(thumbnail: self).or(Spotlight::Exhibit.where(masthead: self)).find_each(&:touch)
120
+ Spotlight::Contact.where(avatar: self).find_each(&:touch)
121
+ Spotlight::Resources::Upload.where(upload: self).find_each(&:touch)
122
+ end
90
123
  end
91
124
  end
@@ -18,14 +18,12 @@ module Spotlight
18
18
  delegate :available_view_fields,
19
19
  :blacklight_config,
20
20
  :current_exhibit,
21
- :document_show_link_field,
22
- :index_fields,
23
- :index_field_label,
24
21
  :spotlight,
25
22
  :t,
26
- :view_label,
27
23
  to: :context
28
24
 
25
+ DOCUMENT_TITLE_KEY = '__spotlight_document_title___'
26
+
29
27
  attr_reader :context, :page
30
28
 
31
29
  def initialize(context:, page:)
@@ -35,7 +33,7 @@ module Spotlight
35
33
 
36
34
  def as_json(*)
37
35
  {
38
- 'blacklight-configuration-index-fields': available_index_fields,
36
+ 'blacklight-configuration-index-fields': available_caption_fields,
39
37
  'blacklight-configuration-search-views': available_view_configs,
40
38
  'attachment-endpoint': attachment_endpoint,
41
39
  'autocomplete-exhibit-catalog-path': exhibit_autocomplete_endpoint,
@@ -48,15 +46,18 @@ module Spotlight
48
46
 
49
47
  private
50
48
 
51
- def available_index_fields
52
- fields = blacklight_config.index_fields.map { |k, _v| { key: k, label: index_field_label(blacklight_config.document_model.new, k) } }
53
- fields.unshift(key: document_show_link_field, label: t(:'spotlight.pages.form.title_placeholder')) unless index_fields.include? document_show_link_field
49
+ def available_caption_fields
50
+ default_caption_fields + blacklight_config.index_fields.reject { |_k, v| v.caption == false }.map { |k, v| { key: k, label: v.display_label } }
51
+ end
54
52
 
53
+ def default_caption_fields
54
+ fields = []
55
+ fields << { key: DOCUMENT_TITLE_KEY, label: t(:'spotlight.pages.form.title_placeholder') } unless blacklight_config.index_fields.key? DOCUMENT_TITLE_KEY
55
56
  fields
56
57
  end
57
58
 
58
59
  def available_view_configs
59
- available_view_fields.map { |k, _| { key: k, label: view_label(k) } }
60
+ available_view_fields.map { |k, v| { key: k, label: v.display_label(k) } }
60
61
  end
61
62
 
62
63
  def attachment_endpoint