X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fplugins%2Fcomposer%2Fsrc%2Fsrc%2Flibraries%2Futils.js;h=ff2adc02ce52a8d1e45ad2443b65c33cabf7e617;hb=267d43e391d633c26d45db31125612355665f193;hp=a182b1a90a4e1fafb6c850a6d27fe863458c6a59;hpb=30879fffbecf6d78cde249fecf68f6335555711a;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 a182b1a90..ff2adc02c 100644 --- a/skyquake/plugins/composer/src/src/libraries/utils.js +++ b/skyquake/plugins/composer/src/src/libraries/utils.js @@ -180,6 +180,9 @@ export default { console.log('Something went wrong while resolving a leafref. Reached a leaf with predicate.'); } else { // contains no predicate + if (!objectCopy) { + break; + } results.push(objectCopy[fragment]); } } @@ -212,12 +215,33 @@ export default { let key = fragment.split('[')[0]; let searchObject = {}; searchObject[predicateKey] = predicateValue; - objectCopy = _.find(objectCopy[key], searchObject); - if (!objectCopy) { - return []; + let found = _.find(objectCopy[key], searchObject); + if (found) { + objectCopy = found; + } else { + // check for numerical value + if (predicateValue != "" && + predicateValue != null && + predicateValue != NaN && + predicateValue != Infinity && + predicateValue != -Infinity) { + let numericalPredicateValue = _.toNumber(predicateValue); + if (_.isNumber(numericalPredicateValue)) { + searchObject[predicateKey] = numericalPredicateValue; + found = _.find(objectCopy[key], searchObject); + } + } + if (found) { + objectCopy = found; + } else { + return []; + } } } else { // contains no predicate + if (!objectCopy) { + break; + } objectCopy = objectCopy[fragment]; } } @@ -290,7 +314,7 @@ export default { for (let subKey in catalogs[key]) { let found = _.find(catalogs[key][subKey], {id: fieldKeyArray[0]}); if (found) { - results = this.getResults(found, pathArray.splice(-i, i)); + results = this.getAbsoluteResults(found, pathArray.splice(-i, i)); return results; } } @@ -303,7 +327,7 @@ export default { for (let foundKey in found) { let topLevel = _.find(found[foundKey], {id: fieldKeyArray[1]}); if (topLevel) { - results = this.getResults(topLevel, pathArray.splice(-i, i)); + results = this.getAbsoluteResults(topLevel, pathArray.splice(-i, i)); return results; } }