Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract CollectionComponent and NonCollectionComponent from DocumentC… #1153

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<%= render Arclight::DocumentActionsComponent.new(presenter: presenter) %>
</div>


<%= render Arclight::MetadataSectionComponent.with_collection(blacklight_config.show.component_metadata_partials || [], metadata_attr: { layout: Arclight::UpperMetadataLayoutComponent }, presenter: presenter, classes: ['al-metadata-section', 'breadcrumb-item', "breadcrumb-item-#{document.parents.length + 3}"]) unless document.collection? %>

<div class='row'>
<div class='col-md-12'>
<%= embed %>
Expand All @@ -27,25 +24,20 @@
<ul class='nav nav-tabs nav-fill' role='tablist' aria-label='<%= t('arclight.views.show.tablist_nav') %>'>
<li class='nav-item flex-fill'>
<a class='nav-link p-1 p-sm-2 active' data-toggle='tab' data-bs-toggle='tab' href='#context' role='tab'>
<%= document.collection? ? t('arclight.views.show.overview') : t('arclight.views.show.context') %>
<%= t('arclight.views.show.overview') %>
</a>
</li>

<% if document.collection? %>
<li class='nav-item flex-fill'>
<a class='nav-link p-1 p-sm-2 disabled' data-toggle='tab' data-bs-toggle='tab' href='#contents' role='tab' data-hierarchy-enable-me='true'>
<a class='nav-link p-1 p-sm-2 disabled' data-toggle='tab' data-bs-toggle='tab' href='#contents' role='tab' data-hierarchy-enable-me='true'>
<%= t 'arclight.views.show.no_contents' %>
</a>
</a>
</li>
<% end %>

<% if online_content? %>
<li class='nav-item flex-fill'>
<a class='nav-link p-1 p-sm-2' data-toggle='tab' data-bs-toggle='tab' href='#online-content' role='tab' data-arclight-online-content-tab='true'>
<%= t 'arclight.views.show.online_content' %>
<% unless document.collection? %>
<span data-arclight-online-content-tab-count/>
<% end %>
</a>
</li>
<% end %>
Expand All @@ -62,34 +54,32 @@
<div class='row'>
<div class='col-md-12'>
<div class='tab-content'>
<% if document.collection? %>
<div class='tab-pane active' id='context' role='tabpanel'>
<div class="row">
<div class="col-md-3 order-md-2">
<div class='tab-pane active' id='context' role='tabpanel'>
<div class="row">
<div class="col-md-3 order-md-2">
<nav class='al-sidebar-navigation-context al-sticky-sidebar'
id="collection-context-sidebar"
aria-label='<%= t('arclight.views.show.context_nav.title') %>'>
<ul class='nav nav-pills flex-sm-row flex-md-column text-sm-left text-md-right'>
id="collection-context-sidebar"
aria-label='<%= t('arclight.views.show.context_nav.title') %>'>
<ul class='nav nav-pills flex-sm-row flex-md-column text-sm-left text-md-right'>
<% blacklight_config.show.metadata_partials&.select { |item| presenter.with_field_group(item).fields_to_render.any? }&.each do |item| %>
<li class='nav-item'>
<li class='nav-item'>
<%= link_to t("arclight.views.show.sections.#{item}"), "##{t("arclight.views.show.sections.#{item}").parameterize}", class: 'nav-link' %>
</li>
</li>
<% end %>
</ul>
</ul>
</nav>
</div>
</div>

<div class="col-md-9 order-md-1">
<div class="col-md-9 order-md-1">
<h2 class="sr-only visually-hidden"><%= t 'arclight.views.show.context' %></h2>
<%= render Arclight::MetadataSectionComponent.with_collection(blacklight_config.show.metadata_partials || [], presenter: presenter, heading: true) %>
</div>
</div>
</div>
<% end %>
</div>

<div class='tab-pane <%= document.collection? ? '': 'active' %>' id='<%= document.collection? ? 'contents' : 'context' %>' role='tabpanel'>
<h2 class="sr-only visually-hidden" data-sr-enable-me='true' data-has-contents=<%= t 'arclight.views.show.has_content' %>><%= document.collection? ? t('arclight.views.show.has_content') : t('arclight.views.show.context') %></h2>
<%= content_tag(:div, id: document.collection? ? nil : t("arclight.views.show.sections.collection_context_field").parameterize) do %>
<div class='tab-pane' id='contents' role='tabpanel'>
<h2 class="sr-only visually-hidden" data-sr-enable-me='true' data-has-contents=<%= t 'arclight.views.show.has_content' %>><%= t('arclight.views.show.has_content') %></h2>
<%= content_tag(:div) do %>
<%= generic_context_navigation(@document) %>
<% end %>
</div>
Expand All @@ -106,7 +96,7 @@
name: document.collection_name,
access: 'online',
view: 'online_contents',
parent: document.collection? ? nil : document.reference,
parent: nil,
search_field: 'within_collection'
}
}
Expand All @@ -117,11 +107,7 @@
<div class='tab-pane' id='access' role='tabpanel'>
<h2 class="sr-only visually-hidden"><%= t 'arclight.views.show.access' %></h2>

<% if @document.collection? %>
<%= render Arclight::MetadataSectionComponent.with_collection(blacklight_config.show.context_access_tab_items || [], presenter: presenter) %>
<% else %>
<%= render Arclight::MetadataSectionComponent.with_collection(blacklight_config.show.component_access_tab_items || [], presenter: presenter) %>
<% end %>
<%= render Arclight::MetadataSectionComponent.with_collection(blacklight_config.show.context_access_tab_items || [], presenter: presenter) %>
</div>
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions app/components/arclight/collection_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Arclight
# Render a single collection document
class CollectionComponent < Blacklight::DocumentComponent
def blacklight_config
presenter.configuration
end
attr_reader :document

delegate :online_content?, to: :document
end
end
18 changes: 12 additions & 6 deletions app/components/arclight/document_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
module Arclight
# Render a single document
class DocumentComponent < Blacklight::DocumentComponent
attr_reader :document

def online_content?
document.online_content? && (document.collection? || document.children?)
def initialize(presenter:, **kwargs) # rubocop:disable Lint/MissingSuper
@presenter = presenter
@kwargs = kwargs
end

def blacklight_config
presenter.configuration
attr_reader :presenter
delegate :collection?, to: :presenter

def call
if collection?
render CollectionComponent.new(presenter: presenter, **@kwargs)
else
render NonCollectionComponent.new(presenter: presenter, **@kwargs)
end
end
end
end
88 changes: 88 additions & 0 deletions app/components/arclight/non_collection_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<div class='d-md-flex justify-content-between al-show'>
<div class='al-show-breadcrumb'>
<nav aria-label="breadcrumb">
<%= render Arclight::BreadcrumbsHierarchyComponent.new(presenter: presenter) %>

<%= content_tag :h1, class: "breadcrumb-item breadcrumb-item-#{document.parents.length + 2} media" do %>
<span class="media-body" aria-hidden="true"><%= blacklight_icon document_or_parent_icon(document) %></span>
<span class="col"><%= document.normalized_title %></span>
<% end %>
</nav>
</div>

<%= render Arclight::DocumentActionsComponent.new(presenter: presenter) %>
</div>

<%= render Arclight::MetadataSectionComponent.with_collection(blacklight_config.show.component_metadata_partials || [], metadata_attr: { layout: Arclight::UpperMetadataLayoutComponent }, presenter: presenter, classes: ['al-metadata-section', 'breadcrumb-item', "breadcrumb-item-#{document.parents.length + 3}"]) %>

<div class='row'>
<div class='col-md-12'>
<%= embed %>
</div>
</div>

<div class='row'>
<div class='col-md-12'>
<ul class='nav nav-tabs nav-fill' role='tablist' aria-label='<%= t('arclight.views.show.tablist_nav') %>'>
<li class='nav-item flex-fill'>
<a class='nav-link p-1 p-sm-2 active' data-toggle='tab' data-bs-toggle='tab' href='#context' role='tab'>
<%= t('arclight.views.show.context') %>
</a>
</li>

<% if online_content? %>
<li class='nav-item flex-fill'>
<a class='nav-link p-1 p-sm-2' data-toggle='tab' data-bs-toggle='tab' href='#online-content' role='tab' data-arclight-online-content-tab='true'>
<%= t 'arclight.views.show.online_content' %>
<span data-arclight-online-content-tab-count/>
</a>
</li>
<% end %>

<li class='nav-item flex-fill'>
<a class='nav-link p-1 p-sm-2' data-toggle='tab' data-bs-toggle='tab' href='#access' role='tab'>
<%= t 'arclight.views.show.access' %>
</a>
</li>
</ul>
</div>
</div>

<div class='row'>
<div class='col-md-12'>
<div class='tab-content'>
<div class='tab-pane active' id='context' role='tabpanel'>
<h2 class="sr-only visually-hidden" data-sr-enable-me='true' data-has-contents=<%= t 'arclight.views.show.has_content' %>><%= t('arclight.views.show.context') %></h2>
<%= content_tag(:div, id: t("arclight.views.show.sections.collection_context_field").parameterize) do %>
<%= generic_context_navigation(@document) %>
<% end %>
</div>

<% if online_content? %>
<div class='tab-pane' id='online-content' role='tabpanel'>
<h2 class="sr-only visually-hidden"><%= t 'arclight.views.show.online_content' %></h2>
<%= content_tag(
:div, '',
class: 'al-contents',
data: {
arclight: {
path: search_catalog_path,
name: document.collection_name,
access: 'online',
view: 'online_contents',
parent: document.reference,
search_field: 'within_collection'
}
}
) %>
</div>
<% end %>

<div class='tab-pane' id='access' role='tabpanel'>
<h2 class="sr-only visually-hidden"><%= t 'arclight.views.show.access' %></h2>

<%= render Arclight::MetadataSectionComponent.with_collection(blacklight_config.show.component_access_tab_items || [], presenter: presenter) %>
</div>
</div>
</div>
</div>
16 changes: 16 additions & 0 deletions app/components/arclight/non_collection_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Arclight
# Render a single non-collection document
class NonCollectionComponent < Blacklight::DocumentComponent
attr_reader :document

def blacklight_config
presenter.configuration
end

def online_content?
document.online_content? && document.children?
end
end
end
1 change: 1 addition & 0 deletions app/presenters/arclight/show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Arclight
# Custom presentation methods for show partial
class ShowPresenter < Blacklight::ShowPresenter
attr_accessor :field_group
delegate :collection?, to: :document

def heading
document.normalized_title
Expand Down