Skip to content

Commit f882f55

Browse files
gordonleacockcbeer
authored andcommitted
Add icons to collection/component show page breadcrumbs #801 (#847)
1 parent 41b12ba commit f882f55

19 files changed

+77
-30
lines changed

.codeclimate.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
version: "2"
32
exclude_patterns:
43
- "app/assets/javascripts/arclight/context_navigation.js"

.rubocop.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ AllCops:
1717
Metrics/ModuleLength:
1818
Exclude:
1919
- 'app/helpers/arclight_helper.rb'
20+
- 'app/models/concerns/arclight/solr_document.rb'
2021

2122
Metrics/BlockLength:
2223
Exclude:

app/assets/stylesheets/arclight/modules/layout.scss

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
background-color: transparent;
99
margin-bottom: 0;
1010
padding: 0;
11+
.breadcrumb-item + .breadcrumb-item::before {
12+
content: '';
13+
}
1114
}
1215

1316
.al-show-actions-box {

app/assets/stylesheets/arclight/modules/search_results.scss

+8
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ article.document {
146146
padding-right: 0 !important;
147147
}
148148

149+
.breadcrumb .media .col, h1.media .col {
150+
flex-basis: auto;
151+
}
152+
153+
.breadcrumb .media svg, h1.media svg {
154+
fill: $gray-600;
155+
}
156+
149157
.breadcrumb-links a {
150158
color: $body-color;
151159
}

app/helpers/arclight_helper.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,14 @@ def hierarchy_component_context?
180180

181181
# determine which icon to show in search results header
182182
# these icon names will need to be updated when the icons are determined
183-
def document_header_icon(document)
183+
def document_or_parent_icon(document)
184184
case document.level&.downcase
185185
when 'collection'
186186
'collection'
187187
when 'file'
188188
'file'
189+
when 'series', 'subseries'
190+
'folder'
189191
else
190192
'container'
191193
end

app/models/arclight/parent.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ module Arclight
55
# Logic containing information about Solr_Ead "Parent"
66
# https://github.com/awead/solr_ead/blob/8cf7ffaa66e0e4c9c0b12f5646d6c2e20984cd99/lib/solr_ead/behaviors.rb#L54-L57
77
class Parent
8-
attr_reader :id, :label, :eadid
9-
def initialize(id:, label:, eadid:)
8+
attr_reader :id, :label, :eadid, :level
9+
def initialize(id:, label:, eadid:, level:)
1010
@id = id
1111
@label = label
1212
@eadid = eadid
13+
@level = level
1314
end
1415

1516
##

app/models/arclight/parents.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ module Arclight
55
# Object for parsing and formalizing Solr_Ead "Parents"
66
# https://github.com/awead/solr_ead/blob/8cf7ffaa66e0e4c9c0b12f5646d6c2e20984cd99/lib/solr_ead/behaviors.rb#L54-L57
77
class Parents
8-
attr_reader :ids, :labels
9-
def initialize(ids:, labels:, eadid:)
8+
attr_reader :ids, :labels, :levels
9+
def initialize(ids:, labels:, eadid:, levels:)
1010
@ids = ids
1111
@labels = labels
1212
@eadid = eadid
13+
@levels = levels
1314
end
1415

1516
def eadid
@@ -19,7 +20,7 @@ def eadid
1920
##
2021
# @return [Array[Arclight::Parent]]
2122
def as_parents
22-
Hash[ids.zip(labels)].map { |k, v| Arclight::Parent.new(id: k, label: v, eadid: eadid) }
23+
ids.map.with_index { |_id, idx| Arclight::Parent.new(id: ids[idx], label: labels[idx], eadid: eadid, level: levels[idx]) }
2324
end
2425

2526
##
@@ -28,7 +29,8 @@ def self.from_solr_document(document)
2829
ids = document.parent_ids
2930
labels = document.parent_labels
3031
eadid = document.eadid
31-
new(ids: ids, labels: labels, eadid: eadid)
32+
levels = document.parent_levels
33+
new(ids: ids, labels: labels, eadid: eadid, levels: levels)
3234
end
3335
end
3436
end

app/models/concerns/arclight/solr_document.rb

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def parent_labels
2020
fetch('parent_unittitles_ssm', [])
2121
end
2222

23+
def parent_levels
24+
fetch('parent_levels_ssm', [])
25+
end
26+
2327
def parent_document
2428
self.class.new fetch('parent').fetch('docs', []).first
2529
end
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= blacklight_icon document_header_icon(document) %>
1+
<%= blacklight_icon document_or_parent_icon(document) %>

app/views/catalog/_arclight_index_compact_default.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="documentHeader row">
22
<div class="col-auto">
3-
<%= blacklight_icon document_header_icon(document) %>
3+
<%= blacklight_icon document_or_parent_icon(document) %>
44
</div>
55
<div class="col col-no-left-padding col-no-right-padding">
66
<div class="d-flex justify-content-between">

app/views/catalog/_arclight_index_group_document_compact_default.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<% breadcrumbs = component_top_level_parent_to_links(document) %>
33
<div class="documentHeader row">
44
<div class="col-auto">
5-
<%= blacklight_icon document_header_icon(document) %>
5+
<%= blacklight_icon document_or_parent_icon(document) %>
66
</div>
77
<div class="col col-no-left-padding">
88
<h4>

app/views/catalog/_arclight_index_group_document_default.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<% breadcrumbs = parents_to_links(document) %>
33
<div class="documentHeader row">
44
<div class="col-auto">
5-
<%= blacklight_icon document_header_icon(document) %>
5+
<%= blacklight_icon document_or_parent_icon(document) %>
66
</div>
77
<div class="col col-no-left-padding">
88
<h4>
+13-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
<% parents = Arclight::Parents.from_solr_document(document).as_parents %>
22
<nav aria-label="breadcrumb">
33
<ol class="breadcrumb">
4-
<li class="breadcrumb-item al-bc-item breadcrumb-item-1">
4+
<li class="media breadcrumb-item breadcrumb-item-1">
55
<% if document.repository_config.present? %>
6-
<%= link_to(document.repository_config.name, arclight_engine.repository_path(document.repository_config.slug)) %>
6+
<span class="media-body" aria-hidden="true"><%= blacklight_icon :repository, classes: 'al-repository-content-icon' %></span>
7+
<span class="col"><%= link_to(document.repository_config.name, arclight_engine.repository_path(document.repository_config.slug)) %></span>
78
<% else %>
8-
<span><%= t('arclight.show_breadcrumb_label') %></span>
9+
<span class="media-body" aria-hidden="true"><%= blacklight_icon :repository, classes: 'al-repository-content-icon' %></span><span class="col"><%= t('arclight.show_breadcrumb_label') %></span>
910
<% end %>
1011
</li>
1112
<% parents.each_with_index.map do |parent, index| %>
12-
<%= content_tag :li, class: "breadcrumb-item breadcrumb-item-#{index + 2} al-bc-item" do %>
13-
<%= link_to parent.label, solr_document_path(parent.global_id) %>
14-
<% end %>
13+
<%= content_tag :li, class: "breadcrumb-item breadcrumb-item-#{index + 1} media" do %>
14+
<span class="media-body" aria-hidden="true"><%= blacklight_icon document_or_parent_icon(parent) %></span>
15+
<span class="col"><%= link_to parent.label, solr_document_path(parent.global_id) %></span>
16+
<% end %>
1517
<% end %>
1618
</ol>
17-
<h1 class="breadcrumb-item breadcrumb-item-<%= parents.length + 2 %> al-bc-item">
18-
<%= document.normalized_title %>
19-
</h1>
19+
20+
<%= content_tag :h1, class: "breadcrumb-item breadcrumb-item-#{parents.length + 2} media" do %>
21+
<span class="media-body" aria-hidden="true"><%= blacklight_icon document_or_parent_icon(document) %></span>
22+
<span class="col"><%= document.normalized_title %></span>
23+
<% end %>
2024
</nav>

lib/arclight/traject/ead2_config.rb

+11
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@
332332
accumulator.concat context.output_hash['parent_unittitles_ssm']
333333
end
334334

335+
to_field 'parent_levels_ssm' do |_record, accumulator, context|
336+
## Top level document
337+
accumulator.concat context.clipboard[:parent].output_hash['level_ssm']
338+
## Other components
339+
context.output_hash['parent_ssm']&.drop(1)&.each do |id|
340+
accumulator.concat Array
341+
.wrap(context.clipboard[:parent].output_hash['components'])
342+
.select { |c| c['ref_ssi'] == [id] }.map { |c| c['level_ssm'] }.flatten
343+
end
344+
end
345+
335346
to_field 'unitid_ssm', extract_xpath('./did/unitid')
336347
to_field 'collection_unitid_ssm' do |_record, accumulator, context|
337348
accumulator.concat Array.wrap(context.clipboard[:parent].output_hash['unitid_ssm'])

spec/features/collection_page_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@
334334
it 'links repository and shows collection header 1 text' do
335335
within '.al-show-breadcrumb' do
336336
expect(page).to have_css 'a', text: 'National Library of Medicine. History of Medicine Division'
337-
expect(page).to have_css 'h1.breadcrumb-item-2', text: 'Alpha Omega Alpha Archives, 1894-1992'
337+
expect(page).to have_css 'span', text: 'Alpha Omega Alpha Archives, 1894-1992'
338338
end
339339
end
340340
end

spec/features/traject/ead2_indexing_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@
437437
aspace_238a0567431f36f49acea49ef576d408
438438
]
439439
end
440+
441+
it 'parents and levels' do
442+
expect(component_with_many_parents['parent_levels_ssm']).to eq %w[
443+
collection
444+
Series
445+
Subseries
446+
]
447+
end
440448
end
441449
end
442450
end

spec/helpers/arclight_helper_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -339,18 +339,18 @@
339339
end
340340
end
341341

342-
describe 'document_header_icon' do
342+
describe 'document_or_parent_icon' do
343343
let(:document) { SolrDocument.new('level_ssm': ['collection']) }
344344

345345
it 'properly assigns the icon' do
346-
expect(helper.document_header_icon(document)).to eq 'collection'
346+
expect(helper.document_or_parent_icon(document)).to eq 'collection'
347347
end
348348

349349
context 'there is no level_ssm' do
350350
let(:document) { SolrDocument.new }
351351

352352
it 'gives the default icon' do
353-
expect(helper.document_header_icon(document)).to eq 'container'
353+
expect(helper.document_or_parent_icon(document)).to eq 'container'
354354
end
355355
end
356356
end

spec/models/arclight/parent_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
require 'spec_helper'
44

55
RSpec.describe Arclight::Parent do
6-
subject(:instance) { described_class.new(id: 'abc', label: 'ABC', eadid: '123') }
6+
subject(:instance) { described_class.new(id: 'abc', label: 'ABC', eadid: '123', level: 'collection') }
77

88
describe '#global_id' do
99
context 'when the eadid is the id' do
10-
subject(:instance) { described_class.new(id: 'abc', label: 'ABC', eadid: 'abc') }
10+
subject(:instance) { described_class.new(id: 'abc', label: 'ABC', eadid: 'abc', level: 'collection') }
1111

1212
it 'returns the id (and does not duplicate the id)' do
1313
expect(instance.global_id).to eq 'abc'

spec/models/arclight/parents_spec.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
SolrDocument.new(
88
parent_ssm: %w[def ghi],
99
parent_unittitles_ssm: %w[DEF GHI],
10-
ead_ssi: 'abc123'
10+
ead_ssi: 'abc123',
11+
parent_levels_ssm: %w[collection]
1112
)
1213
end
1314

1415
let(:dot_eadid_doc) do
1516
SolrDocument.new(
1617
parent_ssm: %w[def ghi],
1718
parent_unittitles_ssm: %w[DEF GHI],
18-
ead_ssi: 'abc123.xml'
19+
ead_ssi: 'abc123.xml',
20+
parent_levels_ssm: %w[collection]
1921
)
2022
end
2123

@@ -33,6 +35,7 @@
3335
expect(good_instance.ids).to eq %w[def ghi]
3436
expect(good_instance.labels).to eq %w[DEF GHI]
3537
expect(good_instance.eadid).to eq 'abc123'
38+
expect(good_instance.levels).to eq %w[collection]
3639
end
3740

3841
it 'cleans up the eadid properly by replacing dots with dashes' do
@@ -63,11 +66,12 @@
6366
expect(good_instance.as_parents.first.id).to eq 'def'
6467
expect(good_instance.as_parents.first.label).to eq 'DEF'
6568
expect(good_instance.as_parents.first.eadid).to eq 'abc123'
69+
expect(good_instance.as_parents.first.level).to eq 'collection'
6670
end
6771
end
6872
context 'with no data' do
6973
it 'returns an empty array' do
70-
expect(described_class.new(ids: [], labels: [], eadid: '').as_parents).to eq []
74+
expect(described_class.new(ids: [], labels: [], eadid: '', levels: '').as_parents).to eq []
7175
end
7276
end
7377
end

0 commit comments

Comments
 (0)