X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fplugins%2Fcomposer%2Fsrc%2Fsrc%2Flibraries%2Futils.js;h=3fa9eb3484fa45a5e759f678aa59e0a0ca899152;hb=f2dc2462571800e62cba969964de621dca09299c;hp=ef37a0bdc2377b31864037290354c5b5c054659b;hpb=4ef8c40c2c013c21f5487330daeab2561ba25fb3;p=osm%2FUI.git diff --git a/skyquake/plugins/composer/src/src/libraries/utils.js b/skyquake/plugins/composer/src/src/libraries/utils.js index ef37a0bdc..3fa9eb348 100644 --- a/skyquake/plugins/composer/src/src/libraries/utils.js +++ b/skyquake/plugins/composer/src/src/libraries/utils.js @@ -283,6 +283,13 @@ export default { return leafRefPath; }, + cleanupFieldKeyArray (fieldKeyArray) { + fieldKeyArray.map((fieldKey, fieldKeyIndex) => { + fieldKeyArray[fieldKeyIndex] = fieldKey.replace(/.*\/(.*)/, '$1'); + }); + return fieldKeyArray; + }, + resolveLeafRefPath (catalogs, leafRefPath, fieldKey, path, container) { let pathCopy = _clone(path); // Strip any prefixes @@ -295,16 +302,20 @@ export default { // Split on delimiter (/) const pathArray = leafRefPathCopy.split('/'); + let fieldKeyArray = fieldKey.split(':'); + + // strip prepending qualifiers from fieldKeys + fieldKeyArray = this.cleanupFieldKeyArray(fieldKeyArray); let results = []; // Check if relative path or not // TODO: Below works but - // better to convert the pathCopy to absolute/rooted path + // better to convert the pathCopy to absolute/rooted path // and use the absolute module instead if (this.isRelativePath(leafRefPathCopy)) { let i = pathArray.length; - while (pathArray[pathArray.length - i] == '..') { + while ((pathArray[pathArray.length - i] == '..') && fieldKeyArray.length > 1) { fieldKeyArray.splice(-1, 1); if (!isNaN(Number(fieldKeyArray[fieldKeyArray.length - 1]))) { // found a number, so an index. strip it @@ -327,13 +338,21 @@ export default { } else if (fieldKeyArray.length == 2) { for (let key in catalogs) { for (let subKey in catalogs[key]) { - let found = _find(catalogs[key][subKey], {id: fieldKeyArray[0]}); + console.log(key, subKey); + var found = _find(catalogs[key][subKey], {id: fieldKeyArray[0]}); if (found) { for (let foundKey in found) { - // let topLevel = _find(found[foundKey], {id: fieldKeyArray[1]}); - if (foundKey == fieldKeyArray[1]) { - results = this.getAbsoluteResults(found[foundKey], pathArray.splice(-i, i)); - return results; + if (_isArray(found[foundKey])) { + let topLevel = _find(found[foundKey], {id: fieldKeyArray[1]}); + if (topLevel) { + results = this.getAbsoluteResults(topLevel, pathArray.splice(-i, i)); + return results; + } + } else { + if (foundKey == fieldKeyArray[1]) { + results = this.getAbsoluteResults(found[foundKey], pathArray.splice(-i, i)); + return results; + } } } } @@ -342,13 +361,20 @@ export default { } else if (fieldKeyArray.length == 3) { for (let key in catalogs) { for (let subKey in catalogs[key]) { - let found = _.find(catalogs[key][subKey], {id: fieldKeyArray[0]}); + let found = _find(catalogs[key][subKey], {id: fieldKeyArray[0]}); if (found) { for (let foundKey in found) { - let topLevel = _.find(found[foundKey], {id: fieldKeyArray[1]}); - if (topLevel) { - results = this.getAbsoluteResults(topLevel, pathArray.splice(-i, i)); - return results; + if (_isArray(found[foundKey])) { + let topLevel = _find(found[foundKey], {id: fieldKeyArray[1]}); + if (topLevel) { + results = this.getAbsoluteResults(topLevel, pathArray.splice(-i, i)); + return results; + } + } else { + if (foundKey == fieldKeyArray[1]) { + results = this.getAbsoluteResults(found[foundKey], pathArray.splice(-i, i)); + return results; + } } } } @@ -375,3 +401,4 @@ export default { } } } +