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
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ ##
5
+ # Reindex an exhibit by parallelizing resource indexing into multiple batches of reindex jobs
6
+ class ReindexExhibitJob < Spotlight::ApplicationJob
7
+ include Spotlight::JobTracking
8
+ include Spotlight::LimitConcurrency
9
+
10
+ def perform(exhibit, batch_size: Spotlight::Engine.config.reindexing_batch_size, batch_count: Spotlight::Engine.config.reindexing_batch_count, **)
11
+ job_tracker.update(status: 'in_progress')
12
+
13
+ count = exhibit.resources.count
14
+
15
+ # Use the provided batch size, or calculate a reasonable default
16
+ batch_count = (count.to_f / batch_size).ceil if batch_size
17
+ batch_count ||= 1 + Math.log(count).round # e.g. 10 => 3, 100 => 6, 1000 => 8
18
+
19
+ return Spotlight::ReindexJob.perform_now(exhibit, reports_on: job_tracker) if batch_count == 1
20
+
21
+ batch_size ||= (count.to_f / batch_count).ceil
22
+
23
+ perform_later_in_batches(exhibit, of: batch_size)
24
+ end
25
+
26
+ def perform_later_in_batches(exhibit, of:)
27
+ last = 0
28
+ exhibit.resources.select(:id).in_batches(of: of) do |batch|
29
+ last = batch.last.id
30
+ Spotlight::ReindexJob.perform_later(exhibit, reports_on: job_tracker, start: batch.first.id, finish: batch.last.id)
31
+ end
32
+
33
+ Spotlight::ReindexJob.perform_later(exhibit, reports_on: job_tracker, start: last)
34
+ end
35
+ end
36
+ end
@@ -3,72 +3,80 @@
3
3
  module Spotlight
4
4
  ##
5
5
  # Reindex the given resources or exhibits
6
- class ReindexJob < ActiveJob::Base
7
- queue_as :default
8
-
9
- # The validity checker is a seam for implementations to expire unnecessary
10
- # indexing tasks if it becomes redundant while waiting in the job queue.
11
- class_attribute :validity_checker, default: Spotlight::ValidityChecker.new
12
- self.validity_checker ||= Spotlight::ValidityChecker.new if Rails.version < '5.2'
6
+ class ReindexJob < Spotlight::ApplicationJob
7
+ include Spotlight::JobTracking
8
+ include Spotlight::LimitConcurrency
13
9
 
14
10
  before_perform do |job|
15
- job_log_entry = log_entry(job)
16
- next unless job_log_entry
11
+ pagination = job.arguments.last.slice(:start, :finish) if job.arguments.last.is_a? Hash
12
+ pagination ||= {}
17
13
 
18
- items_reindexed_estimate = resource_list(job.arguments.first).sum do |resource|
19
- resource.document_builder.documents_to_index.size
20
- end
21
- job_log_entry.update(items_reindexed_estimate: items_reindexed_estimate)
14
+ progress.total = resource_list(job.arguments.first, **pagination).sum(&:estimated_size)
15
+ end
16
+
17
+ after_perform do
18
+ exhibit&.touch # rubocop:disable Rails/SkipsModelValidations
22
19
  end
23
20
 
24
- around_perform do |job, block|
25
- job_log_entry = log_entry(job)
26
- job_log_entry&.in_progress!
21
+ after_perform :commit
22
+
23
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
24
+ def perform(exhibit_or_resources, start: nil, finish: nil, **)
25
+ job_tracker.update(status: 'in_progress')
26
+
27
+ errors = 0
28
+
29
+ error_handler = lambda do |pipeline, _error_context, exception, _data|
30
+ job_tracker.append_log_entry(type: :error, message: exception.to_s, resource_id: pipeline.source&.id)
31
+ errors += 1
32
+ end
27
33
 
28
- begin
29
- block.call
30
- rescue StandardError
31
- job_log_entry&.failed!
32
- raise
34
+ resource_list(exhibit_or_resources, start: start, finish: finish).each do |resource|
35
+ resource.reindex(touch: false, commit: false, job_tracker: job_tracker, additional_data: job_data, on_error: error_handler) do |*|
36
+ progress&.increment
37
+ end
38
+ rescue StandardError => e
39
+ error_handler.call(Struct.new(:source).new(resource), self, e, nil)
33
40
  end
34
41
 
35
- job_log_entry&.succeeded!
42
+ job_tracker.append_log_entry(type: :info, message: "#{progress.progress} of #{progress.total} (#{errors} errors)")
43
+ job_tracker.update(status: errors.zero? ? 'completed' : 'failed', data: { progress: progress.progress, total: progress.total })
36
44
  end
45
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
37
46
 
38
- def self.perform_later(exhibit_or_resources, log_entry = nil)
39
- validity_token = validity_checker.mint(exhibit_or_resources)
47
+ private
40
48
 
41
- super(exhibit_or_resources, log_entry, validity_token)
49
+ def commit
50
+ Blacklight.default_index.connection.commit
42
51
  end
43
52
 
44
- def perform(exhibit_or_resources, log_entry = nil, validity_token = nil)
45
- return unless still_valid?(exhibit_or_resources, validity_token)
53
+ def job_data
54
+ return unless job_tracker
46
55
 
47
- resource_list(exhibit_or_resources).each do |resource|
48
- resource.reindex(log_entry)
49
- end
56
+ { Spotlight::Engine.config.job_tracker_id_field => job_tracker.top_level_job_tracker.job_id }
50
57
  end
51
58
 
52
- private
53
-
54
- def resource_list(exhibit_or_resources)
59
+ def resource_list(exhibit_or_resources, start: nil, finish: nil)
55
60
  if exhibit_or_resources.is_a?(Spotlight::Exhibit)
56
- exhibit_or_resources.resources.find_each
57
- elsif exhibit_or_resources.is_a?(Enumerable)
58
- exhibit_or_resources
61
+ exhibit_or_resources.resources.find_each(start: start, finish: finish)
59
62
  else
60
63
  Array(exhibit_or_resources)
61
64
  end
62
65
  end
63
66
 
64
- def log_entry(job)
65
- job.arguments.second if job.arguments.second.is_a?(Spotlight::ReindexingLogEntry)
67
+ def job_tracking_resource
68
+ exhibit
66
69
  end
67
70
 
68
- def still_valid?(exhibit_or_resources, validity_token)
69
- return true unless validity_token
71
+ def exhibit
72
+ exhibit_or_resources = arguments.first
70
73
 
71
- validity_checker.check exhibit_or_resources, validity_token
74
+ case exhibit_or_resources
75
+ when Spotlight::Exhibit
76
+ exhibit_or_resources
77
+ when Spotlight::Resource
78
+ exhibit_or_resources.exhibit
79
+ end
72
80
  end
73
81
  end
74
82
  end
@@ -4,8 +4,8 @@ module Spotlight
4
4
  ##
5
5
  # After renaming an exhibit-specific field, we also
6
6
  # need to update the sidecars that may contain that field
7
- class RenameSidecarFieldJob < ActiveJob::Base
8
- queue_as :default
7
+ class RenameSidecarFieldJob < Spotlight::ApplicationJob
8
+ include Spotlight::JobTracking
9
9
 
10
10
  def perform(exhibit, old_field, new_field, old_slug = nil, new_slug = nil)
11
11
  exhibit.solr_document_sidecars.find_each do |s|
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ ###
5
+ # Calls the #set_default_thumbnail method
6
+ # on the object passed in and calls save
7
+ ###
8
+ class UpdateJobTrackersJob < Spotlight::ApplicationJob
9
+ def perform(job_tracker)
10
+ reports_on = job_tracker.on
11
+
12
+ return unless reports_on.is_a? Spotlight::JobTracker
13
+
14
+ reports_on.update(status: 'completed') if reports_on.job_trackers.all?(&:completed?)
15
+ reports_on.update(status: 'failed') if reports_on.job_trackers.any?(&:failed?)
16
+
17
+ reports_on.update(data: { progress: reports_on.job_trackers.sum(&:progress), total: reports_on.job_trackers.sum(&:total) })
18
+ end
19
+ end
20
+ end
@@ -5,9 +5,10 @@ module Spotlight
5
5
  # Notify the curator that we're finished processing a
6
6
  # batch upload
7
7
  class IndexingCompleteMailer < ActionMailer::Base
8
- def documents_indexed(csv_data, exhibit, user)
9
- @number = csv_data.length
8
+ def documents_indexed(csv_data, exhibit, user, indexed_count: nil, errors: [])
9
+ @number = indexed_count || csv_data.length
10
10
  @exhibit = exhibit
11
+ @errors = errors
11
12
  mail(to: user.email, subject: 'Document indexing complete')
12
13
  end
13
14
  end
@@ -29,7 +29,7 @@ module Spotlight
29
29
  def initialize_browse
30
30
  return unless searches.blank?
31
31
 
32
- searches.create title: 'All Exhibit Items',
32
+ searches.create title: 'All exhibit items',
33
33
  long_description: 'All items in this exhibit.'
34
34
  end
35
35
 
@@ -15,8 +15,24 @@ module Spotlight
15
15
  # Set up a reader for the specified attribute that uses the I18n backend,
16
16
  # and defaults to the ActiveRecord value
17
17
  def define_translated_attr_reader(attr_name)
18
+ # Define a dynamic method for translating database-backed attributes,
19
+ # falling back to the database information as needed.
20
+ #
21
+ # Note: the empty string is provided as the final fallback to avoid i18n blowing
22
+ # up on nil attributes.
18
23
  define_method(:"#{attr_name}") do
19
- I18n.translate(attr_name, scope: slug, default: attr_translation(attr_name))
24
+ send("translated_#{attr_name}", default: [attr_translation(attr_name), ''])
25
+ end
26
+
27
+ # Define an accessor that gets the value of the attribute in a given locale,
28
+ # returning `nil` for untranslated values.
29
+ #
30
+ # Note: For the default locale, we actually want to dig into the database,
31
+ # because that is the source of truth for the data.
32
+ define_method(:"translated_#{attr_name}") do |default: [], **options|
33
+ default = Array.wrap(default)
34
+ default.prepend(attr_translation(attr_name)) if I18n.locale == I18n.default_locale
35
+ I18n.translate(attr_name, scope: slug, default: default, **options).presence
20
36
  end
21
37
  end
22
38
  end
@@ -8,7 +8,6 @@ module Spotlight
8
8
  included do
9
9
  has_many :roles, class_name: 'Spotlight::Role', dependent: :destroy
10
10
  has_many :exhibits, class_name: 'Spotlight::Exhibit', through: :roles, source: 'resource', source_type: 'Spotlight::Exhibit'
11
- has_many :reindexing_log_entries, class_name: 'Spotlight::ReindexingLogEntry'
12
11
 
13
12
  scope :with_roles, -> { where(id: Spotlight::Role.distinct.pluck(:user_id)) }
14
13
 
@@ -28,6 +27,8 @@ module Spotlight
28
27
  end
29
28
 
30
29
  def add_default_roles
30
+ return unless Spotlight::Engine.config.assign_default_roles_to_first_user
31
+
31
32
  roles.build role: 'admin', resource: Spotlight::Site.instance unless self.class.any?
32
33
  end
33
34
 
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SirTrevorRails
4
+ module Blocks
5
+ ##
6
+ # Browese Group Categories
7
+ class BrowseGroupCategoriesBlock < SirTrevorRails::Block
8
+ include Displayable
9
+
10
+ def display_item_counts?
11
+ send(:'display-item-counts') == 'true'
12
+ end
13
+
14
+ def groups
15
+ @groups ||= parent.exhibit.groups.published.where(slug: item_ids).sort do |a, b|
16
+ ordered_items.index(a.slug) <=> ordered_items.index(b.slug)
17
+ end
18
+ end
19
+
20
+ def groups?
21
+ !groups.empty?
22
+ end
23
+ end
24
+ end
25
+ end
@@ -25,6 +25,7 @@ module Spotlight
25
25
  can :manage, [
26
26
  Spotlight::Attachment,
27
27
  Spotlight::Search,
28
+ Spotlight::Group,
28
29
  Spotlight::Resource,
29
30
  Spotlight::Page,
30
31
  Spotlight::Contact,
@@ -43,6 +44,7 @@ module Spotlight
43
44
  can :read, Spotlight::Exhibit, published: true
44
45
  can :read, Spotlight::Page, published: true
45
46
  can :read, Spotlight::Search, published: true
47
+ can :read, Spotlight::Group, published: true
46
48
  can :read, Spotlight::Language, public: true
47
49
  end
48
50
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
@@ -5,6 +5,8 @@ module Spotlight
5
5
  # About pages
6
6
  class AboutPage < 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 contacts])
10
+ end
9
11
  end
10
12
  end
@@ -76,6 +76,7 @@ module Spotlight
76
76
 
77
77
  config.show.merge! show unless show.blank?
78
78
  config.index.merge! index unless index.blank?
79
+ config.index.respond_to[:iiif_json] = true
79
80
 
80
81
  config.index.thumbnail_field ||= Spotlight::Engine.config.thumbnail_field
81
82
 
@@ -353,7 +354,7 @@ module Spotlight
353
354
  def title_only_by_default?(view)
354
355
  return false if %i[show enabled].include?(view)
355
356
 
356
- title_only = default_blacklight_config.view.send(:[], view).try(:title_only_by_default)
357
+ title_only = default_blacklight_config.view.send(:[], view)&.title_only_by_default
357
358
  title_only.nil? ? false : title_only
358
359
  end
359
360
 
@@ -19,7 +19,7 @@ module Spotlight
19
19
  self.contact_info = contact_info.symbolize_keys
20
20
  end
21
21
 
22
- before_save on: :create do
22
+ before_create do
23
23
  self.show_in_sidebar = true if show_in_sidebar.nil?
24
24
  end
25
25
 
@@ -18,10 +18,10 @@ module Spotlight
18
18
  self.field_type ||= 'text'
19
19
  end
20
20
 
21
- before_save :update_field_name, on: :update, if: -> { field_type_changed? || readonly_field_changed? }
21
+ before_update :update_field_name, if: -> { field_type_changed? || readonly_field_changed? }
22
22
 
23
- after_commit :update_blacklight_configuration_after_field_name_change, on: :update, if: -> { saved_change_to_field? || saved_change_to_slug? }
24
- after_commit :update_sidecar_data_after_field_name_change, on: :update, if: -> { saved_change_to_field? || saved_change_to_slug? }
23
+ after_update_commit :update_blacklight_configuration_after_field_name_change, if: -> { saved_change_to_field? || saved_change_to_slug? }
24
+ after_update_commit :update_sidecar_data_after_field_name_change, if: -> { saved_change_to_field? || saved_change_to_slug? }
25
25
 
26
26
  def label=(label)
27
27
  configuration['label'] = label
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ # Logged events for Spotlight exhibits
5
+ class Event < ActiveRecord::Base
6
+ belongs_to :resource, polymorphic: true
7
+ belongs_to :exhibit, optional: true
8
+
9
+ serialize :data
10
+
11
+ self.inheritance_column = :event_class
12
+ end
13
+ end
@@ -22,11 +22,16 @@ module Spotlight
22
22
  paginates_per 48
23
23
 
24
24
  extend FriendlyId
25
- friendly_id :title, use: %i[slugged finders]
25
+ friendly_id :title, use: %i[slugged finders] do |config|
26
+ config.reserved_words&.concat(%w[site])
27
+ end
28
+
26
29
  validates :title, presence: true, if: -> { I18n.locale == I18n.default_locale }
27
30
  validates :slug, uniqueness: true
28
31
  validates :theme, inclusion: { in: Spotlight::Engine.config.exhibit_themes }, allow_blank: true
29
32
 
33
+ after_validation :move_friendly_id_error_to_slug
34
+
30
35
  acts_as_tagger
31
36
  acts_as_taggable
32
37
  delegate :blacklight_config, to: :blacklight_configuration
@@ -50,8 +55,9 @@ module Spotlight
50
55
  has_many :custom_search_fields, dependent: :delete_all
51
56
 
52
57
  has_many :feature_pages, -> { for_default_locale }, extend: FriendlyId::FinderMethods
58
+ has_many :groups, dependent: :delete_all
59
+ has_many :job_trackers, as: :on, dependent: :delete_all
53
60
  has_many :main_navigations, dependent: :delete_all
54
- has_many :reindexing_log_entries, dependent: :destroy
55
61
  has_many :resources
56
62
  has_many :roles, as: :resource, dependent: :delete_all
57
63
  has_many :searches, dependent: :destroy, extend: FriendlyId::FinderMethods
@@ -70,7 +76,7 @@ module Spotlight
70
76
  belongs_to :masthead, dependent: :destroy, optional: true
71
77
  belongs_to :thumbnail, class_name: 'Spotlight::ExhibitThumbnail', dependent: :destroy, optional: true
72
78
 
73
- accepts_nested_attributes_for :about_pages, :attachments, :contacts, :custom_fields, :feature_pages, :languages,
79
+ accepts_nested_attributes_for :about_pages, :attachments, :contacts, :custom_fields, :feature_pages, :groups, :languages,
74
80
  :main_navigations, :owned_taggings, :pages, :resources, :searches, :solr_document_sidecars, :translations
75
81
  accepts_nested_attributes_for :blacklight_configuration, :home_page, :filters, update_only: true
76
82
  accepts_nested_attributes_for :masthead, :thumbnail, update_only: true, reject_if: proc { |attr| attr['iiif_tilesource'].blank? }
@@ -100,8 +106,10 @@ module Spotlight
100
106
  end
101
107
 
102
108
  def import(hash)
103
- Spotlight::ExhibitExportSerializer.prepare(self).from_hash(hash)
104
- self
109
+ ActiveRecord::Base.transaction do
110
+ Spotlight::ExhibitImportExportService.new(self).from_hash!(hash)
111
+ save
112
+ end
105
113
  end
106
114
 
107
115
  def solr_data
@@ -110,8 +118,8 @@ module Spotlight
110
118
  end
111
119
  end
112
120
 
113
- def reindex_later(user = nil)
114
- Spotlight::ReindexJob.perform_later(self, new_reindexing_log_entry(user))
121
+ def reindex_later(current_user = nil)
122
+ Spotlight::ReindexExhibitJob.perform_later(self, user: current_user)
115
123
  end
116
124
 
117
125
  def uploaded_resource_fields
@@ -127,7 +135,7 @@ module Spotlight
127
135
  end
128
136
 
129
137
  def reindex_progress
130
- @reindex_progress ||= ReindexProgress.new(current_reindexing_log_entry)
138
+ @reindex_progress ||= ReindexProgress.new(self)
131
139
  end
132
140
 
133
141
  def available_locales
@@ -140,14 +148,10 @@ module Spotlight
140
148
  self.description = ::Rails::Html::FullSanitizer.new.sanitize(description)
141
149
  end
142
150
 
143
- def new_reindexing_log_entry(user = nil)
144
- Spotlight::ReindexingLogEntry.create(exhibit: self, user: user, items_reindexed_count: 0, job_status: 'unstarted')
145
- end
146
-
147
151
  private
148
152
 
149
- def current_reindexing_log_entry
150
- reindexing_log_entries.started_or_completed.first || reindexing_log_entries.build
153
+ def move_friendly_id_error_to_slug
154
+ errors.add :slug, *errors.delete(:friendly_id) if errors[:friendly_id].present?
151
155
  end
152
156
  end
153
157
  end