Skip to content

Commit

Permalink
Use a document component for rendering documents for admins.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Sep 20, 2024
1 parent 0896a7f commit a700b6f
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 7 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>
<%= 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
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
5 changes: 4 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,7 @@
<th scope="col" class="checkbox-toggle"><%= t(:'spotlight.catalog.fields.visibility') %></th>
</tr>
</thead>
<%= render partial: 'document_row', collection: documents, as: :document %>
<% document_presenters = documents.map { |doc| document_presenter(doc) } -%>
<%= render view_config.document_component.with_collection(document_presenters) %>
</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(document: 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

0 comments on commit a700b6f

Please sign in to comment.