From 0896a7fa55cfbb2082ead7ca791294df1053f2ad Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Fri, 20 Sep 2024 15:13:22 -0700 Subject: [PATCH 1/2] Add a Spotlight deprecator. --- lib/spotlight.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/spotlight.rb b/lib/spotlight.rb index 8dea1de7f..3097fd591 100644 --- a/lib/spotlight.rb +++ b/lib/spotlight.rb @@ -6,4 +6,7 @@ ## # Spotlight module Spotlight + def self.deprecator + @deprecator ||= ActiveSupport::Deprecation.new('5.0', 'blacklight-spotlight') + end end From 8d497594d0d40a275e7f0ed67ae7fc085ac785ff Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Fri, 20 Sep 2024 15:13:44 -0700 Subject: [PATCH 2/2] Use a document component for rendering documents for admins. --- .../document_admin_table_component.html.erb | 36 +++++++++++++++++++ .../document_admin_table_component.rb | 23 ++++++++++++ .../spotlight/catalog_controller.rb | 6 +++- .../spotlight/dashboards_controller.rb | 7 ++-- .../_admin_index_header_default.html.erb | 1 + .../catalog/_admin_thumbnail_default.html.erb | 1 + .../catalog/_document_admin_table.html.erb | 9 ++++- .../spotlight/catalog/_document_row.html.erb | 7 ++-- .../catalog/_index_compact_default.html.erb | 1 + 9 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 app/components/spotlight/document_admin_table_component.html.erb create mode 100644 app/components/spotlight/document_admin_table_component.rb diff --git a/app/components/spotlight/document_admin_table_component.html.erb b/app/components/spotlight/document_admin_table_component.html.erb new file mode 100644 index 000000000..87dac7c8c --- /dev/null +++ b/app/components/spotlight/document_admin_table_component.html.erb @@ -0,0 +1,36 @@ +<%= content_tag @component, + id: @id, + data: { + 'document-id': @document.id.to_s.parameterize, + 'document-counter': @counter, + 'label-toggle': @document.id + }, + itemscope: true, + itemtype: @document.itemtype, + class: classes.flatten.join(' ') do %> + <% # header bar for doc items in index view -%> + + <%= thumbnail %> + + + <%# header bar for doc items in index view -%> +
+
+ <%= helpers.link_to_document(presenter.document, itemprop: 'name') %> +
+
+ + + + + + <%= timestamp %> + + + + <%= render partial: 'document_visibility_control', locals: { document: presenter.document} %> + +<% end %> diff --git a/app/components/spotlight/document_admin_table_component.rb b/app/components/spotlight/document_admin_table_component.rb new file mode 100644 index 000000000..8303da6ba --- /dev/null +++ b/app/components/spotlight/document_admin_table_component.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Spotlight + # Displays the document + # This overrides the title method to provide an edit link. + class DocumentAdminTableComponent < Blacklight::DocumentComponent + def initialize(component: 'tr', **kwargs) + super + end + + def classes + super + ['doc-row'] + end + + def timestamp + return unless presenter.document[presenter.configuration.index.timestamp_field] + + l Date.parse(presenter.document[presenter.configuration.index.timestamp_field]) + rescue StandardError + nil + end + end +end diff --git a/app/controllers/spotlight/catalog_controller.rb b/app/controllers/spotlight/catalog_controller.rb index 3cf8f98fe..389567dd3 100644 --- a/app/controllers/spotlight/catalog_controller.rb +++ b/app/controllers/spotlight/catalog_controller.rb @@ -37,7 +37,11 @@ class CatalogController < ::CatalogController before_action only: :admin do blacklight_config.view.select! { |k, _v| k == :admin_table } - blacklight_config.view.admin_table(partials: [:index_compact], document_actions: []) unless blacklight_config.view.key? :admin_table + unless blacklight_config.view.key? :admin_table + blacklight_config.view.admin_table(document_component: Spotlight::DocumentAdminTableComponent, + partials: [:index_compact], + document_actions: []) + end if Blacklight::VERSION > '8' blacklight_config.track_search_session.storage = false else diff --git a/app/controllers/spotlight/dashboards_controller.rb b/app/controllers/spotlight/dashboards_controller.rb index 903b83e2b..7696e2993 100644 --- a/app/controllers/spotlight/dashboards_controller.rb +++ b/app/controllers/spotlight/dashboards_controller.rb @@ -12,14 +12,15 @@ class DashboardsController < Spotlight::ApplicationController before_action only: [:show] do blacklight_config.action_mapping&.delete(:show) - blacklight_config.view.clear - blacklight_config.view.admin_table(partials: ['index_compact'], document_actions: []) + blacklight_config.action_mapping.show.top_level_config = :index if blacklight_config.key?(:action_mapping) + + blacklight_config.index.document_component = Spotlight::DocumentAdminTableComponent + blacklight_config.index.document_actions = [] if Blacklight::VERSION > '8' blacklight_config.track_search_session.storage = false else blacklight_config.track_search_session = false end - blacklight_config.action_mapping.show.top_level_config = :index if blacklight_config.key?(:action_mapping) end def show diff --git a/app/views/spotlight/catalog/_admin_index_header_default.html.erb b/app/views/spotlight/catalog/_admin_index_header_default.html.erb index 9fc60c1c6..517550a6e 100644 --- a/app/views/spotlight/catalog/_admin_index_header_default.html.erb +++ b/app/views/spotlight/catalog/_admin_index_header_default.html.erb @@ -1,4 +1,5 @@ <%# header bar for doc items in index view -%> +<%- Spotlight.deprecator.warn 'The partial _spotlight/catalog/admin_index_header_default.html.erb will be removed; customize the admin display using components instead' %>
<%# main title container for doc partial view How many bootstrap columns need to be reserved diff --git a/app/views/spotlight/catalog/_admin_thumbnail_default.html.erb b/app/views/spotlight/catalog/_admin_thumbnail_default.html.erb index c017c169c..30f4425eb 100644 --- a/app/views/spotlight/catalog/_admin_thumbnail_default.html.erb +++ b/app/views/spotlight/catalog/_admin_thumbnail_default.html.erb @@ -1,3 +1,4 @@ +<%- Spotlight.deprecator.warn 'The partial _spotlight/catalog/_admin_thumbnail.html.erb will be removed; customize the admin display using components instead' %> <% doc_presenter = document_presenter(document) %> <%- if doc_presenter.thumbnail.exists? %>
diff --git a/app/views/spotlight/catalog/_document_admin_table.html.erb b/app/views/spotlight/catalog/_document_admin_table.html.erb index f5c7e33d3..6703f9354 100644 --- a/app/views/spotlight/catalog/_document_admin_table.html.erb +++ b/app/views/spotlight/catalog/_document_admin_table.html.erb @@ -1,4 +1,5 @@ <% # container for all documents in index view -%> +<% view_config = local_assigns[:view_config] || blacklight_config&.view_config(document_index_view_type) %> @@ -8,5 +9,11 @@ - <%= render partial: 'document_row', collection: documents, as: :document %> + + <% if Blacklight.version < '8.0' %> + <%= render view_config.document_component.with_collection(documents) %> + <% else %> + <% document_presenters = documents.map { |doc| document_presenter(doc) } -%> + <%= render view_config.document_component.with_collection(document_presenters) %> + <% end %>
<%= t(:'spotlight.catalog.fields.visibility') %>
diff --git a/app/views/spotlight/catalog/_document_row.html.erb b/app/views/spotlight/catalog/_document_row.html.erb index c5e8cc2f5..7d737eebd 100644 --- a/app/views/spotlight/catalog/_document_row.html.erb +++ b/app/views/spotlight/catalog/_document_row.html.erb @@ -1,5 +1,2 @@ -<% # container for a single doc -%> - - <%= render_document_partials document, blacklight_config.view_config(document_index_view_type).partials, :document_counter => document_counter %> - - +<%- Spotlight.deprecator.warn 'The partial _spotlight/catalog/_document_row.html.erb will be removed; customize the admin display using components instead' %> +<%= render Spotlight::DocumentAdminTableComponent.new(presenter: document_presenter(document)) %> diff --git a/app/views/spotlight/catalog/_index_compact_default.html.erb b/app/views/spotlight/catalog/_index_compact_default.html.erb index 92d43673e..6796f2401 100644 --- a/app/views/spotlight/catalog/_index_compact_default.html.erb +++ b/app/views/spotlight/catalog/_index_compact_default.html.erb @@ -1,3 +1,4 @@ +<%- Spotlight.deprecator.warn 'The partial _spotlight/catalog/_index_compact_default.html.erb will be removed; customize the admin display using components instead' %> <% # header bar for doc items in index view -%> <%= render_document_partial document, 'admin_thumbnail', document_counter: document_counter %>