+ return results;
+ },
+
+ resolveCurrentPredicate (leafRefPath, container, pathCopy) {
+ if (leafRefPath.indexOf('current()') != -1) {
+ // contains current
+
+ // Get the relative path from current
+ let relativePath = leafRefPath.match("current\\(\\)\/(.*)\]");
+ let relativePathArray = relativePath[1].split('/');
+
+ while (relativePathArray[0] == '..') {
+ pathCopy.pop();
+ relativePathArray.shift();
+ }
+
+ // Supports only one relative path up
+ // To support deeper paths, will need to massage the string more
+ // i.e. change '/'' to '.'
+ const searchPath = pathCopy.join('.').concat('.', relativePathArray[0]);
+ const searchValue = this.resolvePath(container.model, searchPath);
+
+ const predicateStr = leafRefPath.match("(current.*)\]")[1];
+ leafRefPath = leafRefPath.replace(predicateStr, searchValue);
+ }
+ return leafRefPath;
+ },
+
+ resolveLeafRefPath (catalogs, leafRefPath, fieldKey, path, container) {
+ let pathCopy = _.clone(path);
+ // Strip any prefixes
+ let leafRefPathCopy = leafRefPath.replace(/[\w\d]*:/g, '');
+ // Strip any spaces
+ leafRefPathCopy = leafRefPathCopy.replace(/\s/g, '');
+
+ // resolve any current paths
+ leafRefPathCopy = this.resolveCurrentPredicate(leafRefPathCopy, container, pathCopy);
+
+ // Split on delimiter (/)
+ const pathArray = leafRefPathCopy.split('/');
+ let fieldKeyArray = fieldKey.split(':');
+ let results = [];
+
+ // Check if relative path or not
+ // TODO: Below works but
+ // 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] == '..') {
+ fieldKeyArray.splice(-1, 1);
+ if (!isNaN(Number(fieldKeyArray[fieldKeyArray.length - 1]))) {
+ // found a number, so an index. strip it
+ fieldKeyArray.splice(-1, 1);
+ }
+ i--;
+ }
+
+ // traversed all .. - now traverse down
+ if (fieldKeyArray.length == 1) {
+ for (let key in catalogs) {
+ 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));
+ return results;
+ }
+ }
+ }
+ } 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]});
+ if (found) {
+ for (let foundKey in found) {
+ let topLevel = _.find(found[foundKey], {id: fieldKeyArray[1]});
+ if (topLevel) {
+ results = this.getResults(topLevel, pathArray.splice(-i, i));
+ return results;
+ }
+ }
+ }
+ }
+ }
+ } else {
+ // not supported - too many levels deep ... maybe some day
+ console.log('The relative path is from a node too many levels deep from root. This is not supported at the time');
+ }
+ } else {
+ // absolute path
+ if (pathArray[0] == "") {
+ pathArray.splice(0, 1);
+ }
+
+ let catalogKey = pathArray[0];
+ let topLevelObject = {};
+
+ topLevelObject[catalogKey] = catalogs[catalogKey];
+
+ results = this.getAbsoluteResults(topLevelObject, pathArray);
+
+ return results;
+ }
+ }