Skip to content

Commit

Permalink
Merge pull request #3146 from projectblacklight/document-admin-table-…
Browse files Browse the repository at this point in the history
…component

Use a document component for rendering documents for admins.
  • Loading branch information
jcoyne committed Sep 21, 2024
2 parents 0419ca6 + 8d49759 commit a8d8e45
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 10 deletions.
36 changes: 36 additions & 0 deletions app/components/spotlight/document_admin_table_component.html.erb
Original file line number Diff line number Diff line change
@@ -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 -%>
<td class="spotlight-admin-thumbnail">
<%= thumbnail %>
</td>
<td>
<%# header bar for doc items in index view -%>
<div class="documentHeader row" data-label-toggle="<%= @document.id %>">
<h5 class="index_title col-md-12">
<%= helpers.link_to_document(presenter.document, itemprop: 'name') %>
</h5>
</div>
<div class="page-links">
<%= helpers.view_link presenter.document, helpers.link_to_document(presenter.document) %> &middot;
<%= helpers.exhibit_edit_link presenter.document, [:edit, helpers.current_exhibit, presenter.document] %>
</div>
</td>
<td class="text-nowrap">
<%= timestamp %>
</td>
<td class="checkbox-toggle">
<%= render partial: 'document_visibility_control', locals: { document: presenter.document} %>
</td>
<% end %>
23 changes: 23 additions & 0 deletions app/components/spotlight/document_admin_table_component.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion app/controllers/spotlight/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/spotlight/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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' %>
<div class="documentHeader row" data-label-toggle="<%= document.id %>">
<%# main title container for doc partial view
How many bootstrap columns need to be reserved
Expand Down
Original file line number Diff line number Diff line change
@@ -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? %>
<div class="document-thumbnail spotlight-admin-thumbnail">
Expand Down
9 changes: 8 additions & 1 deletion app/views/spotlight/catalog/_document_admin_table.html.erb
Original file line number Diff line number Diff line change
@@ -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) %>
<table id="documents" class="table">
<thead>
<tr>
Expand All @@ -8,5 +9,11 @@
<th scope="col" class="checkbox-toggle"><%= t(:'spotlight.catalog.fields.visibility') %></th>
</tr>
</thead>
<%= 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 %>
</table>
7 changes: 2 additions & 5 deletions app/views/spotlight/catalog/_document_row.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<% # container for a single doc -%>
<tr class="<%= render_document_class document %> doc-row" data-label-toggle="<%= document.id %>" itemscope itemtype="<%= document.itemtype %>">
<%= render_document_partials document, blacklight_config.view_config(document_index_view_type).partials, :document_counter => document_counter %>
</tr>

<%- 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)) %>
Original file line number Diff line number Diff line change
@@ -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 -%>
<td>
<%= render_document_partial document, 'admin_thumbnail', document_counter: document_counter %>
Expand Down
3 changes: 3 additions & 0 deletions lib/spotlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
##
# Spotlight
module Spotlight
def self.deprecator
@deprecator ||= ActiveSupport::Deprecation.new('5.0', 'blacklight-spotlight')
end
end

0 comments on commit a8d8e45

Please sign in to comment.