aboutsummaryrefslogtreecommitdiffstats
path: root/web/js/nms.js
diff options
context:
space:
mode:
authorKristian Lyngstol <kristian@bohemians.org>2016-05-27 23:54:45 +0200
committerKristian Lyngstol <kristian@bohemians.org>2016-05-27 23:54:45 +0200
commit6f1fc97c9c097249e316f85a914aa439b4273448 (patch)
tree6f952674b84f759b1414475c3e2503df2a020fdb /web/js/nms.js
parent00317ae0fd34acd2244d1ef26ef37b1f55486f59 (diff)
front: More performance tweaks and testTree()
testTree() will make it easier to avoid try-catch'ing because instead of if (nmsData == undefined || nmsData.snmp == undefined || nmsData.snmp.snmp == undefined || nmsData.snmp.snmp[sw] == undefined || nmsData.snmp.snmp[sw].misc ...) you can do if (!testRoot(nmsData,['snmp','snmp',sw,'misc')) { ... Which is at least slightly less annoying.
Diffstat (limited to 'web/js/nms.js')
-rw-r--r--web/js/nms.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/web/js/nms.js b/web/js/nms.js
index ca87f5d..a3706b9 100644
--- a/web/js/nms.js
+++ b/web/js/nms.js
@@ -813,3 +813,24 @@ function startNowPicker(now) {
}
});
}
+
+/*
+ * Test if the entire path specified in the arrary "ar" exists under the
+ * specified root.
+ *
+ * E.g.:
+ * if (!testTree(nmsData,['snmp','snmp',sw,'misc'])) {
+ * do stuff with nmsData.snmp.snmp[sw].misc
+ * }
+ *
+ */
+function testTree(root, ar) {
+ if (ar == undefined || root == undefined)
+ return false;
+ for (var i in ar) {
+ root = root[ar[i]];
+ if (root == undefined)
+ return false;
+ }
+ return true;
+}