From b3746223f432b607b6f0316814d1db51cb937a42 Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Fri, 5 Nov 2021 10:15:01 -0400 Subject: [PATCH 1/6] #80: fix container list block when unititle has descendants --- includes/jstreebuilder.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/jstreebuilder.inc b/includes/jstreebuilder.inc index fa60e80..f99d0a9 100644 --- a/includes/jstreebuilder.inc +++ b/includes/jstreebuilder.inc @@ -84,8 +84,8 @@ class JSTreeBuilder { * Never actually got used? */ protected function getComponentTree(DOMElement $element) { - $title = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unittitle/text()))', $element); - $date = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unitdate/text()))', $element); + $title = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unittitle/descendant-or-self::*/text()))', $element); + $date = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unitdate/descendant-or-self::*/text()))', $element); $text = empty($date) ? $title : format_string('@title (@date)', array( From 3d67ebc338656817189d906ce4bce87deee03650 Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Wed, 1 Dec 2021 12:11:52 -0500 Subject: [PATCH 2/6] discoverygarden#82: prefix container list with unitid --- includes/jstreebuilder.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/jstreebuilder.inc b/includes/jstreebuilder.inc index f99d0a9..449e86e 100644 --- a/includes/jstreebuilder.inc +++ b/includes/jstreebuilder.inc @@ -84,6 +84,7 @@ class JSTreeBuilder { * Never actually got used? */ protected function getComponentTree(DOMElement $element) { + $unitid = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unitid/descendant-or-self::*/text()))', $element); $title = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unittitle/descendant-or-self::*/text()))', $element); $date = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unitdate/descendant-or-self::*/text()))', $element); $text = empty($date) ? @@ -92,6 +93,9 @@ class JSTreeBuilder { '@title' => $title, '@date' => $date, )); + if ($unitid) { + $text = $unitid.' '.$text; + } $info = array( 'id' => $element->getAttribute('id'), 'text' => $text, From 051a1c8bd695a3a4e5a58c33ca9a61674c2feb2c Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Fri, 17 Dec 2021 09:46:18 -0500 Subject: [PATCH 3/6] #83: suppress container list block if treebuilder is empty --- includes/blocks.inc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/blocks.inc b/includes/blocks.inc index 70cdbf7..fa00835 100644 --- a/includes/blocks.inc +++ b/includes/blocks.inc @@ -49,6 +49,10 @@ function islandora_manuscript_container_list($object) { ); module_load_include('inc', 'islandora_manuscript', 'includes/jstreebuilder'); $builder = new \Islandora\Manuscript\ContainerListJSTreeBuilder($object); + $structure = $builder->getTreeStructure(); + if (empty($structure)) { + return; + } $form['tree']['#attached']['js'][] = array( 'type' => 'setting', 'data' => array( @@ -58,7 +62,7 @@ function islandora_manuscript_container_list($object) { $id => array( 'core' => array( 'multiple' => FALSE, - 'data' => $builder->getTreeStructure(), + 'data' => $structure, ), 'plugins' => array('types'), 'types' => array( From a92a2e2476ebc5410246df52314c267a1f1dcb97 Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Fri, 15 Apr 2022 17:33:49 -0400 Subject: [PATCH 4/6] #80: fix container list block when unititle has decendents or braces --- includes/jstreebuilder.inc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/includes/jstreebuilder.inc b/includes/jstreebuilder.inc index 449e86e..9743078 100644 --- a/includes/jstreebuilder.inc +++ b/includes/jstreebuilder.inc @@ -84,9 +84,9 @@ class JSTreeBuilder { * Never actually got used? */ protected function getComponentTree(DOMElement $element) { - $unitid = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unitid/descendant-or-self::*/text()))', $element); - $title = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unittitle/descendant-or-self::*/text()))', $element); - $date = $this->xpath->evaluate('normalize-space(string(ead:did/ead:unitdate/descendant-or-self::*/text()))', $element); + $unitid = $this->stringifyNode('ead:did/ead:unitid', $element); + $title = $this->stringifyNode('ead:did/ead:unittitle', $element); + $date = $this->stringifyNode('ead:did/ead:unitdate', $element); $text = empty($date) ? $title : format_string('@title (@date)', array( @@ -101,7 +101,7 @@ class JSTreeBuilder { 'text' => $text, 'type' => $element->getAttribute('level'), 'children' => array_merge( - $this->getLevel('ead:c01 | ead:c02 | ead:c03 | ead:c04 | ead:c05 | ead:c', $element), + $this->getLevel('ead:c01 | ead:c02 | ead:c03 | ead:c04 | ead:c05 | ead:c06 | ead:c07 | ead:c08 | ead:c09 | ead:c', $element), $this->getContainers($element) ), 'path' => $element->getNodePath(), @@ -109,6 +109,18 @@ class JSTreeBuilder { return $info; } + /** + * Given the xpath to a single node in a DOMElement, + * return the text content of the node and its children + * @param string $xpath Path to a single node + * @param DOMElement $element Element which may contain the xpath + * @return string The textContent of the node, or an empty string if no node is found + */ + protected function stringifyNode($xpath, DOMElement $element) { + $node = $this->xpath->query($xpath, $element)->item(0); + return $node ? $node->textContent : ''; + } + /** * Get all containers of this component. */ From a2007b939c7fdc346bc7e982d8eeda9ae0a76ec6 Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Tue, 31 May 2022 10:15:44 -0400 Subject: [PATCH 5/6] discoverygarden#82: prefix container list with level --- includes/jstreebuilder.inc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/includes/jstreebuilder.inc b/includes/jstreebuilder.inc index 9743078..e9fc76b 100644 --- a/includes/jstreebuilder.inc +++ b/includes/jstreebuilder.inc @@ -84,6 +84,7 @@ class JSTreeBuilder { * Never actually got used? */ protected function getComponentTree(DOMElement $element) { + $level = $this->translateLevelCode($this->xpath->evaluate('string(./@level)', $element)); $unitid = $this->stringifyNode('ead:did/ead:unitid', $element); $title = $this->stringifyNode('ead:did/ead:unittitle', $element); $date = $this->stringifyNode('ead:did/ead:unitdate', $element); @@ -96,6 +97,9 @@ class JSTreeBuilder { if ($unitid) { $text = $unitid.' '.$text; } + if ($level) { + $text = $level.' '.$text; + } $info = array( 'id' => $element->getAttribute('id'), 'text' => $text, @@ -109,6 +113,28 @@ class JSTreeBuilder { return $info; } + /** + * Given the string of a component's level + * return a human-readable representation + * @param string $level the code from an EAD component's level attribute + * @return string A human-readable representation + */ + protected function translateLevelCode($level) { + $value = ''; + switch ($level) { + case 'recordgrp': + $value = t('Record Group'); + break; + case 'subgrp': + $value = t('Subgroup'); + break; + default: + $value = t(ucfirst($level)); + } + return $value; + } + + /** * Given the xpath to a single node in a DOMElement, * return the text content of the node and its children From de5139ad839537b8aa2cfedfb215fba5cc1e6ab9 Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Tue, 7 Jun 2022 17:23:53 -0400 Subject: [PATCH 6/6] discoverygarden#82: ignore otherlevel containers --- includes/jstreebuilder.inc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/jstreebuilder.inc b/includes/jstreebuilder.inc index e9fc76b..23192b9 100644 --- a/includes/jstreebuilder.inc +++ b/includes/jstreebuilder.inc @@ -62,7 +62,10 @@ class JSTreeBuilder { $list = $this->xpath->query($query, $node); $roots = array(); foreach ($list as $component) { - $roots[] = $this->getComponentTree($component); + $root = $this->getComponentTree($component); + if ($root) { + $roots[] = $root; + } } return $roots; }