refactor setData
This commit is contained in:
parent
3e143435e6
commit
a031ac336d
|
@ -8,8 +8,8 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
||||||
d.appendChild(el)
|
d.appendChild(el)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setData = function (links) {
|
self.setData = function (data) {
|
||||||
if (links.length === 0)
|
if (data.links.length === 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
var h2 = document.createElement("h2")
|
var h2 = document.createElement("h2")
|
||||||
|
@ -39,7 +39,7 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
||||||
|
|
||||||
var tbody = document.createElement("tbody")
|
var tbody = document.createElement("tbody")
|
||||||
|
|
||||||
links.forEach( function (d) {
|
data.links.forEach( function (d) {
|
||||||
var row = document.createElement("tr")
|
var row = document.createElement("tr")
|
||||||
var td1 = document.createElement("td")
|
var td1 = document.createElement("td")
|
||||||
var a = document.createElement("a")
|
var a = document.createElement("a")
|
||||||
|
|
32
lib/main.js
32
lib/main.js
|
@ -18,8 +18,8 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
|
||||||
document.body.insertBefore(map.div, document.body.firstChild)
|
document.body.insertBefore(map.div, document.body.firstChild)
|
||||||
|
|
||||||
meshstats = new Meshstats()
|
meshstats = new Meshstats()
|
||||||
newnodeslist = new SimpleNodelist(config, "firstseen", router, "Neue Knoten")
|
newnodeslist = new SimpleNodelist(config, "new", "firstseen", router, "Neue Knoten")
|
||||||
lostnodeslist = new SimpleNodelist(config, "lastseen", router, "Verschwundene Knoten")
|
lostnodeslist = new SimpleNodelist(config, "lost", "lastseen", router, "Verschwundene Knoten")
|
||||||
nodelist = new Nodelist(router)
|
nodelist = new Nodelist(router)
|
||||||
linklist = new Linklist(linkScale, router)
|
linklist = new Linklist(linkScale, router)
|
||||||
|
|
||||||
|
@ -37,8 +37,7 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleData(data) {
|
function handleData(data) {
|
||||||
var nodedict = data[0]
|
var nodes = Object.keys(data[0].nodes).map(function (key) { return data[0].nodes[key] })
|
||||||
var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.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
|
||||||
|
@ -99,13 +98,15 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
|
||||||
d.target.node.neighbours.push({ node: d.source.node, link: d })
|
d.target.node.neighbours.push({ node: d.source.node, link: d })
|
||||||
})
|
})
|
||||||
|
|
||||||
map.setData(now, nodes, links, newnodes, lostnodes)
|
return { now: now,
|
||||||
meshstats.setData(nodes)
|
timestamp: data[0].timestamp,
|
||||||
nodelist.setData(now, nodes)
|
nodes: {
|
||||||
linklist.setData(links)
|
all: nodes,
|
||||||
newnodeslist.setData(newnodes)
|
new: newnodes,
|
||||||
lostnodeslist.setData(lostnodes)
|
lost: lostnodes
|
||||||
router.setData(nodes, links)
|
},
|
||||||
|
links: links
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var urls = [ config.dataPath + "nodes.json",
|
var urls = [ config.dataPath + "nodes.json",
|
||||||
|
@ -118,6 +119,15 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
|
||||||
return d
|
return d
|
||||||
})
|
})
|
||||||
.then(handleData)
|
.then(handleData)
|
||||||
|
.then(function (d) {
|
||||||
|
map.setData(d)
|
||||||
|
meshstats.setData(d)
|
||||||
|
nodelist.setData(d)
|
||||||
|
linklist.setData(d)
|
||||||
|
newnodeslist.setData(d)
|
||||||
|
lostnodeslist.setData(d)
|
||||||
|
router.setData(d)
|
||||||
|
})
|
||||||
.then(function () { router.start() })
|
.then(function () { router.start() })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
14
lib/map.js
14
lib/map.js
|
@ -77,15 +77,15 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
|
||||||
var nodeDict = {}
|
var nodeDict = {}
|
||||||
var linkDict = {}
|
var linkDict = {}
|
||||||
|
|
||||||
self.setData = function (now, nodes, links, newnodes, lostnodes) {
|
self.setData = function (data) {
|
||||||
nodeDict = {}
|
nodeDict = {}
|
||||||
linkDict = {}
|
linkDict = {}
|
||||||
|
|
||||||
var lines = addLinksToMap(linkDict, linkScale, links, router)
|
var lines = addLinksToMap(linkDict, linkScale, data.links, router)
|
||||||
L.featureGroup(lines).addTo(map)
|
L.featureGroup(lines).addTo(map)
|
||||||
|
|
||||||
var nodesOnline = subtract(nodes.filter(online), newnodes)
|
var nodesOnline = subtract(data.nodes.all.filter(online), data.nodes.new)
|
||||||
var nodesOffline = subtract(nodes.filter(offline), lostnodes)
|
var nodesOffline = subtract(data.nodes.all.filter(offline), data.nodes.lost)
|
||||||
|
|
||||||
var markersOnline = nodesOnline.filter(has_location)
|
var markersOnline = nodesOnline.filter(has_location)
|
||||||
.map(mkMarker(nodeDict, function () { return iconOnline }, router))
|
.map(mkMarker(nodeDict, function () { return iconOnline }, router))
|
||||||
|
@ -93,12 +93,12 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
|
||||||
var markersOffline = nodesOffline.filter(has_location)
|
var markersOffline = nodesOffline.filter(has_location)
|
||||||
.map(mkMarker(nodeDict, function () { return iconOffline }, router))
|
.map(mkMarker(nodeDict, function () { return iconOffline }, router))
|
||||||
|
|
||||||
var markersNew = newnodes.filter(has_location)
|
var markersNew = data.nodes.new.filter(has_location)
|
||||||
.map(mkMarker(nodeDict, function () { return iconNew }, router))
|
.map(mkMarker(nodeDict, function () { return iconNew }, router))
|
||||||
|
|
||||||
var markersLost = lostnodes.filter(has_location)
|
var markersLost = data.nodes.lost.filter(has_location)
|
||||||
.map(mkMarker(nodeDict, function (d) {
|
.map(mkMarker(nodeDict, function (d) {
|
||||||
if (d.lastseen.isAfter(moment(now).subtract(3, "days")))
|
if (d.lastseen.isAfter(moment(data.now).subtract(3, "days")))
|
||||||
return iconAlert
|
return iconAlert
|
||||||
|
|
||||||
return iconLost
|
return iconLost
|
||||||
|
|
|
@ -3,12 +3,12 @@ define(["moment"], function (moment) {
|
||||||
var self = this
|
var self = this
|
||||||
var p
|
var p
|
||||||
|
|
||||||
self.setData = function (nodes) {
|
self.setData = function (d) {
|
||||||
var totalNodes = sum(nodes.filter(online).map(one))
|
var totalNodes = sum(d.nodes.all.filter(online).map(one))
|
||||||
var totalClients = sum(nodes.filter(online).map( function (d) {
|
var totalClients = sum(d.nodes.all.filter(online).map( function (d) {
|
||||||
return d.statistics.clients
|
return d.statistics.clients
|
||||||
}))
|
}))
|
||||||
var totalGateways = sum(nodes.filter(online).filter( function (d) {
|
var totalGateways = sum(d.nodes.all.filter(online).filter( function (d) {
|
||||||
return d.flags.gateway
|
return d.flags.gateway
|
||||||
}).map(one))
|
}).map(one))
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ define(["moment"], function (moment) {
|
||||||
totalGateways + " Gateways"
|
totalGateways + " Gateways"
|
||||||
|
|
||||||
p.appendChild(document.createElement("br"))
|
p.appendChild(document.createElement("br"))
|
||||||
p.appendChild(document.createTextNode("Diese Daten sind von " + moment(nodes.timestamp).format("LLLL") + "."))
|
p.appendChild(document.createTextNode("Diese Daten sind von " + moment(d.timestamp).format("LLLL") + "."))
|
||||||
}
|
}
|
||||||
|
|
||||||
self.render = function (el) {
|
self.render = function (el) {
|
||||||
|
|
|
@ -27,8 +27,8 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
||||||
d.appendChild(el)
|
d.appendChild(el)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setData = function (now, nodes) {
|
self.setData = function (data) {
|
||||||
if (nodes.length === 0)
|
if (data.nodes.all.length === 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
var h2 = document.createElement("h2")
|
var h2 = document.createElement("h2")
|
||||||
|
@ -58,7 +58,7 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
||||||
|
|
||||||
var tbody = document.createElement("tbody")
|
var tbody = document.createElement("tbody")
|
||||||
|
|
||||||
nodes.forEach( function (d) {
|
data.nodes.all.forEach( function (d) {
|
||||||
var row = document.createElement("tr")
|
var row = document.createElement("tr")
|
||||||
|
|
||||||
var td1 = document.createElement("td")
|
var td1 = document.createElement("td")
|
||||||
|
@ -79,7 +79,7 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var td2 = document.createElement("td")
|
var td2 = document.createElement("td")
|
||||||
showUptime(td2, now, d)
|
showUptime(td2, data.now, d)
|
||||||
row.appendChild(td2)
|
row.appendChild(td2)
|
||||||
|
|
||||||
var td3 = document.createElement("td")
|
var td3 = document.createElement("td")
|
||||||
|
|
|
@ -105,15 +105,15 @@ define(function () {
|
||||||
|
|
||||||
self.addTarget = function (d) { targets.push(d) }
|
self.addTarget = function (d) { targets.push(d) }
|
||||||
|
|
||||||
self.setData = function (nodes, links) {
|
self.setData = function (data) {
|
||||||
objects.nodes = {}
|
objects.nodes = {}
|
||||||
objects.links = {}
|
objects.links = {}
|
||||||
|
|
||||||
nodes.forEach( function (d) {
|
data.nodes.all.forEach( function (d) {
|
||||||
objects.nodes[d.nodeinfo.node_id] = d
|
objects.nodes[d.nodeinfo.node_id] = d
|
||||||
})
|
})
|
||||||
|
|
||||||
links.forEach( function (d) {
|
data.links.forEach( function (d) {
|
||||||
objects.links[linkId(d)] = d
|
objects.links[linkId(d)] = d
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
define(["moment"], function (moment) {
|
define(["moment"], function (moment) {
|
||||||
return function(config, field, router, title) {
|
return function(config, nodes, field, router, title) {
|
||||||
var self = this
|
var self = this
|
||||||
var el
|
var el
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@ define(["moment"], function (moment) {
|
||||||
d.appendChild(el)
|
d.appendChild(el)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setData = function (list) {
|
self.setData = function (data) {
|
||||||
|
var list = data.nodes[nodes]
|
||||||
|
|
||||||
if (list.length === 0)
|
if (list.length === 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue