blacklight-spotlight 3.0.0.alpha.9 → 3.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (262) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/app/assets/images/blacklight/arrow-alt-circle-left.svg +1 -0
  4. data/app/assets/images/blacklight/arrow-alt-circle-right.svg +1 -0
  5. data/app/assets/javascripts/spotlight/admin/{add_new_page_button.js → add_new_button.js} +7 -0
  6. data/app/assets/javascripts/spotlight/admin/block_mixins/autocompleteable.js +4 -4
  7. data/app/assets/javascripts/spotlight/admin/blocks/browse_block.js +55 -1
  8. data/app/assets/javascripts/spotlight/admin/blocks/browse_group_categories_block.js +88 -0
  9. data/app/assets/javascripts/spotlight/admin/blocks/pages_block.js +1 -1
  10. data/app/assets/javascripts/spotlight/admin/blocks/solr_documents_base_block.js +1 -1
  11. data/app/assets/javascripts/spotlight/admin/blocks/uploaded_items_block.js +7 -2
  12. data/app/assets/javascripts/spotlight/admin/crop.es6 +11 -0
  13. data/app/assets/javascripts/spotlight/admin/croppable.js +1 -1
  14. data/app/assets/javascripts/spotlight/admin/index.js +0 -2
  15. data/app/assets/javascripts/spotlight/admin/reindex_monitor.js +1 -0
  16. data/app/assets/javascripts/spotlight/admin/search_typeahead.js +2 -2
  17. data/app/assets/javascripts/spotlight/admin/sir-trevor/block_controls.js +21 -12
  18. data/app/assets/javascripts/spotlight/admin/sir-trevor/locales.js +11 -3
  19. data/app/assets/javascripts/spotlight/user/browse_group_categories.js +59 -0
  20. data/app/assets/javascripts/spotlight/user/index.js +1 -0
  21. data/app/assets/stylesheets/spotlight/_accessibility.scss +1 -1
  22. data/app/assets/stylesheets/spotlight/_breadcrumbs.scss +8 -0
  23. data/app/assets/stylesheets/spotlight/_browse.scss +16 -0
  24. data/app/assets/stylesheets/spotlight/_catalog.scss +6 -6
  25. data/app/assets/stylesheets/spotlight/_curation.scss +6 -0
  26. data/app/assets/stylesheets/spotlight/_featured_browse_categories_block.scss +214 -83
  27. data/app/assets/stylesheets/spotlight/_header.scss +1 -1
  28. data/app/assets/stylesheets/spotlight/_item_text_block.scss +6 -0
  29. data/app/assets/stylesheets/spotlight/_pages.scss +9 -4
  30. data/app/assets/stylesheets/spotlight/_report_a_problem.scss +5 -2
  31. data/app/assets/stylesheets/spotlight/_spotlight.scss +2 -0
  32. data/app/assets/stylesheets/spotlight/_translations.scss +7 -0
  33. data/app/assets/stylesheets/spotlight/browse_group_categories_block.scss +92 -0
  34. data/app/builders/spotlight/bootstrap_breadcrumbs_builder.rb +1 -2
  35. data/app/controllers/concerns/spotlight/search_helper.rb +2 -8
  36. data/app/controllers/spotlight/appearances_controller.rb +0 -12
  37. data/app/controllers/spotlight/browse_controller.rb +7 -3
  38. data/app/controllers/spotlight/catalog_controller.rb +5 -2
  39. data/app/controllers/spotlight/concerns/application_controller.rb +13 -2
  40. data/app/controllers/spotlight/dashboards_controller.rb +1 -1
  41. data/app/controllers/spotlight/exhibits_controller.rb +2 -3
  42. data/app/controllers/spotlight/featured_images_controller.rb +1 -1
  43. data/app/controllers/spotlight/groups_controller.rb +80 -0
  44. data/app/controllers/spotlight/pages_controller.rb +6 -9
  45. data/app/controllers/spotlight/resources/csv_upload_controller.rb +1 -1
  46. data/app/controllers/spotlight/searches_controller.rb +7 -19
  47. data/app/controllers/spotlight/translations_controller.rb +46 -0
  48. data/app/helpers/spotlight/application_helper.rb +20 -1
  49. data/app/helpers/spotlight/crop_helper.rb +4 -1
  50. data/app/helpers/spotlight/crud_link_helpers.rb +1 -1
  51. data/app/helpers/spotlight/main_app_helpers.rb +1 -1
  52. data/app/helpers/spotlight/pages_helper.rb +1 -1
  53. data/app/jobs/concerns/spotlight/job_tracking.rb +47 -0
  54. data/app/jobs/concerns/spotlight/limit_concurrency.rb +33 -0
  55. data/app/jobs/spotlight/add_uploads_from_csv.rb +34 -6
  56. data/app/jobs/spotlight/application_job.rb +8 -0
  57. data/app/jobs/spotlight/cleanup_job_trackers_job.rb +13 -0
  58. data/app/jobs/spotlight/default_thumbnail_job.rb +1 -3
  59. data/app/jobs/spotlight/reindex_exhibit_job.rb +36 -0
  60. data/app/jobs/spotlight/reindex_job.rb +49 -41
  61. data/app/jobs/spotlight/rename_sidecar_field_job.rb +2 -2
  62. data/app/jobs/spotlight/update_job_trackers_job.rb +20 -0
  63. data/app/mailers/spotlight/indexing_complete_mailer.rb +3 -2
  64. data/app/models/concerns/spotlight/exhibit_defaults.rb +1 -1
  65. data/app/models/concerns/spotlight/translatables.rb +17 -1
  66. data/app/models/concerns/spotlight/user.rb +2 -1
  67. data/app/models/sir_trevor_rails/blocks/browse_group_categories_block.rb +25 -0
  68. data/app/models/spotlight/ability.rb +2 -0
  69. data/app/models/spotlight/about_page.rb +3 -1
  70. data/app/models/spotlight/blacklight_configuration.rb +2 -1
  71. data/app/models/spotlight/contact.rb +1 -1
  72. data/app/models/spotlight/custom_field.rb +3 -3
  73. data/app/models/spotlight/event.rb +13 -0
  74. data/app/models/spotlight/exhibit.rb +18 -14
  75. data/app/models/spotlight/feature_page.rb +3 -1
  76. data/app/models/spotlight/featured_image.rb +29 -12
  77. data/app/models/spotlight/group.rb +22 -0
  78. data/app/models/spotlight/group_member.rb +11 -0
  79. data/app/models/spotlight/home_page.rb +3 -1
  80. data/app/models/spotlight/job_tracker.rb +105 -0
  81. data/app/models/spotlight/main_navigation.rb +2 -2
  82. data/app/models/spotlight/masthead.rb +1 -1
  83. data/app/models/spotlight/page.rb +5 -1
  84. data/app/models/spotlight/page_configurations.rb +6 -0
  85. data/app/models/spotlight/page_content.rb +2 -0
  86. data/app/models/spotlight/reindex_progress.rb +44 -27
  87. data/app/models/spotlight/resource.rb +24 -58
  88. data/app/models/spotlight/resources/csv_upload.rb +2 -1
  89. data/app/models/spotlight/resources/iiif_harvester.rb +10 -1
  90. data/app/models/spotlight/resources/iiif_manifest.rb +11 -7
  91. data/app/models/spotlight/resources/iiif_service.rb +1 -1
  92. data/app/models/spotlight/resources/json_upload.rb +12 -0
  93. data/app/models/spotlight/resources/upload.rb +25 -2
  94. data/app/models/spotlight/search.rb +10 -1
  95. data/app/models/spotlight/solr_document_sidecar.rb +9 -6
  96. data/app/models/spotlight/temporary_image.rb +8 -0
  97. data/app/services/spotlight/etl.rb +7 -0
  98. data/app/services/spotlight/etl/context.rb +52 -0
  99. data/app/services/spotlight/etl/executor.rb +194 -0
  100. data/app/services/spotlight/etl/loaders.rb +12 -0
  101. data/app/services/spotlight/etl/pipeline.rb +81 -0
  102. data/app/services/spotlight/etl/solr_loader.rb +96 -0
  103. data/app/services/spotlight/etl/sources.rb +25 -0
  104. data/app/services/spotlight/etl/step.rb +82 -0
  105. data/app/services/spotlight/etl/transforms.rb +64 -0
  106. data/app/services/spotlight/exhibit_import_export_service.rb +482 -0
  107. data/app/services/spotlight/validity_checker.rb +5 -5
  108. data/app/values/custom_field_name.rb +1 -0
  109. data/app/views/catalog/_save_search.html.erb +1 -1
  110. data/app/views/spotlight/about_pages/_empty.html.erb +5 -5
  111. data/app/views/spotlight/browse/_search.html.erb +5 -3
  112. data/app/views/spotlight/browse/_search_title.html.erb +2 -1
  113. data/app/views/spotlight/browse/index.html.erb +13 -0
  114. data/app/views/spotlight/catalog/_document.html.erb +2 -4
  115. data/app/views/spotlight/catalog/index.iiif_json.jbuilder +22 -0
  116. data/app/views/spotlight/contacts/_form.html.erb +1 -1
  117. data/app/views/spotlight/dashboards/_reindexing_activity.html.erb +6 -6
  118. data/app/views/spotlight/feature_pages/_empty.html.erb +5 -5
  119. data/app/views/spotlight/featured_images/_form.html.erb +1 -1
  120. data/app/views/spotlight/featured_images/_upload_form.html.erb +1 -1
  121. data/app/views/spotlight/home_pages/_empty.html.erb +3 -3
  122. data/app/views/spotlight/indexing_complete_mailer/documents_indexed.html.erb +9 -0
  123. data/app/views/spotlight/pages/_form.html.erb +2 -2
  124. data/app/views/spotlight/searches/_form.html.erb +13 -0
  125. data/app/views/spotlight/searches/_group.html.erb +27 -0
  126. data/app/views/spotlight/searches/_search.html.erb +1 -0
  127. data/app/views/spotlight/searches/index.html.erb +58 -17
  128. data/app/views/spotlight/shared/_honeypot_field.html.erb +4 -0
  129. data/app/views/spotlight/shared/_locale_picker.html.erb +1 -1
  130. data/app/views/spotlight/shared/_report_a_problem.html.erb +7 -10
  131. data/app/views/spotlight/sir_trevor/blocks/_browse_block.html.erb +1 -0
  132. data/app/views/spotlight/sir_trevor/blocks/_browse_group_categories_block.html.erb +45 -0
  133. data/app/views/spotlight/sir_trevor/blocks/_uploaded_items_block.html.erb +7 -1
  134. data/app/views/spotlight/translations/_browse_categories.html.erb +29 -3
  135. data/app/views/spotlight/translations/_general.html.erb +7 -7
  136. data/app/views/spotlight/translations/_groups.html.erb +34 -0
  137. data/app/views/spotlight/translations/_import.html.erb +24 -0
  138. data/app/views/spotlight/translations/_metadata.html.erb +1 -1
  139. data/app/views/spotlight/translations/_page.html.erb +5 -5
  140. data/app/views/spotlight/translations/_pages.html.erb +4 -4
  141. data/app/views/spotlight/translations/_pages_table.html.erb +5 -5
  142. data/app/views/spotlight/translations/_search_fields.html.erb +3 -3
  143. data/app/views/spotlight/translations/edit.html.erb +14 -6
  144. data/app/views/spotlight/translations/show.yaml.yamlbuilder +81 -0
  145. data/config/i18n-tasks.yml +7 -0
  146. data/config/locales/spotlight.ar.yml +57 -24
  147. data/config/locales/spotlight.en.yml +184 -128
  148. data/config/routes.rb +16 -1
  149. data/db/migrate/20200403161512_add_subtitle_to_searches.rb +7 -0
  150. data/db/migrate/20210113092223_create_spotlight_groups.rb +23 -0
  151. data/db/migrate/20210122082032_create_job_trackers.rb +22 -0
  152. data/db/migrate/20210126123041_create_events.rb +15 -0
  153. data/lib/generators/spotlight/install_generator.rb +23 -2
  154. data/lib/generators/spotlight/scaffold_resource_generator.rb +5 -13
  155. data/lib/generators/spotlight/templates/config/initializers/sir_trevor_rails.rb +10 -0
  156. data/lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb +3 -1
  157. data/lib/spotlight/engine.rb +35 -4
  158. data/lib/spotlight/upload_field_config.rb +1 -0
  159. data/lib/spotlight/version.rb +1 -1
  160. data/spec/controllers/spotlight/about_pages_controller_spec.rb +3 -3
  161. data/spec/controllers/spotlight/browse_controller_spec.rb +24 -1
  162. data/spec/controllers/spotlight/catalog_controller_spec.rb +4 -2
  163. data/spec/controllers/spotlight/contacts_controller_spec.rb +2 -2
  164. data/spec/controllers/spotlight/feature_pages_controller_spec.rb +11 -0
  165. data/spec/controllers/spotlight/groups_controller_spec.rb +103 -0
  166. data/spec/controllers/spotlight/home_pages_controller_spec.rb +2 -2
  167. data/spec/controllers/spotlight/resources/csv_upload_controller_spec.rb +4 -4
  168. data/spec/controllers/spotlight/searches_controller_spec.rb +10 -3
  169. data/spec/controllers/spotlight/translations_controller_spec.rb +53 -2
  170. data/spec/controllers/spotlight/view_configurations_controller_spec.rb +1 -1
  171. data/spec/examples.txt +1448 -125
  172. data/spec/factories/featured_images.rb +4 -0
  173. data/spec/factories/group.rb +17 -0
  174. data/spec/factories/job_trackers.rb +9 -0
  175. data/spec/factories/searches.rb +11 -1
  176. data/spec/features/add_contacts_spec.rb +1 -1
  177. data/spec/features/add_items_spec.rb +9 -4
  178. data/spec/features/browse_category_admin_spec.rb +39 -7
  179. data/spec/features/browse_category_navigation_spec.rb +44 -0
  180. data/spec/features/browse_category_spec.rb +2 -2
  181. data/spec/features/catalog_spec.rb +2 -2
  182. data/spec/features/create_exhibit_spec.rb +5 -4
  183. data/spec/features/dashboard_spec.rb +7 -7
  184. data/spec/features/edit_search_fields_spec.rb +2 -2
  185. data/spec/features/exhibits/administration_spec.rb +3 -3
  186. data/spec/features/exhibits/edit_metadata_fields_spec.rb +1 -1
  187. data/spec/features/exhibits/language_create_edit_spec.rb +3 -3
  188. data/spec/features/exhibits/translation_editing_spec.rb +57 -8
  189. data/spec/features/home_page_spec.rb +13 -4
  190. data/spec/features/item_admin_spec.rb +4 -4
  191. data/spec/features/javascript/about_page_admin_spec.rb +1 -1
  192. data/spec/features/javascript/block_controls_spec.rb +3 -1
  193. data/spec/features/javascript/blocks/browse_group_categories_block_spec.rb +64 -0
  194. data/spec/features/javascript/blocks/uploaded_items_block_spec.rb +4 -1
  195. data/spec/features/javascript/browse_group_admin_spec.rb +45 -0
  196. data/spec/features/javascript/edit_in_place_spec.rb +3 -3
  197. data/spec/features/javascript/feature_page_admin_spec.rb +1 -1
  198. data/spec/features/javascript/reindex_monitor_spec.rb +1 -1
  199. data/spec/features/javascript/search_config_admin_spec.rb +1 -1
  200. data/spec/features/report_a_problem_spec.rb +6 -5
  201. data/spec/features/site_users_management_spec.rb +4 -4
  202. data/spec/helpers/spotlight/crud_link_helpers_spec.rb +3 -3
  203. data/spec/helpers/spotlight/pages_helper_spec.rb +10 -2
  204. data/spec/i18n_spec.rb +0 -2
  205. data/spec/jobs/spotlight/add_uploads_from_csv_spec.rb +13 -1
  206. data/spec/jobs/spotlight/reindex_exhibit_job_spec.rb +43 -0
  207. data/spec/jobs/spotlight/reindex_job_spec.rb +30 -59
  208. data/spec/mailers/spotlight/indexing_complete_mailer_spec.rb +11 -1
  209. data/spec/models/sir_trevor_rails/blocks/browse_group_categories_block_spec.rb +41 -0
  210. data/spec/models/solr_document_spec.rb +2 -3
  211. data/spec/models/spotlight/access_controls_enforcement_search_builder_spec.rb +1 -0
  212. data/spec/models/spotlight/exhibit_spec.rb +21 -59
  213. data/spec/models/spotlight/featured_image_spec.rb +27 -0
  214. data/spec/models/spotlight/group_spec.rb +19 -0
  215. data/spec/models/spotlight/main_navigation_spec.rb +1 -1
  216. data/spec/models/spotlight/page_spec.rb +6 -1
  217. data/spec/models/spotlight/reindex_progress_spec.rb +89 -87
  218. data/spec/models/spotlight/resource_spec.rb +69 -90
  219. data/spec/models/spotlight/resources/iiif_harvester_spec.rb +9 -10
  220. data/spec/models/spotlight/resources/upload_spec.rb +43 -79
  221. data/spec/models/spotlight/role_spec.rb +3 -3
  222. data/spec/models/spotlight/search_spec.rb +30 -3
  223. data/spec/models/spotlight/solr_document_sidecar_spec.rb +1 -0
  224. data/spec/services/spotlight/etl/context_spec.rb +66 -0
  225. data/spec/services/spotlight/etl/executor_spec.rb +149 -0
  226. data/spec/services/spotlight/etl/pipeline_spec.rb +22 -0
  227. data/spec/services/spotlight/etl/solr_loader_spec.rb +76 -0
  228. data/spec/services/spotlight/etl/step_spec.rb +70 -0
  229. data/spec/{serializers/spotlight/exhibit_export_serializer_spec.rb → services/spotlight/exhibit_import_export_service_spec.rb} +168 -23
  230. data/spec/services/spotlight/iiif_resource_resolver_spec.rb +1 -1
  231. data/spec/spec_helper.rb +3 -6
  232. data/spec/support/features/test_features_helpers.rb +15 -0
  233. data/spec/test_app_templates/Gemfile.extra +1 -3
  234. data/spec/test_app_templates/catalog_controller.rb +6 -3
  235. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
  236. data/spec/views/shared/_exhibit_navbar.html.erb_spec.rb +1 -1
  237. data/spec/views/spotlight/browse/index.html.erb_spec.rb +2 -0
  238. data/spec/views/spotlight/dashboards/_analytics.html.erb_spec.rb +1 -1
  239. data/spec/views/spotlight/dashboards/_reindexing_activity.html.erb_spec.rb +28 -25
  240. data/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb +3 -3
  241. data/spec/views/spotlight/pages/show.html.erb_spec.rb +1 -0
  242. data/spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb +1 -1
  243. data/spec/views/spotlight/search_configurations/_sort.html.erb_spec.rb +7 -8
  244. data/spec/views/spotlight/translations/_import.html.erb_spec.rb +24 -0
  245. data/vendor/assets/javascripts/leaflet-iiif.js +46 -21
  246. data/vendor/assets/javascripts/tiny-slider.js +3218 -0
  247. data/vendor/assets/stylesheets/tiny-slider.css +1 -0
  248. metadata +444 -289
  249. data/app/models/concerns/spotlight/resources/open_graph.rb +0 -36
  250. data/app/models/spotlight/reindexing_log_entry.rb +0 -42
  251. data/app/serializers/spotlight/exhibit_export_serializer.rb +0 -205
  252. data/app/serializers/spotlight/featured_image_representer.rb +0 -29
  253. data/app/serializers/spotlight/main_navigation_representer.rb +0 -13
  254. data/app/serializers/spotlight/page_representer.rb +0 -33
  255. data/app/services/spotlight/resources/iiif_builder.rb +0 -19
  256. data/app/services/spotlight/solr_document_builder.rb +0 -76
  257. data/app/services/spotlight/upload_solr_document_builder.rb +0 -57
  258. data/spec/factories/reindexing_log_entries.rb +0 -54
  259. data/spec/models/spotlight/reindexing_log_entry_spec.rb +0 -129
  260. data/spec/models/spotlight/resources/open_graph_spec.rb +0 -65
  261. data/spec/services/spotlight/solr_document_builder_spec.rb +0 -66
  262. data/vendor/assets/javascripts/handlebars-v1.3.0.js +0 -2746
@@ -5,7 +5,9 @@ module Spotlight
5
5
  # Feature pages
6
6
  class FeaturePage < Spotlight::Page
7
7
  extend FriendlyId
8
- friendly_id :title, use: %i[slugged scoped finders history], scope: %i[exhibit locale]
8
+ friendly_id :title, use: %i[slugged scoped finders history], scope: %i[exhibit locale] do |config|
9
+ config.reserved_words&.concat(%w[update_all])
10
+ end
9
11
 
10
12
  has_many :child_pages, class_name: 'Spotlight::FeaturePage', inverse_of: :parent_page, foreign_key: 'parent_page_id'
11
13
  belongs_to :parent_page, class_name: 'Spotlight::FeaturePage', optional: true
@@ -6,6 +6,24 @@ module Spotlight
6
6
  class FeaturedImage < ActiveRecord::Base
7
7
  mount_uploader :image, Spotlight::FeaturedImageUploader
8
8
 
9
+ before_validation do
10
+ next unless upload_id.present? && source == 'remote'
11
+
12
+ # copy the image from the temp upload
13
+ temp_image = Spotlight::TemporaryImage.find(upload_id)
14
+ self.image = CarrierWave::SanitizedFile.new tempfile: StringIO.new(temp_image.image.read),
15
+ filename: temp_image.image.filename || temp_image.image.identifier,
16
+ content_type: temp_image.image.content_type
17
+
18
+ # Unset the incoming iiif_tilesource, which points at the temp image
19
+ self.iiif_tilesource = nil
20
+ end
21
+
22
+ after_commit do
23
+ # Clean up the temporary image
24
+ Spotlight::TemporaryImage.find(upload_id).delete if upload_id.present?
25
+ end
26
+
9
27
  after_save do
10
28
  if image.present?
11
29
  image.cache! unless image.cached?
@@ -13,7 +31,7 @@ module Spotlight
13
31
  end
14
32
  end
15
33
 
16
- after_create :set_tilesource_from_uploaded_resource
34
+ attr_accessor :upload_id
17
35
 
18
36
  def iiif_url
19
37
  return unless iiif_service_base.present?
@@ -45,24 +63,23 @@ module Spotlight
45
63
  image.file.present?
46
64
  end
47
65
 
48
- private
49
-
50
- def set_tilesource_from_uploaded_resource
51
- return if iiif_tilesource
52
-
53
- riiif = Riiif::Engine.routes.url_helpers
54
- self.iiif_tilesource = riiif.info_path(id)
55
- save
66
+ def iiif_tilesource
67
+ if self[:iiif_tilesource]
68
+ self[:iiif_tilesource]
69
+ elsif file_present?
70
+ riiif = Riiif::Engine.routes.url_helpers
71
+ riiif.info_path(id)
72
+ end
56
73
  end
57
74
 
75
+ private
76
+
58
77
  def image_size
59
78
  Spotlight::Engine.config.featured_image_thumb_size
60
79
  end
61
80
 
62
81
  def iiif_service_base
63
- return unless iiif_tilesource
64
-
65
- iiif_tilesource.sub('/info.json', '')
82
+ iiif_tilesource&.sub('/info.json', '')
66
83
  end
67
84
  end
68
85
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ ##
5
+ # Exhibit saved searches
6
+ class Group < ActiveRecord::Base
7
+ include Spotlight::Translatables
8
+
9
+ extend FriendlyId
10
+ friendly_id :title, use: %i[slugged scoped finders history], scope: [:exhibit]
11
+ translates :title
12
+
13
+ self.table_name = 'spotlight_groups'
14
+ belongs_to :exhibit
15
+ has_many :group_members
16
+ has_many :searches, through: :group_members, source: :member, source_type: 'Spotlight::Search'
17
+ default_scope { order('weight ASC') }
18
+ scope :published, -> { where(published: true) }
19
+ accepts_nested_attributes_for :group_members
20
+ accepts_nested_attributes_for :searches
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ ##
5
+ # Exhibit saved searches
6
+ class GroupMember < ActiveRecord::Base
7
+ self.table_name = 'spotlight_groups_members'
8
+ belongs_to :group
9
+ belongs_to :member, polymorphic: true
10
+ end
11
+ end
@@ -5,7 +5,9 @@ module Spotlight
5
5
  # Exhibit home page
6
6
  class HomePage < Spotlight::Page
7
7
  extend FriendlyId
8
- friendly_id :title, use: %i[slugged scoped finders], scope: %i[exhibit locale]
8
+ friendly_id :title, use: %i[slugged scoped finders history], scope: %i[exhibit locale] do |config|
9
+ config.reserved_words&.concat(%w[update_all])
10
+ end
9
11
 
10
12
  before_save :publish
11
13
  before_create :default_content
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ # Associate background jobs with records
5
+ class JobTracker < ActiveRecord::Base
6
+ scope :recent, -> { order('updated_at DESC').limit(5) }
7
+ scope :in_progress, -> { where.not(status: %w[completed failed]) }
8
+ scope :completed, -> { where(status: %w[completed failed]) }
9
+
10
+ belongs_to :on, polymorphic: true
11
+ belongs_to :resource, polymorphic: true
12
+ belongs_to :user, optional: true, class_name: Spotlight::Engine.config.user_class # rubocop:disable Rails/ReflectionClassName
13
+ has_many :events, as: :resource, dependent: :delete_all
14
+ has_many :job_trackers, as: :on, dependent: Rails.version > '6.1' ? :destroy_async : :destroy
15
+
16
+ serialize :data
17
+
18
+ after_initialize do
19
+ self.data ||= {}
20
+ end
21
+
22
+ after_commit do
23
+ next unless on.is_a? Spotlight::JobTracker
24
+
25
+ UpdateJobTrackersJob.perform_later(self)
26
+ end
27
+
28
+ def label
29
+ "[#{job_class.titleize}] #{resource_label}"
30
+ end
31
+
32
+ def resource_label
33
+ return resource.filename if resource.is_a? ActiveStorage::Blob
34
+ return resource.name if resource.is_a? Upload
35
+
36
+ resource_id
37
+ end
38
+
39
+ def job_status
40
+ return {} unless job_id
41
+
42
+ @job_status ||= ActiveJob::Status.get(job_id)
43
+ end
44
+
45
+ def progress_label
46
+ return number_with_delimiter(progress) unless total?
47
+
48
+ "#{number_with_delimiter(progress)} / #{number_with_delimiter(total)}"
49
+ end
50
+
51
+ def progress
52
+ data[:progress] || job_status[:progress] || 0
53
+ end
54
+
55
+ def total(default: progress)
56
+ [progress, data[:total] || job_status[:total] || default].max
57
+ end
58
+
59
+ def total?
60
+ total(default: 0).positive?
61
+ end
62
+
63
+ def percent
64
+ return nil unless total?
65
+
66
+ (100.0 * progress) / total
67
+ end
68
+
69
+ def enqueued?
70
+ status == 'enqueued'
71
+ end
72
+
73
+ def in_progress?
74
+ status == 'in_progress'
75
+ end
76
+
77
+ def completed?
78
+ status == 'completed'
79
+ end
80
+
81
+ def failed?
82
+ status == 'failed'
83
+ end
84
+
85
+ def append_log_entry(type:, **args)
86
+ events.create(type: type, data: args)
87
+ rescue StandardError => e
88
+ Rails.logger.error("Unable to create log entry for job tracker #{id}: #{e}")
89
+ end
90
+
91
+ def top_level_job_tracker
92
+ if on.is_a?(Spotlight::JobTracker)
93
+ on.top_level_job_tracker
94
+ else
95
+ self
96
+ end
97
+ end
98
+
99
+ private
100
+
101
+ def number_with_delimiter(*args)
102
+ ActiveSupport::NumberHelper.number_to_delimited(*args)
103
+ end
104
+ end
105
+ end
@@ -26,8 +26,8 @@ module Spotlight
26
26
  end
27
27
  end
28
28
 
29
- def default_label
30
- I18n.t(:"spotlight.main_navigation.#{nav_type}")
29
+ def default_label(**options)
30
+ I18n.t(:"spotlight.main_navigation.#{nav_type}", **options)
31
31
  end
32
32
 
33
33
  private
@@ -11,7 +11,7 @@ module Spotlight
11
11
  private
12
12
 
13
13
  def image_size
14
- [1800, 180]
14
+ Spotlight::Engine.config.featured_image_masthead_size
15
15
  end
16
16
  end
17
17
  end
@@ -7,7 +7,11 @@ module Spotlight
7
7
  MAX_PAGES = Spotlight::Engine.config.max_pages
8
8
 
9
9
  extend FriendlyId
10
- friendly_id :title, use: %i[slugged scoped finders history], scope: %i[exhibit locale]
10
+ # Note: This configuration also needs to be duplicated on the
11
+ # STI models ({Spotlight::AboutPage}, {Spotlight::FeaturePage}, {Spotlight::HomePage})
12
+ friendly_id :title, use: %i[slugged scoped finders history], scope: %i[exhibit locale], treat_reserved_as_conflict: true do |config|
13
+ config.reserved_words&.concat(%w[update_all contacts])
14
+ end
11
15
 
12
16
  belongs_to :exhibit, touch: true
13
17
  belongs_to :created_by, class_name: Spotlight::Engine.config.user_class, optional: true
@@ -27,6 +27,7 @@ module Spotlight
27
27
  to: :context
28
28
 
29
29
  attr_reader :context, :page
30
+
30
31
  def initialize(context:, page:)
31
32
  @context = context
32
33
  @page = page
@@ -39,6 +40,7 @@ module Spotlight
39
40
  'attachment-endpoint': attachment_endpoint,
40
41
  'autocomplete-exhibit-catalog-path': exhibit_autocomplete_endpoint,
41
42
  'autocomplete-exhibit-pages-path': page_autocomplete_endpoint,
43
+ 'autocomplete-exhibit-browse-groups-path': browse_groups_autocomplete_endpoint,
42
44
  'autocomplete-exhibit-searches-path': search_autocomplete_endpoint,
43
45
  'preview-url': page_preview_url
44
46
  }.merge(downstream_parameters)
@@ -61,6 +63,10 @@ module Spotlight
61
63
  spotlight.exhibit_attachments_path(current_exhibit)
62
64
  end
63
65
 
66
+ def browse_groups_autocomplete_endpoint
67
+ spotlight.exhibit_groups_path(current_exhibit)
68
+ end
69
+
64
70
  def exhibit_autocomplete_endpoint
65
71
  spotlight.autocomplete_exhibit_catalog_path(current_exhibit, q: '%QUERY', format: 'json')
66
72
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spotlight/page_content/sir_trevor'
4
+
3
5
  module Spotlight
4
6
  # Factory for picking the right page content renderer
5
7
  module PageContent
@@ -4,59 +4,76 @@ module Spotlight
4
4
  ##
5
5
  # ReindexProgress is a class that models the progress of reindexing a list of resources
6
6
  class ReindexProgress
7
- attr_reader :current_log_entry
7
+ attr_reader :exhibit
8
8
 
9
- delegate :updated_at, to: :current_log_entry
9
+ delegate :updated_at, to: :most_relevant_job_tracker
10
10
 
11
- def initialize(current_log_entry)
12
- @current_log_entry = current_log_entry
11
+ def initialize(exhibit)
12
+ @exhibit = exhibit
13
+ end
14
+
15
+ def as_json(*)
16
+ {
17
+ recently_in_progress: recently_in_progress?,
18
+ started_at: localized_start_time,
19
+ finished_at: localized_finish_time,
20
+ updated_at: localized_updated_time,
21
+ total: [total, completed].max,
22
+ completed: completed,
23
+ finished: finished?,
24
+ errored: errored?
25
+ }
26
+ end
27
+
28
+ private
29
+
30
+ def job_trackers
31
+ @job_trackers ||= exhibit.job_trackers.where(job_class: 'Spotlight::ReindexExhibitJob').recent
32
+ end
33
+
34
+ def most_relevant_job_tracker
35
+ return @most_relevant_job_tracker if @most_relevant_job_tracker
36
+
37
+ @most_relevant_job_tracker ||= job_trackers.in_progress.first || job_trackers.completed.first || job_trackers.first || Spotlight::JobTracker.new
13
38
  end
14
39
 
15
40
  def recently_in_progress?
16
- return true if current_log_entry.in_progress?
41
+ return false unless most_relevant_job_tracker.persisted?
42
+ return true if most_relevant_job_tracker.in_progress?
17
43
 
18
- current_log_entry.end_time.present? && (current_log_entry.end_time > Spotlight::Engine.config.reindex_progress_window.minutes.ago)
44
+ finished? && most_relevant_job_tracker.updated_at >= Spotlight::Engine.config.reindex_progress_window.ago
19
45
  end
20
46
 
21
47
  def started_at
22
- current_log_entry.start_time
48
+ most_relevant_job_tracker.created_at
23
49
  end
24
50
 
25
51
  def finished?
26
- current_log_entry.succeeded? || current_log_entry.failed?
52
+ most_relevant_job_tracker.completed? || (errored? && most_relevant_job_tracker.job_trackers.none?(&:in_progress?))
27
53
  end
28
54
 
29
55
  def finished_at
30
- current_log_entry.end_time
56
+ return unless finished?
57
+
58
+ most_relevant_job_tracker.updated_at
31
59
  end
32
60
 
33
61
  def total
34
- current_log_entry.items_reindexed_estimate
62
+ return most_relevant_job_tracker.total if finished?
63
+
64
+ most_relevant_job_tracker.job_trackers.sum(&:total)
35
65
  end
36
66
 
37
67
  def completed
38
- current_log_entry.items_reindexed_count
39
- end
68
+ return most_relevant_job_tracker.progress if finished?
40
69
 
41
- def errored?
42
- current_log_entry.failed?
70
+ most_relevant_job_tracker.job_trackers.sum(&:progress)
43
71
  end
44
72
 
45
- def as_json(*)
46
- {
47
- recently_in_progress: recently_in_progress?,
48
- started_at: localized_start_time,
49
- finished_at: localized_finish_time,
50
- updated_at: localized_updated_time,
51
- total: total,
52
- completed: completed,
53
- finished: finished?,
54
- errored: errored?
55
- }
73
+ def errored?
74
+ most_relevant_job_tracker.failed?
56
75
  end
57
76
 
58
- private
59
-
60
77
  def localized_start_time
61
78
  return unless started_at
62
79
 
@@ -4,10 +4,17 @@ module Spotlight
4
4
  ##
5
5
  # Exhibit resources
6
6
  class Resource < ActiveRecord::Base
7
- include ActiveSupport::Benchmarkable
8
-
9
- class_attribute :document_builder_class
10
- self.document_builder_class = SolrDocumentBuilder
7
+ class_attribute :indexing_pipeline, default: (Spotlight::Etl::Pipeline.new do |pipeline|
8
+ pipeline.sources = [Spotlight::Etl::Sources::IdentitySource]
9
+ pipeline.transforms = [
10
+ reject_blank: Spotlight::Etl::Transforms::RejectBlank,
11
+ reject_missing: Spotlight::Etl::Transforms::RejectMissingUniqueId,
12
+ apply_exhibit_metadata: Spotlight::Etl::Transforms::ApplyExhibitMetadata,
13
+ apply_application_metadata: Spotlight::Etl::Transforms::ApplyApplicationMetadata,
14
+ apply_pipeline_metadata: Spotlight::Etl::Transforms::ApplyPipelineMetadata
15
+ ]
16
+ pipeline.loaders = [Spotlight::Etl::SolrLoader]
17
+ end)
11
18
 
12
19
  extend ActiveModel::Callbacks
13
20
  define_model_callbacks :index
@@ -16,12 +23,10 @@ module Spotlight
16
23
 
17
24
  belongs_to :exhibit
18
25
  has_many :solr_document_sidecars
26
+ has_many :events, as: :resource
19
27
 
20
28
  serialize :data, Hash
21
29
 
22
- after_index :commit
23
- after_index :touch_exhibit!
24
-
25
30
  ##
26
31
  # Persist the record to the database, and trigger a reindex to solr
27
32
  #
@@ -45,67 +50,28 @@ module Spotlight
45
50
  # Index the result of {#to_solr} into the index in batches of {#batch_size}
46
51
  #
47
52
  # @return [Integer] number of records indexed
48
- def reindex(reindexing_log_entry = nil)
49
- benchmark "Reindexing #{self} (batch size: #{batch_size})" do
50
- count = 0
51
-
52
- run_callbacks :index do
53
- document_builder.documents_to_index.each_slice(batch_size) do |batch|
54
- write_to_index(batch)
55
- count += batch.length
56
- reindexing_log_entry&.update(items_reindexed_count: count)
57
- end
58
-
59
- count
53
+ def reindex(touch: true, **args, &block)
54
+ i = 0
55
+ run_callbacks :index do
56
+ indexing_pipeline.call(Spotlight::Etl::Context.new(self, commit: true, **args)) do |data|
57
+ i += 1
58
+ block&.call(data)
60
59
  end
61
60
  end
62
- end
63
-
64
- def document_builder
65
- @document_builder ||= document_builder_class.new(self)
66
- end
67
-
68
- private
69
-
70
- def blacklight_solr
71
- @solr ||= RSolr.connect(connection_config.merge(adapter: connection_config[:http_adapter]))
72
- end
73
61
 
74
- def connection_config
75
- Blacklight.connection_config
76
- end
62
+ touch_exhibit! if touch
77
63
 
78
- def batch_size
79
- Spotlight::Engine.config.solr_batch_size
64
+ i
80
65
  end
81
66
 
82
- def write_to_index(batch)
83
- documents = documents_that_have_ids(batch)
84
- return unless write? && documents.present?
85
-
86
- blacklight_solr.update params: { commitWithin: 500 },
87
- data: documents.to_json,
88
- headers: { 'Content-Type' => 'application/json' }
67
+ def estimated_size(**args)
68
+ indexing_pipeline.estimated_size(Spotlight::Etl::Context.new(self, **args))
89
69
  end
90
70
 
91
- def commit
92
- return unless write?
93
-
94
- blacklight_solr.commit
95
- rescue StandardError => e
96
- Rails.logger.warn "Unable to commit to solr: #{e}"
97
- end
71
+ private
98
72
 
99
73
  def touch_exhibit!
100
- exhibit.touch
101
- end
102
-
103
- def write?
104
- Spotlight::Engine.config.writable_index
105
- end
106
-
107
- def documents_that_have_ids(document_list)
108
- document_list.reject { |d| d[document_builder.document_model.unique_key.to_sym].blank? }
74
+ exhibit&.touch
109
75
  end
110
76
  end
111
77
  end