check nodes and graph version

This commit is contained in:
Nils Schneider 2015-04-07 21:10:37 +02:00
parent c6605aded6
commit c734975a3b

View File

@ -2,7 +2,15 @@ define(["config", "moment", "router", "leaflet", "gui", "numeral"],
function (config, moment, Router, L, GUI, numeral) { function (config, moment, Router, L, GUI, numeral) {
return function () { return function () {
function handleData(data) { function handleData(data) {
var nodes = Object.keys(data[0].nodes).map(function (key) { return data[0].nodes[key] }) var dataNodes = data[0]
var dataGraph = data[1]
if (dataNodes.version !== 1 || dataGraph.version !== 1) {
var err = "Unsupported nodes or graph version: " + dataNodes.version + " " + dataGraph.version
throw err
}
var nodes = Object.keys(dataNodes.nodes).map(function (key) { return dataNodes.nodes[key] })
nodes = nodes.filter( function (d) { nodes = nodes.filter( function (d) {
return "firstseen" in d && "lastseen" in d return "firstseen" in d && "lastseen" in d
@ -19,8 +27,8 @@ function (config, moment, Router, L, GUI, numeral) {
var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online)) var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online))
var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline)) var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline))
var graph = data[1].batadv var graphnodes = dataNodes.nodes
var graphnodes = data[0].nodes var graph = dataGraph.batadv
graph.nodes.forEach( function (d) { graph.nodes.forEach( function (d) {
if (d.node_id in graphnodes) if (d.node_id in graphnodes)
@ -108,6 +116,7 @@ function (config, moment, Router, L, GUI, numeral) {
}, 60000) }, 60000)
}) })
.catch(function (e) { .catch(function (e) {
document.body.textContent = e
console.log(e) console.log(e)
}) })
} }