2016-05-26 16:37:24 +00:00
|
|
|
define(["helper"], function (helper) {
|
2015-07-08 14:32:26 +00:00
|
|
|
return function (config) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var self = this;
|
|
|
|
var stats, timestamp;
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2015-03-29 15:48:25 +00:00
|
|
|
self.setData = function (d) {
|
2016-05-26 16:37:24 +00:00
|
|
|
var totalNodes = helper.sum(d.nodes.all.map(helper.one));
|
|
|
|
var totalOnlineNodes = helper.sum(d.nodes.all.filter(helper.online).map(helper.one));
|
|
|
|
var totalNewNodes = helper.sum(d.nodes.new.map(helper.one));
|
|
|
|
var totalLostNodes = helper.sum(d.nodes.lost.map(helper.one));
|
|
|
|
var totalClients = helper.sum(d.nodes.all.filter(helper.online).map(function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return d.statistics.clients ? d.statistics.clients : 0;
|
|
|
|
}));
|
2016-05-26 16:37:24 +00:00
|
|
|
var totalGateways = helper.sum(d.nodes.all.filter(helper.online).filter(function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return d.flags.gateway;
|
2016-05-26 16:37:24 +00:00
|
|
|
}).map(helper.one));
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var nodetext = [{count: totalOnlineNodes, label: "online"},
|
|
|
|
{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(", ");
|
2015-07-08 21:31:54 +00:00
|
|
|
|
|
|
|
stats.textContent = totalNodes + " Knoten " +
|
2016-05-22 12:51:30 +00:00
|
|
|
"(" + nodetext + "), " +
|
|
|
|
totalClients + " Client" + ( totalClients === 1 ? ", " : "s, " ) +
|
|
|
|
totalGateways + " Gateways";
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
timestamp.textContent = "Diese Daten sind von " + d.timestamp.format("LLLL") + ".";
|
|
|
|
};
|
2015-03-25 14:33:36 +00:00
|
|
|
|
|
|
|
self.render = function (el) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var h2 = document.createElement("h2");
|
|
|
|
h2.textContent = config.siteName;
|
|
|
|
el.appendChild(h2);
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var p = document.createElement("p");
|
|
|
|
el.appendChild(p);
|
|
|
|
stats = document.createTextNode("");
|
|
|
|
p.appendChild(stats);
|
|
|
|
p.appendChild(document.createElement("br"));
|
|
|
|
timestamp = document.createTextNode("");
|
|
|
|
p.appendChild(timestamp);
|
|
|
|
};
|
2015-03-25 14:33:36 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|