blacklight-spotlight 3.0.0.alpha.6 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/assets/javascripts/spotlight/admin/blocks/browse_block.js +55 -1
  4. data/app/assets/javascripts/spotlight/admin/blocks/uploaded_items_block.js +7 -2
  5. data/app/assets/javascripts/spotlight/admin/crop.es6 +11 -0
  6. data/app/assets/javascripts/spotlight/admin/sir-trevor/block_controls.js +21 -12
  7. data/app/assets/javascripts/spotlight/admin/sir-trevor/locales.js +3 -2
  8. data/app/assets/stylesheets/spotlight/_accessibility.scss +8 -0
  9. data/app/assets/stylesheets/spotlight/_browse.scss +16 -0
  10. data/app/assets/stylesheets/spotlight/_curation.scss +9 -16
  11. data/app/assets/stylesheets/spotlight/_featured_browse_categories_block.scss +7 -4
  12. data/app/assets/stylesheets/spotlight/_header.scss +1 -1
  13. data/app/assets/stylesheets/spotlight/_item_text_block.scss +6 -0
  14. data/app/assets/stylesheets/spotlight/_nestable.scss +4 -0
  15. data/app/assets/stylesheets/spotlight/_pages.scss +3 -1
  16. data/app/assets/stylesheets/spotlight/_report_a_problem.scss +5 -2
  17. data/app/assets/stylesheets/spotlight/_spotlight.scss +1 -0
  18. data/app/assets/stylesheets/spotlight/_translations.scss +1 -0
  19. data/app/controllers/concerns/spotlight/base.rb +8 -0
  20. data/app/controllers/spotlight/admin_users_controller.rb +4 -1
  21. data/app/controllers/spotlight/appearances_controller.rb +1 -0
  22. data/app/controllers/spotlight/browse_controller.rb +1 -1
  23. data/app/controllers/spotlight/catalog_controller.rb +2 -2
  24. data/app/controllers/spotlight/exhibits_controller.rb +4 -3
  25. data/app/controllers/spotlight/featured_images_controller.rb +1 -1
  26. data/app/controllers/spotlight/pages_controller.rb +1 -5
  27. data/app/controllers/spotlight/resources/csv_upload_controller.rb +1 -1
  28. data/app/controllers/spotlight/searches_controller.rb +3 -2
  29. data/app/controllers/spotlight/sites_controller.rb +8 -2
  30. data/app/controllers/spotlight/translations_controller.rb +46 -0
  31. data/app/helpers/spotlight/crop_helper.rb +4 -1
  32. data/app/helpers/spotlight/title_helper.rb +12 -2
  33. data/app/jobs/spotlight/add_uploads_from_csv.rb +30 -5
  34. data/app/mailers/spotlight/indexing_complete_mailer.rb +3 -2
  35. data/app/models/concerns/spotlight/translatables.rb +17 -1
  36. data/app/models/spotlight/about_page.rb +3 -1
  37. data/app/models/spotlight/contact.rb +1 -1
  38. data/app/models/spotlight/custom_field.rb +3 -3
  39. data/app/models/spotlight/exhibit.rb +4 -2
  40. data/app/models/spotlight/feature_page.rb +3 -1
  41. data/app/models/spotlight/featured_image.rb +29 -12
  42. data/app/models/spotlight/home_page.rb +3 -1
  43. data/app/models/spotlight/main_navigation.rb +2 -2
  44. data/app/models/spotlight/masthead.rb +1 -1
  45. data/app/models/spotlight/page.rb +7 -3
  46. data/app/models/spotlight/page_configurations.rb +1 -0
  47. data/app/models/spotlight/page_content.rb +2 -0
  48. data/app/models/spotlight/resources/csv_upload.rb +2 -1
  49. data/app/models/spotlight/resources/iiif_manifest.rb +2 -0
  50. data/app/models/spotlight/resources/upload.rb +1 -1
  51. data/app/models/spotlight/search.rb +5 -1
  52. data/app/models/spotlight/solr_document_sidecar.rb +7 -5
  53. data/app/models/spotlight/temporary_image.rb +8 -0
  54. data/app/services/spotlight/exhibit_import_export_service.rb +454 -0
  55. data/app/services/spotlight/solr_document_builder.rb +1 -0
  56. data/app/values/custom_field_name.rb +1 -0
  57. data/app/views/catalog/_save_search.html.erb +1 -1
  58. data/app/views/layouts/spotlight/spotlight.html.erb +1 -1
  59. data/app/views/shared/_site_sidebar.html.erb +1 -1
  60. data/app/views/spotlight/about_pages/_contact.html.erb +15 -17
  61. data/app/views/spotlight/admin_users/index.html.erb +1 -1
  62. data/app/views/spotlight/appearances/edit.html.erb +1 -23
  63. data/app/views/spotlight/browse/_search.html.erb +3 -2
  64. data/app/views/spotlight/browse/_search_title.html.erb +2 -1
  65. data/app/views/spotlight/exhibits/new.html.erb +1 -1
  66. data/app/views/spotlight/feature_pages/_sidebar.html.erb +9 -5
  67. data/app/views/spotlight/indexing_complete_mailer/documents_indexed.html.erb +9 -0
  68. data/app/views/spotlight/pages/_form.html.erb +2 -2
  69. data/app/views/spotlight/pages/_page.html.erb +19 -35
  70. data/app/views/spotlight/search_configurations/_facets.html.erb +15 -34
  71. data/app/views/spotlight/search_configurations/_search_fields.html.erb +4 -19
  72. data/app/views/spotlight/search_configurations/_sort.html.erb +8 -22
  73. data/app/views/spotlight/searches/_form.html.erb +1 -0
  74. data/app/views/spotlight/searches/_search.html.erb +31 -29
  75. data/app/views/spotlight/shared/_dd3_item.html.erb +56 -0
  76. data/app/views/spotlight/shared/_honeypot_field.html.erb +4 -0
  77. data/app/views/spotlight/shared/_report_a_problem.html.erb +7 -10
  78. data/app/views/spotlight/sir_trevor/blocks/_browse_block.html.erb +1 -0
  79. data/app/views/spotlight/sir_trevor/blocks/_uploaded_items_block.html.erb +7 -1
  80. data/app/views/spotlight/sites/edit.html.erb +1 -1
  81. data/app/views/spotlight/sites/edit_exhibits.html.erb +1 -1
  82. data/app/views/spotlight/translations/_browse_categories.html.erb +29 -3
  83. data/app/views/spotlight/translations/_general.html.erb +7 -7
  84. data/app/views/spotlight/translations/_import.html.erb +24 -0
  85. data/app/views/spotlight/translations/_metadata.html.erb +1 -1
  86. data/app/views/spotlight/translations/_page.html.erb +5 -5
  87. data/app/views/spotlight/translations/_pages.html.erb +4 -4
  88. data/app/views/spotlight/translations/_pages_table.html.erb +5 -5
  89. data/app/views/spotlight/translations/_search_fields.html.erb +3 -3
  90. data/app/views/spotlight/translations/edit.html.erb +8 -6
  91. data/app/views/spotlight/translations/show.yaml.yamlbuilder +81 -0
  92. data/config/i18n-tasks.yml +2 -0
  93. data/config/locales/spotlight.ar.yml +47 -24
  94. data/config/locales/spotlight.en.yml +82 -67
  95. data/config/routes.rb +6 -1
  96. data/db/migrate/20200403161512_add_subtitle_to_searches.rb +7 -0
  97. data/lib/generators/spotlight/install_generator.rb +22 -1
  98. data/lib/generators/spotlight/templates/config/initializers/sir_trevor_rails.rb +10 -0
  99. data/lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb +2 -0
  100. data/lib/spotlight/engine.rb +26 -0
  101. data/lib/spotlight/upload_field_config.rb +1 -0
  102. data/lib/spotlight/version.rb +1 -1
  103. data/spec/controllers/spotlight/browse_controller_spec.rb +1 -1
  104. data/spec/controllers/spotlight/home_pages_controller_spec.rb +1 -1
  105. data/spec/controllers/spotlight/resources/csv_upload_controller_spec.rb +4 -4
  106. data/spec/controllers/spotlight/resources/upload_controller_spec.rb +2 -2
  107. data/spec/controllers/spotlight/translations_controller_spec.rb +53 -2
  108. data/spec/examples.txt +1410 -1389
  109. data/spec/factories/featured_images.rb +4 -0
  110. data/spec/features/add_contacts_spec.rb +1 -1
  111. data/spec/features/browse_category_admin_spec.rb +2 -2
  112. data/spec/features/create_exhibit_spec.rb +6 -6
  113. data/spec/features/dashboard_spec.rb +5 -5
  114. data/spec/features/exhibits/administration_spec.rb +3 -3
  115. data/spec/features/exhibits/language_create_edit_spec.rb +3 -3
  116. data/spec/features/exhibits/translation_editing_spec.rb +2 -2
  117. data/spec/features/home_page_spec.rb +9 -0
  118. data/spec/features/javascript/block_controls_spec.rb +2 -0
  119. data/spec/features/javascript/blocks/uploaded_items_block_spec.rb +4 -1
  120. data/spec/features/report_a_problem_spec.rb +5 -4
  121. data/spec/helpers/spotlight/pages_helper_spec.rb +2 -2
  122. data/spec/helpers/spotlight/title_helper_spec.rb +13 -0
  123. data/spec/i18n_spec.rb +0 -2
  124. data/spec/jobs/spotlight/add_uploads_from_csv_spec.rb +13 -1
  125. data/spec/mailers/spotlight/indexing_complete_mailer_spec.rb +11 -1
  126. data/spec/models/solr_document_spec.rb +2 -3
  127. data/spec/models/spotlight/access_controls_enforcement_search_builder_spec.rb +1 -0
  128. data/spec/models/spotlight/exhibit_spec.rb +9 -1
  129. data/spec/models/spotlight/feature_page_spec.rb +0 -5
  130. data/spec/models/spotlight/featured_image_spec.rb +27 -0
  131. data/spec/models/spotlight/page_spec.rb +6 -1
  132. data/spec/models/spotlight/resources/upload_spec.rb +43 -79
  133. data/spec/models/spotlight/role_spec.rb +2 -2
  134. data/spec/{serializers/spotlight/exhibit_export_serializer_spec.rb → services/spotlight/exhibit_import_export_service_spec.rb} +120 -22
  135. data/spec/services/spotlight/iiif_resource_resolver_spec.rb +1 -1
  136. data/spec/test_app_templates/Gemfile.extra +0 -3
  137. data/spec/views/spotlight/feature_pages/_sidebar.html.erb_spec.rb +1 -0
  138. data/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb +3 -3
  139. data/spec/views/spotlight/search_configurations/_search_fields.html.erb_spec.rb +1 -1
  140. data/spec/views/spotlight/search_configurations/_sort.html.erb_spec.rb +9 -10
  141. data/spec/views/spotlight/translations/_import.html.erb_spec.rb +24 -0
  142. data/vendor/assets/javascripts/leaflet-iiif.js +46 -21
  143. metadata +69 -34
  144. data/app/serializers/spotlight/exhibit_export_serializer.rb +0 -205
  145. data/app/serializers/spotlight/featured_image_representer.rb +0 -29
  146. data/app/serializers/spotlight/main_navigation_representer.rb +0 -13
  147. data/app/serializers/spotlight/page_representer.rb +0 -33
@@ -10,7 +10,10 @@ module Spotlight
10
10
 
11
11
  load_and_authorize_resource :site, class: 'Spotlight::Site'
12
12
 
13
- def index; end
13
+ def index
14
+ add_breadcrumb t(:'spotlight.sites.home'), root_url
15
+ add_breadcrumb t(:'spotlight.admin_users.index.page_title')
16
+ end
14
17
 
15
18
  def create
16
19
  if update_roles
@@ -40,6 +40,7 @@ module Spotlight
40
40
  source
41
41
  image
42
42
  document_global_id
43
+ upload_id
43
44
  ]
44
45
  end
45
46
  end
@@ -69,7 +69,7 @@ module Spotlight
69
69
  end
70
70
 
71
71
  def attach_search_breadcrumb
72
- add_breadcrumb @search.title, exhibit_browse_path(@exhibit, @search)
72
+ add_breadcrumb @search.full_title, exhibit_browse_path(@exhibit, @search)
73
73
  end
74
74
 
75
75
  def _prefixes
@@ -209,9 +209,9 @@ module Spotlight
209
209
  if current_browse_category
210
210
  add_breadcrumb current_browse_category.exhibit.main_navigations.browse.label_or_default, exhibit_browse_index_path(current_browse_category.exhibit)
211
211
  add_breadcrumb current_browse_category.title, exhibit_browse_path(current_browse_category.exhibit, current_browse_category)
212
- elsif current_page_context && current_page_context.title.present? && !current_page_context.is_a?(Spotlight::HomePage)
212
+ elsif current_page_context&.title&.present? && !current_page_context.is_a?(Spotlight::HomePage)
213
213
  add_breadcrumb current_page_context.title, [current_page_context.exhibit, current_page_context]
214
- elsif current_search_session
214
+ elsif current_search_session && !current_page_context&.is_a?(Spotlight::HomePage)
215
215
  add_breadcrumb t(:'spotlight.catalog.breadcrumb.index'), search_action_url(current_search_session.query_params)
216
216
  end
217
217
 
@@ -22,11 +22,12 @@ module Spotlight
22
22
 
23
23
  def new
24
24
  build_initial_exhibit_contact_emails
25
+ add_breadcrumb t(:'spotlight.sites.home'), root_url
26
+ add_breadcrumb t(:'spotlight.exhibits.new.page_title')
25
27
  end
26
28
 
27
29
  def process_import
28
- @exhibit.import(JSON.parse(import_exhibit_params.read))
29
- if @exhibit.save && @exhibit.reindex_later
30
+ if @exhibit.import(JSON.parse(import_exhibit_params.read)) && @exhibit.reindex_later
30
31
  redirect_to spotlight.exhibit_dashboard_path(@exhibit), notice: t(:'helpers.submit.exhibit.updated', model: @exhibit.class.model_name.human.downcase)
31
32
  else
32
33
  render action: :import
@@ -48,7 +49,7 @@ module Spotlight
48
49
  respond_to do |format|
49
50
  format.json do
50
51
  authorize! :export, @exhibit
51
- send_data JSON.pretty_generate(Spotlight::ExhibitExportSerializer.new(@exhibit).as_json),
52
+ send_data JSON.pretty_generate(Spotlight::ExhibitImportExportService.new(@exhibit).as_json),
52
53
  type: 'application/json',
53
54
  disposition: 'attachment',
54
55
  filename: "#{@exhibit.friendly_id}-export.json"
@@ -3,7 +3,7 @@
3
3
  module Spotlight
4
4
  # Handles requests to upload images for exhibit thumbnails
5
5
  class FeaturedImagesController < Spotlight::ApplicationController
6
- load_and_authorize_resource instance_name: :featured_image
6
+ load_and_authorize_resource instance_name: :featured_image, class: 'Spotlight::TemporaryImage'
7
7
 
8
8
  def create
9
9
  if @featured_image.save && @featured_image.file_present?
@@ -19,10 +19,6 @@ 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.track_search_session = false
24
- end
25
-
26
22
  # GET /exhibits/1/pages
27
23
  def index
28
24
  # set up a model the inline "add a new page" form
@@ -74,7 +70,7 @@ module Spotlight
74
70
  @page.lock&.delete
75
71
 
76
72
  if @page.update(page_params.merge(last_edited_by: current_user))
77
- redirect_to [spotlight, @page.exhibit, @page], flash: { html_safe: true }, notice: undo_notice(:updated)
73
+ redirect_to [spotlight, @page.exhibit, @page, format: params.permit(:format)], flash: { html_safe: true }, notice: undo_notice(:updated)
78
74
  else
79
75
  render action: 'edit'
80
76
  end
@@ -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
@@ -31,7 +31,7 @@ module Spotlight
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,7 @@ module Spotlight
50
50
  end
51
51
 
52
52
  def edit
53
- add_breadcrumb @search.title, edit_exhibit_search_path(@search.exhibit, @search)
53
+ add_breadcrumb @search.full_title, edit_exhibit_search_path(@search.exhibit, @search)
54
54
  @exhibit = @search.exhibit
55
55
  end
56
56
 
@@ -105,6 +105,7 @@ module Spotlight
105
105
  def search_params
106
106
  params.require(:search).permit(
107
107
  :title,
108
+ :subtitle,
108
109
  :long_description,
109
110
  :search_box,
110
111
  :default_index_view_type,
@@ -8,9 +8,15 @@ module Spotlight
8
8
  before_action :load_site
9
9
  load_and_authorize_resource
10
10
 
11
- def edit; end
11
+ def edit
12
+ add_breadcrumb t(:'spotlight.sites.home'), root_url
13
+ add_breadcrumb t(:'spotlight.sites.edit.page_title')
14
+ end
12
15
 
13
- def edit_exhibits; end
16
+ def edit_exhibits
17
+ add_breadcrumb t(:'spotlight.sites.home'), root_url
18
+ add_breadcrumb t(:'spotlight.sites.edit_exhibits.page_title')
19
+ end
14
20
 
15
21
  def update
16
22
  if @site.update(site_params)
@@ -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
@@ -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)
@@ -13,8 +13,18 @@ module Spotlight
13
13
  end
14
14
 
15
15
  def page_title(section, title = nil)
16
- set_html_page_title(t(:'spotlight.html_admin_title', section: section, title: title || t(:'.title', default: :'.header')))
17
- content_tag(:h1, safe_join([section, content_tag(:small, title || t(:'.header'))], "\n"), class: 'page-header')
16
+ title ||= t(:'.header', default: '').presence
17
+
18
+ head_content = t(:'spotlight.html_admin_title', section: section, title: title) if section && title
19
+ head_content ||= section || title
20
+ set_html_page_title(head_content)
21
+
22
+ html_content = safe_join([
23
+ (section if section.present?),
24
+ (content_tag(:small, title) if title.present?)
25
+ ].compact, "\n")
26
+
27
+ content_tag(:h1, html_content, class: 'page-header')
18
28
  end
19
29
 
20
30
  # rubocop:disable Naming/AccessorMethodName
@@ -3,15 +3,41 @@
3
3
  module Spotlight
4
4
  ##
5
5
  # Process a CSV upload into new Spotlight::Resource::Upload objects
6
- class AddUploadsFromCSV < ActiveJob::Base
6
+ class AddUploadsFromCsv < ActiveJob::Base
7
+ attr_reader :count
8
+ attr_reader :errors
9
+
7
10
  queue_as :default
8
11
 
9
12
  after_perform do |job|
10
13
  csv_data, exhibit, user = job.arguments
11
- Spotlight::IndexingCompleteMailer.documents_indexed(csv_data, exhibit, user).deliver_now
14
+ Spotlight::IndexingCompleteMailer.documents_indexed(
15
+ csv_data,
16
+ exhibit,
17
+ user,
18
+ indexed_count: job.count,
19
+ errors: job.errors
20
+ ).deliver_now
12
21
  end
13
22
 
14
23
  def perform(csv_data, exhibit, _user)
24
+ @count = 0
25
+ @errors = {}
26
+
27
+ resources(csv_data, exhibit).each_with_index do |resource, index|
28
+ if resource.save_and_index
29
+ @count += 1
30
+ else
31
+ @errors[index + 1] = resource.errors.full_messages + resource.upload&.errors&.full_messages
32
+ end
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def resources(csv_data, exhibit)
39
+ return to_enum(:resources, csv_data, exhibit) unless block_given?
40
+
15
41
  encoded_csv(csv_data).each do |row|
16
42
  url = row.delete('url')
17
43
  next unless url.present?
@@ -21,12 +47,11 @@ module Spotlight
21
47
  exhibit: exhibit
22
48
  )
23
49
  resource.build_upload(remote_image_url: url) unless url == '~'
24
- resource.save_and_index
50
+
51
+ yield resource
25
52
  end
26
53
  end
27
54
 
28
- private
29
-
30
55
  def encoded_csv(csv)
31
56
  csv.map do |row|
32
57
  row.map do |label, column|
@@ -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
@@ -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
@@ -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
@@ -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
@@ -100,8 +100,10 @@ module Spotlight
100
100
  end
101
101
 
102
102
  def import(hash)
103
- Spotlight::ExhibitExportSerializer.prepare(self).from_hash(hash)
104
- self
103
+ ActiveRecord::Base.transaction do
104
+ Spotlight::ExhibitImportExportService.new(self).from_hash!(hash)
105
+ save
106
+ end
105
107
  end
106
108
 
107
109
  def solr_data
@@ -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.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