From ba40ffea4bb5d1dbde8f73b7b70b2d0bfeac32bc Mon Sep 17 00:00:00 2001 From: Thomas Francart Date: Tue, 19 Dec 2017 09:54:23 +0100 Subject: [PATCH] Disply domains in the tree 1. Add extra first-level nodes in the tree for each domain of a concept scheme, and add concept schemes under their domain nodes 2. When adding top concepts in the tree, search at the first and second level of the tree to find its concept scheme 3. sorts the tree to have domains first, before concept schemes without domains --- resource/js/hierarchy.js | 183 ++++++++++++++++++++++++++++++++++----- 1 file changed, 159 insertions(+), 24 deletions(-) diff --git a/resource/js/hierarchy.js b/resource/js/hierarchy.js index 19b069381..f0912797d 100644 --- a/resource/js/hierarchy.js +++ b/resource/js/hierarchy.js @@ -129,17 +129,57 @@ function createConceptObject(conceptUri, conceptData) { */ function attachTopConceptsToSchemes(schemes, currentNode, parentData) { for (var i = 0; i < schemes.length; i++) { - if (schemes[i].uri === parentData[currentNode.uri].top) { - if(Object.prototype.toString.call(schemes[i].children) !== '[object Array]' ) { - schemes[i].children = []; - } - schemes[i].children.push(currentNode); - // the hierarchy response contains the parent info before the topConcepts so it's a safe to open the first one without broaders - if (!schemes.opened && !currentNode.broader) { - schemes[i].state = currentNode.state; - schemes.opened = true; - } - } + // search if top concept uri is equal to scheme uri on first level + // search in all the 'tops' key + for (var j = 0; j < parentData[currentNode.uri].tops.length; j++) { + var currentTop = parentData[currentNode.uri].tops[j]; + // we found a scheme at the first level that is equal to one of the 'tops' value + if(schemes[i].uri===currentTop){ + if(Object.prototype.toString.call(schemes[i].children) !== '[object Array]' ) { + schemes[i].children = []; + } + // append to a first-level node that corresponds to a concept scheme + schemes[i].children.push(currentNode); + + // the hierarchy response contains the parent info before the topConcepts so it's a safe to open the first one without broaders + if (!schemes[i].opened && !currentNode.broader) { + schemes[i].state = currentNode.state; + schemes.opened = true; + } + break; + } + } + + // search if top concept uri is equal to scheme children uri, if there are children (second level) + // this may be the case if schemes are organised by subjects : subjects will be first-level nodes, concepts schemes will be second level + for (var h = 0; h