From 45242f8aee3c349e06cff9455770df769f6f13d0 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Thu, 23 Jun 2016 14:07:43 +0200 Subject: [PATCH] Init --- .gitignore | 2 + bower.json | 21 +++++ config.json.example | 9 ++ index.html | 74 ++++++++++++++++ lib/store.js | 201 ++++++++++++++++++++++++++++++++++++++++++++ styles.css | 23 +++++ 6 files changed, 330 insertions(+) create mode 100644 .gitignore create mode 100644 bower.json create mode 100644 config.json.example create mode 100644 index.html create mode 100644 lib/store.js create mode 100644 styles.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d959fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bower_components +config.json diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..346c394 --- /dev/null +++ b/bower.json @@ -0,0 +1,21 @@ +{ + "name": "eventmanager", + "authors": [ + "Martin Geno " + ], + "description": "", + "main": "", + "license": "MIT", + "homepage": "", + "private": true, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "dependencies": { + "material-design-lite": "^1.1.3" + } +} diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..5db130e --- /dev/null +++ b/config.json.example @@ -0,0 +1,9 @@ +{ + "api":"http://localhost:8080/api", + "reload":60000, + "map":"http://localhost:8080/meshviewer", + "statistics":{ + "one":"http://ffhb.h.sum7.de:8080/dashboard-solo/file/Short.json?panelId=1&fullscreen&var-interval_group=60s&theme=light&from=1466165052000&var-title={{NODEID}}&var-node={{NODEID}}", + "all":"http://ffhb.h.sum7.de:8080/dashboard-solo/file/Short.json?panelId=1&fullscreen&var-interval_group=60s&theme=light&from=1466165052000&var-title=All" + } +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..c0f2d32 --- /dev/null +++ b/index.html @@ -0,0 +1,74 @@ + + + + + + + + Eventmanager + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+
+ +
+ + +
+
+ +
+
+ +
+
+
+
+
+
+
+ +
+ + + + diff --git a/lib/store.js b/lib/store.js new file mode 100644 index 0000000..f3a5277 --- /dev/null +++ b/lib/store.js @@ -0,0 +1,201 @@ +function get(url) { + return new Promise(function(resolve, reject) { + var req = new XMLHttpRequest(); + req.open('GET', url); + + req.onload = function() { + if (req.status == 200) { + resolve(req.response); + } + else { + reject(Error(req.statusText)); + } + }; + + req.onerror = function() { + reject(Error("Network Error")); + }; + + req.send(); + }).then(JSON.parse); +} +function localStorageTest() { + var test = 'test' + try { + localStorage.setItem(test, test) + localStorage.removeItem(test) + return true + } catch(e) { + return false + } +} + +var internal = { + config:{}, + nodes:{}, + aliases:{}, + tmp:{ + aliases_count: 0, + nodes_count: 0 + } +} +//var toast = document.querySelector('#toast'); +var toast = document.getElementById("toast") +var container = document.getElementById("container") +var refreshButton = document.getElementById("refresh") +var menuNodes = document.getElementById("menu_nodes") +var menuAliases = document.getElementById("menu_aliases") + + +function notify(key){ + toast.MaterialSnackbar.showSnackbar({ + message:"New Nodes with nodeid '"+key+"'!", + actionHandler: function(event) { + console.log(event) + }, + actionText: 'Edit', + timeout: 3000 + }); +} +function update(){ + get(internal.config.api+"/aliases").then(function(data){ + internal.aliases = data + menuAliases.setAttribute("data-badge",Object.keys(internal.aliases).length) + }) + get(internal.config.api+"/nodes").then(function(data){ + Object.keys(data).map(function(key){ + if(typeof internal.nodes[key]=='undefined'){ + notify(key) + } + internal.nodes[key] = data[key] + }) + menuNodes.setAttribute("data-badge",Object.keys(internal.nodes).length) + }) + localStorage.setItem("nodes",JSON.stringify(internal.nodes)) + localStorage.setItem("aliases",JSON.stringify(internal.aliases)) +} + + + +function routeNodes(){ + fill = '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + Object.keys(internal.nodes).map(function(key){ + fill += '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + }) + fill += '
HostnameClientsPorts2.4 Ghz5 GhzLocationSSH
' + + '
' + + '' + + '' + + '
' + + '
' + + '2.4 Ghz: '+internal.nodes[key].statistics.clients.wifi24 + + '
' + + '5 Ghz: '+internal.nodes[key].statistics.clients.wifi5 + + '
100%' + + 'Ch: '+((internal.nodes[key].nodeinfo.settings !== undefined)?internal.nodes[key].nodeinfo.settings.freq24.channel:'-') + + '
' + + 'Tx: '+((internal.nodes[key].nodeinfo.settings !== undefined)?internal.nodes[key].nodeinfo.settings.freq24.txpower:'-') + + '
' + + 'Ch: '+((internal.nodes[key].nodeinfo.settings !== undefined)?internal.nodes[key].nodeinfo.settings.freq5.channel:'-') + + '
' + + 'TX: '+((internal.nodes[key].nodeinfo.settings !== undefined)?internal.nodes[key].nodeinfo.settings.freq5.txpower:'-') + + '
locationSSH
' + container.innerHTML = fill +} +function routeAliases(){ + fill = '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + Object.keys(internal.aliases).map(function(key){ + fill += '' + + '' + + '' + + '' + + '' + + '' + }) + fill += '
HostnameLocation2.4 Ghz5 Ghz
' + + internal.aliases[key].hostname + + '
' + + ''+key+'' + + '
location' + + 'Ch: '+((internal.aliases[key].freq24 !== undefined)?internal.aliases[key].freq24.channel:'-') + + '
' + + 'Tx: '+((internal.aliases[key].freq24 !== undefined)?internal.aliases[key].freq24.txpower:'-') + + '
' + + 'Ch: '+((internal.aliases[key].freq5 !== undefined)?internal.aliases[key].freq5.channel:'-') + + '
' + + 'TX: '+((internal.aliases[key].freq5 !== undefined)?internal.aliases[key].freq5.txpower:'-') + + '
' + container.innerHTML = fill +} +function routeMap(){ + container.innerHTML = "