NOTICKET: Relative refs, 3 levels deep
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / utils.js
index a182b1a..75afab3 100644 (file)
@@ -212,13 +212,35 @@ 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
                                                objectCopy = objectCopy[fragment];
+                                               if (!objectCopy) {
+                                                       // contains no value
+                                                       break;
+                                               }
                                        }
                                }
                        }
@@ -290,12 +312,27 @@ 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;
                                                }
                                        }
                                }
                        } 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 (foundKey == fieldKeyArray[1]) {
+                                                                       results = this.getAbsoluteResults(found[foundKey], pathArray.splice(-i, i));
+                                                                       return results;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       } 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]});
@@ -303,7 +340,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;
                                                                }
                                                        }