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 = "