blacklight-spotlight 3.0.0.rc4 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/images/blacklight/close.svg +1 -0
- data/app/assets/images/blacklight/zoom_in.svg +1 -0
- data/app/assets/images/blacklight/zoom_out.svg +1 -0
- data/app/assets/javascripts/spotlight/admin/blocks/uploaded_items_block.js +8 -1
- data/app/assets/javascripts/spotlight/admin/catalog_edit.js +13 -47
- data/app/assets/javascripts/spotlight/admin/exhibit_tag_autocomplete.js +37 -0
- data/app/assets/javascripts/spotlight/admin/{reindex_monitor.js → progress_monitor.js} +25 -4
- data/app/assets/javascripts/spotlight/admin/sir-trevor/locales.js +1 -1
- data/app/assets/javascripts/spotlight/user/zpr_links.js.erb +29 -14
- data/app/assets/stylesheets/spotlight/_browse.scss +8 -0
- data/app/assets/stylesheets/spotlight/_catalog.scss +30 -4
- data/app/assets/stylesheets/spotlight/_exhibit_admin.scss +9 -0
- data/app/assets/stylesheets/spotlight/_modals.scss +3 -0
- data/app/assets/stylesheets/spotlight/_nestable.scss +8 -0
- data/app/assets/stylesheets/spotlight/_spotlight.scss +2 -0
- data/app/assets/stylesheets/spotlight/_view_larger.scss +22 -0
- data/app/assets/stylesheets/spotlight/typeahead.css +23 -23
- data/app/builders/spotlight/bootstrap_breadcrumbs_builder.rb +4 -2
- data/app/controllers/concerns/spotlight/base.rb +1 -1
- data/app/controllers/concerns/spotlight/catalog.rb +7 -1
- data/app/controllers/spotlight/browse_controller.rb +9 -15
- data/app/controllers/spotlight/bulk_actions_controller.rb +62 -0
- data/app/controllers/spotlight/bulk_updates_controller.rb +67 -0
- data/app/controllers/spotlight/catalog_controller.rb +12 -12
- data/app/controllers/spotlight/dashboards_controller.rb +5 -4
- data/app/controllers/spotlight/featured_images_controller.rb +1 -1
- data/app/controllers/spotlight/job_trackers_controller.rb +17 -0
- data/app/controllers/spotlight/pages_controller.rb +6 -7
- data/app/controllers/spotlight/tags_controller.rb +39 -5
- data/app/helpers/spotlight/application_helper.rb +1 -1
- data/app/helpers/spotlight/job_trackers_helper.rb +31 -0
- data/app/helpers/spotlight/main_app_helpers.rb +3 -4
- data/app/helpers/spotlight/meta_helper.rb +2 -2
- data/app/helpers/spotlight/pages_helper.rb +0 -7
- data/app/helpers/spotlight/roles_helper.rb +1 -1
- data/app/helpers/spotlight/searches_helper.rb +1 -1
- data/app/jobs/concerns/spotlight/gather_documents.rb +35 -0
- data/app/jobs/concerns/spotlight/job_tracking.rb +40 -23
- data/app/jobs/spotlight/add_tags_job.rb +31 -0
- data/app/jobs/spotlight/add_uploads_from_csv.rb +2 -4
- data/app/jobs/spotlight/change_visibility_job.rb +33 -0
- data/app/jobs/spotlight/process_bulk_updates_csv_job.rb +82 -0
- data/app/jobs/spotlight/reindex_exhibit_job.rb +5 -2
- data/app/jobs/spotlight/reindex_job.rb +35 -23
- data/app/jobs/spotlight/remove_tags_job.rb +31 -0
- data/app/jobs/spotlight/rename_sidecar_field_job.rb +1 -0
- data/app/jobs/spotlight/rename_tags_job.rb +33 -0
- data/app/models/concerns/spotlight/browse_category_search_builder.rb +59 -0
- data/app/models/concerns/spotlight/exhibit_analytics.rb +2 -6
- data/app/models/concerns/spotlight/exhibit_documents.rb +2 -2
- data/app/models/concerns/spotlight/resources/web.rb +1 -1
- data/app/models/concerns/spotlight/search_builder.rb +11 -0
- data/app/models/concerns/spotlight/solr_document.rb +1 -1
- data/app/models/concerns/spotlight/solr_document/atomic_updates.rb +2 -2
- data/app/models/concerns/spotlight/user.rb +5 -1
- data/app/models/sir_trevor_rails/blocks/browse_block.rb +1 -1
- data/app/models/sir_trevor_rails/blocks/featured_pages_block.rb +1 -1
- data/app/models/sir_trevor_rails/blocks/solr_documents_block.rb +9 -0
- data/app/models/sir_trevor_rails/blocks/uploaded_items_block.rb +4 -0
- data/app/models/spotlight/ability.rb +6 -2
- data/app/models/spotlight/attachment.rb +1 -1
- data/app/models/spotlight/{reindex_progress.rb → background_job_progress.rb} +8 -7
- data/app/models/spotlight/blacklight_configuration.rb +26 -6
- data/app/models/spotlight/bulk_update.rb +8 -0
- data/app/models/spotlight/exhibit.rb +2 -1
- data/app/models/spotlight/feature_page.rb +0 -2
- data/app/models/spotlight/featured_image.rb +40 -1
- data/app/models/spotlight/field_metadata.rb +4 -8
- data/app/models/spotlight/job_tracker.rb +11 -2
- data/app/models/spotlight/page.rb +1 -3
- data/app/models/spotlight/page_configurations.rb +10 -9
- data/app/models/spotlight/resource.rb +4 -4
- data/app/models/spotlight/resources/iiif_harvester.rb +2 -2
- data/app/models/spotlight/resources/iiif_service.rb +8 -1
- data/app/models/spotlight/resources/upload.rb +2 -2
- data/app/models/spotlight/role.rb +1 -2
- data/app/presenters/spotlight/iiif_manifest_presenter.rb +2 -2
- data/app/services/spotlight/bulk_updates_csv_template_service.rb +93 -0
- data/app/services/spotlight/etl/executor.rb +1 -3
- data/app/services/spotlight/iiif_resource_resolver.rb +1 -1
- data/app/uploaders/spotlight/bulk_updates_uploader.rb +7 -0
- data/app/uploaders/spotlight/featured_image_uploader.rb +1 -1
- data/app/views/catalog/_add_tags.html.erb +28 -0
- data/app/views/catalog/_bulk_actions.html.erb +12 -0
- data/app/views/catalog/_change_visibility.html.erb +35 -0
- data/app/views/catalog/_curator_actions.html.erb +3 -0
- data/app/views/catalog/_remove_tags.html.erb +37 -0
- data/app/views/catalog/_save_search.html.erb +1 -1
- data/app/views/spotlight/about_pages/_sidebar.html.erb +2 -2
- data/app/views/spotlight/browse/_search.html.erb +3 -3
- data/app/views/spotlight/browse/_search_box.html.erb +9 -9
- data/app/views/spotlight/browse/_search_title.html.erb +1 -1
- data/app/views/spotlight/bulk_updates/_download.html.erb +23 -0
- data/app/views/spotlight/bulk_updates/_overview.html.erb +1 -0
- data/app/views/spotlight/bulk_updates/_progress_panel.html.erb +19 -0
- data/app/views/spotlight/bulk_updates/_upload.html.erb +12 -0
- data/app/views/spotlight/bulk_updates/edit.html.erb +37 -0
- data/app/views/spotlight/catalog/_admin_header.html.erb +1 -1
- data/app/views/spotlight/catalog/_admin_index_header_default.html.erb +1 -1
- data/app/views/spotlight/catalog/_admin_thumbnail_default.html.erb +3 -2
- data/app/views/spotlight/catalog/_edit_default.html.erb +2 -2
- data/app/views/spotlight/catalog/_reindex_progress_panel.html.erb +1 -1
- data/app/views/spotlight/catalog/index.iiif_json.jbuilder +1 -1
- data/app/views/spotlight/custom_fields/_form.html.erb +1 -1
- data/app/views/spotlight/custom_search_fields/_form.html.erb +1 -1
- data/app/views/spotlight/dashboards/_reindexing_activity.html.erb +1 -1
- data/app/views/spotlight/exhibits/_exhibit_card.html.erb +1 -1
- data/app/views/spotlight/feature_pages/_sidebar.html.erb +1 -1
- data/app/views/spotlight/featured_images/_form.html.erb +1 -1
- data/app/views/spotlight/job_trackers/show.html.erb +79 -0
- data/app/views/spotlight/metadata_configurations/_metadata_field.html.erb +2 -2
- data/app/views/spotlight/pages/_form.html.erb +2 -2
- data/app/views/spotlight/pages/_order_pages.html.erb +2 -2
- data/app/views/spotlight/pages/_view_type_group.html.erb +3 -3
- data/app/views/spotlight/pages/show.html.erb +1 -1
- data/app/views/spotlight/resources/_form.html.erb +1 -1
- data/app/views/spotlight/resources/csv_upload/_form.html.erb +1 -1
- data/app/views/spotlight/resources/iiif/_form.html.erb +1 -1
- data/app/views/spotlight/resources/json_upload/_form.html.erb +2 -2
- data/app/views/spotlight/resources/upload/_form.html.erb +1 -1
- data/app/views/spotlight/search_configurations/_document_index_view_types.html.erb +2 -2
- data/app/views/spotlight/searches/_form.html.erb +2 -2
- data/app/views/spotlight/shared/_curation_sidebar.html.erb +3 -0
- data/app/views/spotlight/sir_trevor/blocks/_browse_group_categories_block.html.erb +3 -3
- data/app/views/spotlight/sir_trevor/blocks/_search_results_block.html.erb +1 -1
- data/app/views/spotlight/sir_trevor/blocks/_solr_documents_block.html.erb +8 -8
- data/app/views/spotlight/sir_trevor/blocks/_solr_documents_carousel_block.html.erb +7 -7
- data/app/views/spotlight/sir_trevor/blocks/_solr_documents_features_block.html.erb +9 -7
- data/app/views/spotlight/sir_trevor/blocks/_solr_documents_grid_block.html.erb +5 -5
- data/app/views/spotlight/sir_trevor/blocks/_uploaded_items_block.html.erb +4 -0
- data/app/views/spotlight/tags/_tag.html.erb +24 -0
- data/app/views/spotlight/tags/index.html.erb +12 -16
- data/app/views/spotlight/translations/show.yaml.yamlbuilder +6 -0
- data/config/i18n-tasks.yml +1 -0
- data/config/locales/spotlight.en.yml +169 -10
- data/config/routes.rb +29 -1
- data/db/migrate/20210126123041_create_events.rb +1 -1
- data/db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb +20 -0
- data/db/migrate/20210305171150_create_bulk_updates.rb +9 -0
- data/db/migrate/20210308090000_migrate_caption_values_for_title_key.rb +29 -0
- data/db/migrate/20210506070809_add_indexes_for_featured_images.rb +9 -0
- data/lib/generators/spotlight/install_generator.rb +2 -2
- data/lib/generators/spotlight/templates/config/initializers/riiif.rb +7 -5
- data/lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb +1 -1
- data/lib/generators/spotlight/templates/solr/config/schema.xml +1 -1
- data/lib/migration/iiif.rb +3 -3
- data/lib/spotlight/engine.rb +14 -0
- data/lib/spotlight/version.rb +1 -1
- data/spec/controllers/spotlight/browse_controller_spec.rb +0 -6
- data/spec/controllers/spotlight/bulk_actions_controller_spec.rb +124 -0
- data/spec/controllers/spotlight/bulk_updates_controller_spec.rb +77 -0
- data/spec/controllers/spotlight/catalog_controller_spec.rb +12 -12
- data/spec/controllers/spotlight/featured_images_controller_spec.rb +3 -3
- data/spec/controllers/spotlight/job_trackers_controller_spec.rb +37 -0
- data/spec/controllers/spotlight/tags_controller_spec.rb +5 -1
- data/spec/examples.txt +1496 -1442
- data/spec/factories/bulk_updates.rb +15 -0
- data/spec/factories/exhibits.rb +4 -0
- data/spec/factories/job_trackers.rb +2 -0
- data/spec/factories/users.rb +27 -8
- data/spec/features/add_items_spec.rb +1 -1
- data/spec/features/bulk_actions_spec.rb +72 -0
- data/spec/features/catalog_spec.rb +1 -0
- data/spec/features/import_exhibit_spec.rb +5 -1
- data/spec/features/javascript/blocks/solr_documents_block_spec.rb +4 -4
- data/spec/features/javascript/blocks/uploaded_items_block_spec.rb +27 -1
- data/spec/features/site_users_management_spec.rb +4 -4
- data/spec/fixtures/bulk-update-template.csv +57 -0
- data/spec/fixtures/updated-bulk-update-template-w-tags.csv +4 -0
- data/spec/fixtures/updated-bulk-update-template.csv +4 -0
- data/spec/helpers/spotlight/application_helper_spec.rb +5 -6
- data/spec/helpers/spotlight/pages_helper_spec.rb +0 -15
- data/spec/helpers/spotlight/roles_helper_spec.rb +1 -1
- data/spec/i18n_spec.rb +1 -0
- data/spec/jobs/spotlight/add_tags_job_spec.rb +34 -0
- data/spec/jobs/spotlight/add_uploads_from_csv_spec.rb +4 -1
- data/spec/jobs/spotlight/change_visibility_job_spec.rb +30 -0
- data/spec/jobs/spotlight/process_bulk_updates_csv_job_spec.rb +78 -0
- data/spec/jobs/spotlight/reindex_job_spec.rb +4 -1
- data/spec/jobs/spotlight/remove_tags_job_spec.rb +39 -0
- data/spec/lib/migration/iiif_spec.rb +1 -1
- data/spec/models/spotlight/ability_spec.rb +27 -0
- data/spec/models/spotlight/access_controls_enforcement_search_builder_spec.rb +1 -2
- data/spec/models/spotlight/{reindex_progress_spec.rb → background_job_progress_spec.rb} +15 -2
- data/spec/models/spotlight/blacklight_configuration_spec.rb +22 -17
- data/spec/models/spotlight/browse_category_search_builder_spec.rb +49 -0
- data/spec/models/spotlight/exhibit_spec.rb +1 -1
- data/spec/models/spotlight/featured_image_spec.rb +13 -1
- data/spec/models/spotlight/resource_spec.rb +23 -0
- data/spec/models/spotlight/solr_document/atomic_updates_spec.rb +10 -0
- data/spec/presenters/spotlight/iiif_manifest_presenter_spec.rb +1 -1
- data/spec/services/spotlight/bulk_updates_csv_template_service_spec.rb +26 -0
- data/spec/test_app_templates/Gemfile.extra +1 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
- data/spec/uploaders/spotlight/featured_image_uploader_spec.rb +2 -2
- data/spec/views/spotlight/catalog/_edit_default.html.erb_spec.rb +1 -1
- data/spec/views/spotlight/dashboards/_reindexing_activity.html.erb_spec.rb +2 -0
- data/spec/views/spotlight/job_trackers/show.html.erb_spec.rb +65 -0
- data/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb +3 -4
- data/spec/views/spotlight/sir_trevor/blocks/_browse_block.html.erb_spec.rb +1 -1
- data/spec/views/spotlight/sir_trevor/blocks/_iframe_block.html.erb_spec.rb +1 -1
- data/spec/views/spotlight/sir_trevor/blocks/_link_to_search_block.html.erb_spec.rb +1 -1
- data/spec/views/spotlight/sir_trevor/blocks/_rule_block.html.erb_spec.rb +1 -1
- data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_block.html.erb_spec.rb +8 -4
- data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_carousel_block.html.erb_spec.rb +7 -2
- data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_embed_block.html.erb_spec.rb +8 -5
- data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_features_block.html.erb_spec.rb +3 -2
- data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_grid_block.html.erb_spec.rb +9 -4
- data/spec/views/spotlight/tags/index.html.erb_spec.rb +5 -2
- metadata +90 -21
- data/app/assets/images/blacklight/add_circle.svg +0 -1
- data/app/assets/images/blacklight/custom_fullscreen.svg +0 -1
- data/app/assets/images/blacklight/remove_circle.svg +0 -1
- data/app/assets/images/blacklight/resize_small.svg +0 -1
@@ -14,8 +14,6 @@ module Spotlight
|
|
14
14
|
|
15
15
|
accepts_nested_attributes_for :child_pages
|
16
16
|
|
17
|
-
belongs_to :thumbnail, class_name: 'Spotlight::FeaturedImage', dependent: :destroy, optional: true
|
18
|
-
|
19
17
|
before_validation unless: :top_level_page? do
|
20
18
|
self.exhibit = top_level_page_or_self.exhibit
|
21
19
|
end
|
@@ -31,6 +31,8 @@ module Spotlight
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
after_save :bust_containing_resource_caches
|
35
|
+
|
34
36
|
attr_accessor :upload_id
|
35
37
|
|
36
38
|
def iiif_url
|
@@ -68,10 +70,16 @@ module Spotlight
|
|
68
70
|
self[:iiif_tilesource]
|
69
71
|
elsif file_present?
|
70
72
|
riiif = Riiif::Engine.routes.url_helpers
|
71
|
-
riiif.info_path(
|
73
|
+
riiif.info_path(self)
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
77
|
+
# Include a hashed updated_at timestamp in the parameter key to bust any
|
78
|
+
# browser caching.
|
79
|
+
def to_param
|
80
|
+
"#{id}-#{Digest::MD5.hexdigest(updated_at.iso8601)}"
|
81
|
+
end
|
82
|
+
|
75
83
|
private
|
76
84
|
|
77
85
|
def image_size
|
@@ -81,5 +89,36 @@ module Spotlight
|
|
81
89
|
def iiif_service_base
|
82
90
|
iiif_tilesource&.sub('/info.json', '')
|
83
91
|
end
|
92
|
+
|
93
|
+
# This is an unfortunate work-around because:
|
94
|
+
# - when this instance is updated through accepts_nested_attributes_for on a parent model,
|
95
|
+
# the parent model is not necessarily updated (to bust caches, etc)
|
96
|
+
# - this model doesn't have an association back to where it is being used
|
97
|
+
# - these images can be used by multiple model instances (e.g. various translations of a feature page)
|
98
|
+
# - this model is used by different types of models (polymorphic use), so belongs_to/has_many doesn't help
|
99
|
+
# - potentially a problem with https://github.com/rails/rails/issues/26726
|
100
|
+
#
|
101
|
+
# Ideally, we might create a join table to connect this model to where it is used, but 🤷♂️
|
102
|
+
# Instead, we check each place this might be used and touch it
|
103
|
+
def bust_containing_resource_caches
|
104
|
+
if Rails.version > '6'
|
105
|
+
Spotlight::Search.where(thumbnail: self).or(Spotlight::Search.where(masthead: self)).touch_all
|
106
|
+
Spotlight::Page.where(thumbnail: self).touch_all
|
107
|
+
Spotlight::Exhibit.where(thumbnail: self).or(Spotlight::Exhibit.where(masthead: self)).touch_all
|
108
|
+
Spotlight::Contact.where(avatar: self).touch_all
|
109
|
+
Spotlight::Resources::Upload.where(upload: self).touch_all
|
110
|
+
else
|
111
|
+
bust_containing_resource_caches_rails5
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Rails 5 doesn't support touch_all.
|
116
|
+
def bust_containing_resource_caches_rails5
|
117
|
+
Spotlight::Search.where(thumbnail: self).or(Spotlight::Search.where(masthead: self)).find_each(&:touch)
|
118
|
+
Spotlight::Page.where(thumbnail: self).find_each(&:touch)
|
119
|
+
Spotlight::Exhibit.where(thumbnail: self).or(Spotlight::Exhibit.where(masthead: self)).find_each(&:touch)
|
120
|
+
Spotlight::Contact.where(avatar: self).find_each(&:touch)
|
121
|
+
Spotlight::Resources::Upload.where(upload: self).find_each(&:touch)
|
122
|
+
end
|
84
123
|
end
|
85
124
|
end
|
@@ -45,18 +45,14 @@ module Spotlight
|
|
45
45
|
|
46
46
|
# This gets the number of *documents* with a field
|
47
47
|
def document_counts
|
48
|
-
@document_count ||=
|
49
|
-
|
50
|
-
h[k.split(/:/).first] = v
|
51
|
-
end
|
48
|
+
@document_count ||= solr_response.facet_queries.each_with_object({}) do |(k, v), h|
|
49
|
+
h[k.split(/:/).first] = v
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
53
|
def terms
|
56
|
-
@terms ||=
|
57
|
-
|
58
|
-
h[facet_name] = facet.items.map(&:label)
|
59
|
-
end
|
54
|
+
@terms ||= solr_response.aggregations.each_with_object({}) do |(facet_name, facet), h|
|
55
|
+
h[facet_name] = facet.items.map(&:label)
|
60
56
|
end
|
61
57
|
end
|
62
58
|
|
@@ -12,6 +12,7 @@ module Spotlight
|
|
12
12
|
belongs_to :user, optional: true, class_name: Spotlight::Engine.config.user_class # rubocop:disable Rails/ReflectionClassName
|
13
13
|
has_many :events, as: :resource, dependent: :delete_all
|
14
14
|
has_many :job_trackers, as: :on, dependent: Rails.version > '6.1' ? :destroy_async : :destroy
|
15
|
+
has_many :subevents, through: :job_trackers, source: :events
|
15
16
|
|
16
17
|
serialize :data
|
17
18
|
|
@@ -66,6 +67,14 @@ module Spotlight
|
|
66
67
|
(100.0 * progress) / total
|
67
68
|
end
|
68
69
|
|
70
|
+
def status
|
71
|
+
@status ||= super
|
72
|
+
@status ||= 'missing'
|
73
|
+
@status = 'in_progress' if @status == 'completed' && job_trackers.any? { |t| t.in_progress? || t.enqueued? }
|
74
|
+
|
75
|
+
@status
|
76
|
+
end
|
77
|
+
|
69
78
|
def enqueued?
|
70
79
|
status == 'enqueued'
|
71
80
|
end
|
@@ -82,8 +91,8 @@ module Spotlight
|
|
82
91
|
status == 'failed'
|
83
92
|
end
|
84
93
|
|
85
|
-
def append_log_entry(type:, **args)
|
86
|
-
events.create(type: type, data: args)
|
94
|
+
def append_log_entry(type:, exhibit: nil, **args)
|
95
|
+
events.create(type: type, exhibit: exhibit, data: args)
|
87
96
|
rescue StandardError => e
|
88
97
|
Rails.logger.error("Unable to create log entry for job tracker #{id}: #{e}")
|
89
98
|
end
|
@@ -18,14 +18,12 @@ module Spotlight
|
|
18
18
|
delegate :available_view_fields,
|
19
19
|
:blacklight_config,
|
20
20
|
:current_exhibit,
|
21
|
-
:document_show_link_field,
|
22
|
-
:index_fields,
|
23
|
-
:index_field_label,
|
24
21
|
:spotlight,
|
25
22
|
:t,
|
26
|
-
:view_label,
|
27
23
|
to: :context
|
28
24
|
|
25
|
+
DOCUMENT_TITLE_KEY = '__spotlight_document_title___'
|
26
|
+
|
29
27
|
attr_reader :context, :page
|
30
28
|
|
31
29
|
def initialize(context:, page:)
|
@@ -35,7 +33,7 @@ module Spotlight
|
|
35
33
|
|
36
34
|
def as_json(*)
|
37
35
|
{
|
38
|
-
'blacklight-configuration-index-fields':
|
36
|
+
'blacklight-configuration-index-fields': available_caption_fields,
|
39
37
|
'blacklight-configuration-search-views': available_view_configs,
|
40
38
|
'attachment-endpoint': attachment_endpoint,
|
41
39
|
'autocomplete-exhibit-catalog-path': exhibit_autocomplete_endpoint,
|
@@ -48,15 +46,18 @@ module Spotlight
|
|
48
46
|
|
49
47
|
private
|
50
48
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
49
|
+
def available_caption_fields
|
50
|
+
default_caption_fields + blacklight_config.index_fields.reject { |_k, v| v.caption == false }.map { |k, v| { key: k, label: v.display_label } }
|
51
|
+
end
|
54
52
|
|
53
|
+
def default_caption_fields
|
54
|
+
fields = []
|
55
|
+
fields << { key: DOCUMENT_TITLE_KEY, label: t(:'spotlight.pages.form.title_placeholder') } unless blacklight_config.index_fields.key? DOCUMENT_TITLE_KEY
|
55
56
|
fields
|
56
57
|
end
|
57
58
|
|
58
59
|
def available_view_configs
|
59
|
-
available_view_fields.map { |k,
|
60
|
+
available_view_fields.map { |k, v| { key: k, label: v.display_label(k) } }
|
60
61
|
end
|
61
62
|
|
62
63
|
def attachment_endpoint
|
@@ -31,14 +31,14 @@ module Spotlight
|
|
31
31
|
# Persist the record to the database, and trigger a reindex to solr
|
32
32
|
#
|
33
33
|
# @param [Hash] All arguments will be passed through to ActiveRecord's #save method
|
34
|
-
def save_and_index(
|
35
|
-
save(*args) && reindex_later
|
34
|
+
def save_and_index(reindex_options: {}, **args)
|
35
|
+
save(*args) && reindex_later(**reindex_options)
|
36
36
|
end
|
37
37
|
|
38
38
|
##
|
39
39
|
# Enqueue an asynchronous reindexing job for this resource
|
40
|
-
def reindex_later
|
41
|
-
Spotlight::ReindexJob.perform_later(self)
|
40
|
+
def reindex_later(**args)
|
41
|
+
Spotlight::ReindexJob.perform_later(self, **args)
|
42
42
|
end
|
43
43
|
|
44
44
|
def document_model
|
@@ -33,8 +33,8 @@ module Spotlight
|
|
33
33
|
|
34
34
|
def url_is_iiif?(url)
|
35
35
|
valid_content_types = ['application/json', 'application/ld+json']
|
36
|
-
req =
|
37
|
-
req =
|
36
|
+
req = Spotlight::Resources::IiifService.http_client.head(url)
|
37
|
+
req = Spotlight::Resources::IiifService.http_client.get(url) if req.status == 405
|
38
38
|
return unless req.success?
|
39
39
|
|
40
40
|
valid_content_types.any? do |valid_type|
|
@@ -29,6 +29,13 @@ module Spotlight
|
|
29
29
|
recursive_manifests(new(url))
|
30
30
|
end
|
31
31
|
|
32
|
+
def self.http_client
|
33
|
+
Faraday.new do |b|
|
34
|
+
b.use FaradayMiddleware::FollowRedirects
|
35
|
+
b.adapter Faraday.default_adapter
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
32
39
|
protected
|
33
40
|
|
34
41
|
def object
|
@@ -41,7 +48,7 @@ module Spotlight
|
|
41
48
|
|
42
49
|
class << self
|
43
50
|
def iiif_response(url)
|
44
|
-
|
51
|
+
Spotlight::Resources::IiifService.http_client.get(url).body
|
45
52
|
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
|
46
53
|
Rails.logger.warn("HTTP GET for #{url} failed with #{e}")
|
47
54
|
{}.to_json
|
@@ -41,7 +41,7 @@ module Spotlight
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def to_solr
|
44
|
-
return {} unless upload
|
44
|
+
return {} unless upload&.file_present?
|
45
45
|
|
46
46
|
spotlight_routes = Spotlight::Engine.routes.url_helpers
|
47
47
|
riiif = Riiif::Engine.routes.url_helpers
|
@@ -51,7 +51,7 @@ module Spotlight
|
|
51
51
|
{
|
52
52
|
spotlight_full_image_width_ssm: dimensions.width,
|
53
53
|
spotlight_full_image_height_ssm: dimensions.height,
|
54
|
-
Spotlight::Engine.config.thumbnail_field => riiif.image_path(
|
54
|
+
Spotlight::Engine.config.thumbnail_field => riiif.image_path(upload, size: '!400,400'),
|
55
55
|
Spotlight::Engine.config.iiif_manifest_field => spotlight_routes.manifest_exhibit_solr_document_path(exhibit, compound_id)
|
56
56
|
}
|
57
57
|
end
|
@@ -4,11 +4,10 @@ module Spotlight
|
|
4
4
|
##
|
5
5
|
# Exhibit authorization roles
|
6
6
|
class Role < ActiveRecord::Base
|
7
|
-
ROLES = %w[admin curator].freeze
|
8
7
|
belongs_to :resource, polymorphic: true, optional: true
|
9
8
|
belongs_to :user, class_name: Spotlight::Engine.config.user_class, autosave: true, optional: false
|
10
9
|
|
11
|
-
validates :role, inclusion: { in:
|
10
|
+
validates :role, inclusion: { in: Spotlight::Engine.config.exhibit_roles }
|
12
11
|
validate :user_must_be_unique, if: :user
|
13
12
|
|
14
13
|
def user_key
|
@@ -70,7 +70,7 @@ module Spotlight
|
|
70
70
|
private
|
71
71
|
|
72
72
|
def presenter
|
73
|
-
controller.view_context.
|
73
|
+
controller.view_context.document_presenter(resource)
|
74
74
|
end
|
75
75
|
|
76
76
|
def endpoint
|
@@ -79,7 +79,7 @@ module Spotlight
|
|
79
79
|
|
80
80
|
def iiif_url
|
81
81
|
# yes this is hacky, and we are appropriately ashamed.
|
82
|
-
controller.riiif.info_url(uploaded_resource.upload
|
82
|
+
controller.riiif.info_url(uploaded_resource.upload).sub(%r{/info\.json\Z}, '')
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
|
5
|
+
module Spotlight
|
6
|
+
# A service to generate a CSV template suitable for re-uploading for bulk updates
|
7
|
+
class BulkUpdatesCsvTemplateService
|
8
|
+
attr_reader :exhibit
|
9
|
+
|
10
|
+
def initialize(exhibit:)
|
11
|
+
@exhibit = exhibit
|
12
|
+
end
|
13
|
+
|
14
|
+
def template(view_context:, title: true, tags: true, visibility: true)
|
15
|
+
return to_enum(:template, view_context: view_context, title: title, tags: tags, visibility: visibility) unless block_given?
|
16
|
+
|
17
|
+
yield ::CSV.generate_line(csv_headers(title: title, tags: tags, visibility: visibility))
|
18
|
+
each_document do |document|
|
19
|
+
sidecar = document.sidecar(exhibit)
|
20
|
+
yield ::CSV.generate_line([
|
21
|
+
document.id,
|
22
|
+
(title_column(view_context, document) if title),
|
23
|
+
(visibility_column(sidecar) if visibility),
|
24
|
+
(tags_column(sidecar) if tags)
|
25
|
+
].flatten.compact)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def title_column(view_context, document)
|
32
|
+
CGI.unescapeHTML(view_context.document_presenter(document).heading)
|
33
|
+
end
|
34
|
+
|
35
|
+
def visibility_column(sidecar)
|
36
|
+
sidecar.public ? 'TRUE' : ' '
|
37
|
+
end
|
38
|
+
|
39
|
+
def tags_column(sidecar)
|
40
|
+
exhibit_tags.map do |tag|
|
41
|
+
sidecar.all_tags_list.include?(tag) ? 'TRUE' : ' '
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def exhibit_tags
|
46
|
+
@exhibit_tags ||= exhibit.owned_tags.map(&:name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def csv_headers(title:, tags:, visibility:)
|
50
|
+
headers = [bulk_updates_config.csv_id]
|
51
|
+
headers.append(bulk_updates_config.csv_title) if title
|
52
|
+
headers.append(bulk_updates_config.csv_visibility) if visibility
|
53
|
+
if tags
|
54
|
+
exhibit_tags.each do |tag|
|
55
|
+
headers.append(format(bulk_updates_config.csv_tags, tag))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
headers
|
59
|
+
end
|
60
|
+
|
61
|
+
def bulk_updates_config
|
62
|
+
Spotlight::Engine.config.bulk_updates
|
63
|
+
end
|
64
|
+
|
65
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
66
|
+
def each_document(&block)
|
67
|
+
return to_enum(:each_document) unless block_given?
|
68
|
+
|
69
|
+
cursor_mark = nil
|
70
|
+
next_cursor_mark = '*'
|
71
|
+
|
72
|
+
solr_params = exhibit&.exhibit_search_builder&.to_h || {}
|
73
|
+
|
74
|
+
until next_cursor_mark == cursor_mark || next_cursor_mark.nil?
|
75
|
+
cursor_mark = next_cursor_mark
|
76
|
+
response = exhibit.blacklight_config.repository.search(
|
77
|
+
solr_params.merge(
|
78
|
+
'q' => '*',
|
79
|
+
'rows' => Spotlight::Engine.config.bulk_actions_batch_size,
|
80
|
+
'cursorMark' => cursor_mark,
|
81
|
+
'sort' => "#{exhibit.blacklight_config.document_model.unique_key} asc"
|
82
|
+
)
|
83
|
+
)
|
84
|
+
response.documents.each do |document|
|
85
|
+
block.call(document)
|
86
|
+
end
|
87
|
+
|
88
|
+
next_cursor_mark = response['nextCursorMark']
|
89
|
+
end
|
90
|
+
end
|
91
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
92
|
+
end
|
93
|
+
end
|
@@ -47,9 +47,7 @@ module Spotlight
|
|
47
47
|
#
|
48
48
|
# @return [Number]
|
49
49
|
def estimated_size
|
50
|
-
@estimated_size ||=
|
51
|
-
compile_steps(sources).sum { |source| source.call(context).count }
|
52
|
-
end
|
50
|
+
@estimated_size ||= compile_steps(sources).sum { |source| source.call(context).count }
|
53
51
|
end
|
54
52
|
|
55
53
|
##
|
@@ -57,7 +57,7 @@ module Spotlight
|
|
57
57
|
|
58
58
|
def response
|
59
59
|
@response ||= begin
|
60
|
-
|
60
|
+
Spotlight::Resources::IiifService.http_client.get(iiif_manifest_url).body
|
61
61
|
rescue Faraday::Error => e
|
62
62
|
Rails.logger.warn("#{self.class.name} failed to fetch #{iiif_manifest_url} with: #{e}")
|
63
63
|
'{}'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<div class="modal fade" id="add-tags-modal" tabindex="-1" role="dialog" aria-labelledby="add-tag-modal" aria-hidden="true">
|
2
|
+
<div class="modal-dialog">
|
3
|
+
<%= bootstrap_form_for([:visibility, current_exhibit], url: add_tags_exhibit_bulk_actions_path(current_exhibit), method: 'post') do |f| %>
|
4
|
+
<div class="modal-content">
|
5
|
+
<div class="modal-header">
|
6
|
+
<h4 class="modal-title" id="add-tag-modal"><%= t(:'spotlight.bulk_actions.add_tags.heading') %></h4>
|
7
|
+
<button type="button" class="blacklight-modal-close close" data-dismiss="modal" aria-label="<%= t('blacklight.modal.close') %>">
|
8
|
+
<span aria-hidden="true">×</span>
|
9
|
+
</button>
|
10
|
+
</div>
|
11
|
+
<div class="modal-body">
|
12
|
+
<p>
|
13
|
+
<%= t(:'spotlight.bulk_actions.add_tags.description', count: @response.total) %>
|
14
|
+
</p>
|
15
|
+
<div class="form-group">
|
16
|
+
<%= label_tag :tags, t(:'spotlight.bulk_actions.add_tags.label') %>
|
17
|
+
<%= text_field_tag :tags, '', class: 'form-control', data: { autocomplete_tag: true, autocomplete_url: exhibit_tags_path(current_exhibit, format: 'json')} %>
|
18
|
+
</div>
|
19
|
+
<%= render Blacklight::HiddenSearchStateComponent.new(params: search_state.params_for_search) %>
|
20
|
+
</div>
|
21
|
+
<div class="modal-footer d-flex flex-row-reverse justify-content-start">
|
22
|
+
<%= f.submit t(:'spotlight.bulk_actions.add'), class: 'btn btn-primary', data: { confirm: t(:'spotlight.bulk_actions.confirm') } %>
|
23
|
+
<button type="button" class="btn btn-link" data-dismiss="modal"><%= t :cancel %></button>
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
<% end %>
|
27
|
+
</div>
|
28
|
+
</div>
|