2015-03-29 19:10:24 +02:00
|
|
|
define(function () {
|
2015-07-08 16:32:26 +02:00
|
|
|
return function (config) {
|
2015-03-25 15:33:36 +01:00
|
|
|
var self = this
|
2015-04-02 19:59:07 +02:00
|
|
|
var stats, timestamp
|
2015-03-25 15:33:36 +01:00
|
|
|
|
2015-03-29 17:48:25 +02:00
|
|
|
self.setData = function (d) {
|
2015-06-04 14:36:59 +02:00
|
|
|
var totalNodes = sum(d.nodes.all.map(one))
|
|
|
|
var totalOnlineNodes = sum(d.nodes.all.filter(online).map(one))
|
2016-06-03 00:43:08 +02:00
|
|
|
var totalOfflineNodes = sum(d.nodes.all.filter(function (node) {return !node.flags.online}).map(one))
|
2015-07-08 23:31:54 +02:00
|
|
|
var totalNewNodes = sum(d.nodes.new.map(one))
|
|
|
|
var totalLostNodes = sum(d.nodes.lost.map(one))
|
2015-03-29 17:48:25 +02:00
|
|
|
var totalClients = sum(d.nodes.all.filter(online).map( function (d) {
|
2016-05-22 00:25:46 +02:00
|
|
|
return d.statistics.clients ? d.statistics.clients : 0
|
2015-03-25 15:33:36 +01:00
|
|
|
}))
|
2016-06-02 22:43:53 +02:00
|
|
|
var totalGateways = sum(Array.from(new Set(d.nodes.all.filter(online).map( function(d) {
|
|
|
|
return d.statistics.gateway
|
|
|
|
}).concat(d.nodes.all.filter( function (d) {
|
2015-11-06 21:10:43 +01:00
|
|
|
return d.flags.gateway
|
2016-06-02 23:17:06 +02:00
|
|
|
})))).map(function(d) {
|
|
|
|
return (typeof d === "string") ? 1 : 0
|
|
|
|
}))
|
2015-03-25 15:33:36 +01:00
|
|
|
|
2015-07-08 23:31:54 +02:00
|
|
|
var nodetext = [{ count: totalOnlineNodes, label: "online" },
|
2016-06-03 00:43:08 +02:00
|
|
|
{ count: totalOfflineNodes, label: "offline" },
|
2015-07-08 23:31:54 +02:00
|
|
|
{ count: totalNewNodes, label: "neu" },
|
|
|
|
{ count: totalLostNodes, label: "verschwunden" }
|
|
|
|
].filter( function (d) { return d.count > 0 } )
|
|
|
|
.map( function (d) { return [d.count, d.label].join(" ") } )
|
|
|
|
.join(", ")
|
|
|
|
|
|
|
|
stats.textContent = totalNodes + " Knoten " +
|
2015-11-06 21:10:43 +01:00
|
|
|
"(" + nodetext + "), " +
|
|
|
|
totalClients + " Client" + ( totalClients === 1 ? ", " : "s, " ) +
|
|
|
|
totalGateways + " Gateways"
|
2015-03-25 15:33:36 +01:00
|
|
|
|
2015-04-02 19:59:07 +02:00
|
|
|
timestamp.textContent = "Diese Daten sind von " + d.timestamp.format("LLLL") + "."
|
2015-03-25 15:33:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self.render = function (el) {
|
|
|
|
var h2 = document.createElement("h2")
|
2015-07-08 16:32:26 +02:00
|
|
|
h2.textContent = config.siteName
|
2015-03-25 15:33:36 +01:00
|
|
|
el.appendChild(h2)
|
|
|
|
|
2015-04-02 19:59:07 +02:00
|
|
|
var p = document.createElement("p")
|
2015-03-25 15:33:36 +01:00
|
|
|
el.appendChild(p)
|
2015-04-02 19:59:07 +02:00
|
|
|
stats = document.createTextNode("")
|
|
|
|
p.appendChild(stats)
|
|
|
|
p.appendChild(document.createElement("br"))
|
|
|
|
timestamp = document.createTextNode("")
|
|
|
|
p.appendChild(timestamp)
|
2015-03-25 15:33:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
})
|