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
@@ -19,6 +19,10 @@ module Spotlight
19
19
 
20
20
  helper_method :get_search_results, :search_results, :fetch, :page_collection_name, :presenter
21
21
 
22
+ before_action do
23
+ blacklight_config.view.gallery.classes = 'row-cols-2 row-cols-md-4' unless @page&.display_sidebar
24
+ end
25
+
22
26
  # GET /exhibits/1/pages
23
27
  def index
24
28
  # set up a model the inline "add a new page" form
@@ -70,7 +74,7 @@ module Spotlight
70
74
  @page.lock&.delete
71
75
 
72
76
  if @page.update(page_params.merge(last_edited_by: current_user))
73
- redirect_to [spotlight, @page.exhibit, @page], flash: { html_safe: true }, notice: undo_notice(:updated)
77
+ redirect_to [spotlight, @page.exhibit, @page, format: params.permit(:format)], flash: { html_safe: true }, notice: undo_notice(:updated)
74
78
  else
75
79
  render action: 'edit'
76
80
  end
@@ -146,14 +150,7 @@ module Spotlight
146
150
  end
147
151
 
148
152
  def allowed_page_params
149
- [:title, :content, thumbnail_attributes: featured_image_attributes]
150
- end
151
-
152
- def featured_image_attributes
153
- %i[
154
- source image document_global_id iiif_region iiif_tilesource
155
- iiif_manifest_url iiif_canvas_id iiif_image_id
156
- ]
153
+ [:title, :content, thumbnail_attributes: featured_image_params]
157
154
  end
158
155
 
159
156
  def human_name
@@ -16,7 +16,7 @@ module Spotlight
16
16
 
17
17
  def create
18
18
  csv = CSV.parse(csv_io_param, headers: true, return_headers: false).map(&:to_hash)
19
- Spotlight::AddUploadsFromCSV.perform_later(csv, current_exhibit, current_user)
19
+ Spotlight::AddUploadsFromCsv.perform_later(csv, current_exhibit, current_user)
20
20
  flash[:notice] = t('spotlight.resources.upload.csv.success', file_name: csv_io_name)
21
21
  redirect_to spotlight.admin_exhibit_catalog_path(current_exhibit)
22
22
  end
@@ -5,9 +5,8 @@ module Spotlight
5
5
  # CRUD actions for curating browse categories (see
6
6
  # {Spotlight::BrowseController} for the end-user read and index actions)
7
7
  class SearchesController < Spotlight::ApplicationController
8
- load_resource :exhibit, class: 'Spotlight::Exhibit'
8
+ load_and_authorize_resource :exhibit, class: 'Spotlight::Exhibit', parent_action: :curate
9
9
  before_action :authenticate_user!
10
- before_action :only_curators!
11
10
  before_action :create_or_load_resource, only: [:create]
12
11
  load_and_authorize_resource through: :exhibit
13
12
  before_action :attach_breadcrumbs, only: %i[index edit], unless: -> { request.format.json? }
@@ -28,10 +27,11 @@ module Spotlight
28
27
  end
29
28
 
30
29
  def index
30
+ @groups = @exhibit.groups
31
31
  respond_to do |format|
32
32
  format.html
33
33
  format.json do
34
- render json: @searches.as_json(methods: %i[count thumbnail_image_url]), root: false
34
+ render json: @searches.as_json(methods: %i[full_title count thumbnail_image_url]), root: false
35
35
  end
36
36
  end
37
37
  end
@@ -50,7 +50,8 @@ module Spotlight
50
50
  end
51
51
 
52
52
  def edit
53
- add_breadcrumb @search.title, edit_exhibit_search_path(@search.exhibit, @search)
53
+ @groups = @exhibit.groups
54
+ add_breadcrumb @search.full_title, edit_exhibit_search_path(@search.exhibit, @search)
54
55
  @exhibit = @search.exhibit
55
56
  end
56
57
 
@@ -105,9 +106,11 @@ module Spotlight
105
106
  def search_params
106
107
  params.require(:search).permit(
107
108
  :title,
109
+ :subtitle,
108
110
  :long_description,
109
111
  :search_box,
110
112
  :default_index_view_type,
113
+ group_ids: [],
111
114
  masthead_attributes: featured_image_params,
112
115
  thumbnail_attributes: featured_image_params
113
116
  )
@@ -117,21 +120,6 @@ module Spotlight
117
120
  params.to_unsafe_h.with_indifferent_access.except(:exhibit_id, :search, *blacklisted_search_session_params).reject { |_k, v| v.blank? }
118
121
  end
119
122
 
120
- def featured_image_params
121
- %i[
122
- iiif_region iiif_tilesource
123
- iiif_manifest_url iiif_canvas_id iiif_image_id
124
- display
125
- source
126
- image
127
- document_global_id
128
- ]
129
- end
130
-
131
- def only_curators!
132
- authorize! :curate, @exhibit if @exhibit
133
- end
134
-
135
123
  def blacklisted_search_session_params
136
124
  %i[id commit counter total search_id page per_page authenticity_token utf8 action controller]
137
125
  end
@@ -21,6 +21,22 @@ module Spotlight
21
21
  end
22
22
  end
23
23
 
24
+ def show
25
+ respond_to do |format|
26
+ format.yaml
27
+ end
28
+ end
29
+
30
+ def import
31
+ if current_exhibit.update(import_exhibit_params)
32
+ I18n.reload! # reload since we're memoizing
33
+ notice = t(:'helpers.submit.spotlight_default.updated', model: current_exhibit.class.model_name.human.downcase)
34
+ redirect_to edit_exhibit_translations_path(current_exhibit, language: @language), notice: notice
35
+ else
36
+ render 'edit'
37
+ end
38
+ end
39
+
24
40
  private
25
41
 
26
42
  def attach_breadcrumbs
@@ -33,6 +49,21 @@ module Spotlight
33
49
  params.require(:exhibit).permit(translations_attributes: %i[id locale key value])
34
50
  end
35
51
 
52
+ def import_exhibit_params
53
+ imported_translations = YAML.safe_load(params.require(:file).read)
54
+
55
+ # set language from YML root locale
56
+ language = imported_translations.keys.first
57
+
58
+ # convert YML to hash
59
+ translation = unfold(imported_translations.values.first).map do |k, v|
60
+ current_translation = Translation.find_or_initialize_by(exhibit: current_exhibit, key: k, locale: language)
61
+ { key: k, value: v, locale: language, id: current_translation.id }
62
+ end
63
+
64
+ { translations_attributes: translation }
65
+ end
66
+
36
67
  def set_language
37
68
  @language = params[:language] || current_exhibit.available_locales.first
38
69
  end
@@ -40,5 +71,20 @@ module Spotlight
40
71
  def set_tab
41
72
  @tab = params[:tab]
42
73
  end
74
+
75
+ def unfold(value, key = nil)
76
+ return to_enum(:unfold, value, key) unless block_given?
77
+
78
+ if value.is_a? Hash
79
+ value.each do |k, v|
80
+ arr = unfold(v, [key, k].compact.join('.'))
81
+ arr.each do |k1, v1|
82
+ yield k1, v1
83
+ end
84
+ end
85
+ else
86
+ yield key, value
87
+ end
88
+ end
43
89
  end
44
90
  end
@@ -30,6 +30,25 @@ module Spotlight
30
30
  current_site.title if current_site.title.present?
31
31
  end
32
32
 
33
+ # Returns the url for the current page in the new locale. This may be
34
+ # overridden in downstream applications where our naive use of `url_for`
35
+ # is insufficient to generate the expected routes
36
+ def current_page_for_locale(locale)
37
+ initial_exception = nil
38
+
39
+ ([self] + additional_locale_routing_scopes).each do |scope|
40
+ return scope.public_send(:url_for, params.to_unsafe_h.merge(locale: locale))
41
+ rescue ActionController::UrlGenerationError => e
42
+ initial_exception ||= e
43
+ end
44
+
45
+ raise initial_exception
46
+ end
47
+
48
+ def additional_locale_routing_scopes
49
+ [spotlight, main_app]
50
+ end
51
+
33
52
  # Can search for named routes directly in the main app, omitting
34
53
  # the "main_app." prefix
35
54
  def method_missing(method, *args, &block)
@@ -132,7 +151,7 @@ module Spotlight
132
151
 
133
152
  def uploaded_field_label(config)
134
153
  solr_field = Array(config.solr_field || config.field_name).first.to_s
135
- blacklight_config.index_fields[solr_field].try(:label) || config.label || t(".#{solr_field}")
154
+ blacklight_config.index_fields[solr_field]&.label || config.label || t(".#{solr_field}")
136
155
  end
137
156
 
138
157
  def available_view_fields
@@ -25,7 +25,10 @@ module Spotlight
25
25
  end
26
26
 
27
27
  def iiif_upload_tag(f)
28
- f.file_field_without_bootstrap :file, name: 'featured_image[image]', data: { endpoint: polymorphic_path(f.object.model_name.route_key) }
28
+ content_tag(:div) do
29
+ concat f.file_field_without_bootstrap :file, name: 'featured_image[image]', data: { endpoint: polymorphic_path(f.object.model_name.route_key) }
30
+ concat f.hidden_field :upload_id
31
+ end
29
32
  end
30
33
 
31
34
  def form_prefix(f)
@@ -112,7 +112,7 @@ module Spotlight
112
112
  defaults << :"helpers.action.#{object_name}.#{key}"
113
113
  defaults << :"helpers.action.#{key}"
114
114
  defaults << "#{key.to_s.humanize} #{model}"
115
- I18n.t(defaults.shift, model: model, default: defaults)
115
+ I18n.t(defaults.shift, model: model.downcase, default: defaults)
116
116
  end
117
117
  # rubocop:enable Metrics/MethodLength
118
118
  end
@@ -24,7 +24,7 @@ module Spotlight
24
24
  end
25
25
 
26
26
  def link_back_to_catalog(opts = { label: nil })
27
- opts[:route_set] ||= spotlight if (current_search_session.try(:query_params) || {}).fetch(:controller, '').starts_with? 'spotlight'
27
+ opts[:route_set] ||= spotlight if (current_search_session&.query_params || {}).fetch(:controller, '').starts_with? 'spotlight'
28
28
  super
29
29
  end
30
30
 
@@ -21,7 +21,7 @@ module Spotlight
21
21
  # a more complete markdown rendered
22
22
  def sir_trevor_markdown(text)
23
23
  clean_text = if text
24
- text.gsub('<br>', "\n").gsub('<p>', '').gsub('</p>', "\n\n")
24
+ text.gsub('<br>', "\n\n").gsub('<p>', '').gsub('</p>', "\n\n")
25
25
  else
26
26
  ''
27
27
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ # Job status tracking
5
+ module JobTracking
6
+ extend ActiveSupport::Concern
7
+ include ActiveJob::Status
8
+
9
+ def self.with_job_tracking
10
+ before_perform :find_or_initialize_job_tracker
11
+ after_perform :finalize_job_tracker
12
+ end
13
+
14
+ def job_tracker
15
+ @job_tracker ||= find_or_initialize_job_tracker
16
+ end
17
+
18
+ private
19
+
20
+ def find_or_initialize_job_tracker
21
+ JobTracker.find_or_create_by(job_id: job_id) do |tracker|
22
+ tracker.job_class = self.class.name
23
+ tracker.status = 'enqueued'
24
+ update_job_tracker_properties(tracker)
25
+ end
26
+ end
27
+
28
+ def finalize_job_tracker
29
+ job_tracker.update(status: 'completed') if job_tracker.status == 'enqueued'
30
+ end
31
+
32
+ def update_job_tracker_properties(tracker)
33
+ tracker.resource = job_tracking_resource
34
+ tracker.on = reports_on_resource || tracker.resource
35
+
36
+ tracker.user = arguments.last[:user] if arguments.last.is_a?(Hash)
37
+ end
38
+
39
+ def job_tracking_resource
40
+ arguments.first
41
+ end
42
+
43
+ def reports_on_resource
44
+ arguments.last[:reports_on] if arguments.last.is_a?(Hash)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ # Job status tracking
5
+ module LimitConcurrency
6
+ extend ActiveSupport::Concern
7
+
8
+ VALIDITY_TOKEN_PARAMETER = 'validity_token'
9
+
10
+ included do
11
+ # The validity checker is a seam for implementations to expire unnecessary
12
+ # indexing tasks if it becomes redundant while waiting in the job queue.
13
+ class_attribute :validity_checker, default: Spotlight::ValidityChecker.new
14
+
15
+ before_enqueue do |job|
16
+ token = job.arguments.last[VALIDITY_TOKEN_PARAMETER] if job.arguments.last.is_a?(Hash)
17
+ token ||= validity_checker.mint(job)
18
+
19
+ job.arguments << {} unless job.arguments.last.is_a? Hash
20
+ job.arguments.last[VALIDITY_TOKEN_PARAMETER] = token
21
+ end
22
+
23
+ before_perform do |job|
24
+ next unless job.arguments.last.is_a?(Hash)
25
+
26
+ token = job.arguments.last.delete(VALIDITY_TOKEN_PARAMETER)
27
+ throw(:abort) unless token.nil? || validity_checker.check(job, validity_token: token)
28
+
29
+ job.arguments.pop if job.arguments.last.empty?
30
+ end
31
+ end
32
+ end
33
+ end
@@ -3,15 +3,40 @@
3
3
  module Spotlight
4
4
  ##
5
5
  # Process a CSV upload into new Spotlight::Resource::Upload objects
6
- class AddUploadsFromCSV < ActiveJob::Base
7
- queue_as :default
6
+ class AddUploadsFromCsv < Spotlight::ApplicationJob
7
+ include Spotlight::JobTracking
8
+ attr_reader :count
9
+ attr_reader :errors
8
10
 
9
11
  after_perform do |job|
10
12
  csv_data, exhibit, user = job.arguments
11
- Spotlight::IndexingCompleteMailer.documents_indexed(csv_data, exhibit, user).deliver_now
13
+ Spotlight::IndexingCompleteMailer.documents_indexed(
14
+ csv_data,
15
+ exhibit,
16
+ user,
17
+ indexed_count: job.count,
18
+ errors: job.errors
19
+ ).deliver_now
12
20
  end
13
21
 
14
22
  def perform(csv_data, exhibit, _user)
23
+ @count = 0
24
+ @errors = {}
25
+
26
+ resources(csv_data, exhibit).each_with_index do |resource, index|
27
+ if resource.save_and_index
28
+ @count += 1
29
+ else
30
+ @errors[index + 1] = resource.errors.full_messages + resource.upload&.errors&.full_messages
31
+ end
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def resources(csv_data, exhibit)
38
+ return to_enum(:resources, csv_data, exhibit) unless block_given?
39
+
15
40
  encoded_csv(csv_data).each do |row|
16
41
  url = row.delete('url')
17
42
  next unless url.present?
@@ -21,12 +46,11 @@ module Spotlight
21
46
  exhibit: exhibit
22
47
  )
23
48
  resource.build_upload(remote_image_url: url) unless url == '~'
24
- resource.save_and_index
49
+
50
+ yield resource
25
51
  end
26
52
  end
27
53
 
28
- private
29
-
30
54
  def encoded_csv(csv)
31
55
  csv.map do |row|
32
56
  row.map do |label, column|
@@ -34,5 +58,9 @@ module Spotlight
34
58
  end.compact.to_h
35
59
  end.compact
36
60
  end
61
+
62
+ def job_tracking_resource
63
+ arguments[1]
64
+ end
37
65
  end
38
66
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spotlight
4
+ # :nodoc:
5
+ class ApplicationJob < ActiveJob::Base
6
+ queue_as :default
7
+ end
8
+ end
@@ -0,0 +1,13 @@
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 CleanupJobTrackersJob < Spotlight::ApplicationJob
9
+ def perform
10
+ Spotlight::JobTracker.where(status: 'completed', updated_at: Time.zone.at(0)...Spotlight::Engine.config.reindex_progress_window.minutes.ago).delete_all
11
+ end
12
+ end
13
+ end
@@ -5,9 +5,7 @@ module Spotlight
5
5
  # Calls the #set_default_thumbnail method
6
6
  # on the object passed in and calls save
7
7
  ###
8
- class DefaultThumbnailJob < ActiveJob::Base
9
- queue_as :default
10
-
8
+ class DefaultThumbnailJob < Spotlight::ApplicationJob
11
9
  def perform(thumbnailable)
12
10
  thumbnailable.set_default_thumbnail
13
11
  thumbnailable.save