2017-01-29 23:51:08 +00:00
|
|
|
define(['helper'], function (helper) {
|
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
2017-01-26 22:52:34 +00:00
|
|
|
return function (config) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var self = this;
|
2017-01-29 23:51:08 +00:00
|
|
|
var stats = document.createTextNode('');
|
|
|
|
var timestamp = document.createTextNode('');
|
2017-01-26 22:52:34 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.setData = function setData(d) {
|
2017-01-26 22:52:34 +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));
|
2017-01-29 23:51:08 +00:00
|
|
|
var totalClients = helper.sum(d.nodes.all.filter(helper.online).map(function (n) {
|
|
|
|
return n.statistics.clients ? n.statistics.clients : 0;
|
2017-01-26 22:52:34 +00:00
|
|
|
}));
|
2017-01-29 23:51:08 +00:00
|
|
|
var totalGateways = helper.sum(d.nodes.all.filter(helper.online).filter(function (n) {
|
|
|
|
return n.flags.gateway;
|
2017-01-26 22:52:34 +00:00
|
|
|
}).map(helper.one));
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
stats.textContent = totalNodes + ' Knoten, ' +
|
|
|
|
'davon ' + totalOnlineNodes + ' Knoten online ' +
|
|
|
|
'mit ' + totalClients + ' Client' + ( totalClients === 1 ? ' ' : 's ' ) +
|
|
|
|
'auf ' + totalGateways + ' Gateway' + ( totalGateways === 1 ? '' : 's' );
|
2017-01-26 22:52:34 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
timestamp.textContent = 'Stand: ' + d.timestamp.format('DD.MM.Y HH:mm');
|
2017-01-26 22:52:34 +00:00
|
|
|
};
|
2015-08-26 23:31:19 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.render = function render(el) {
|
|
|
|
var h2 = document.createElement('h2');
|
2017-01-26 22:52:34 +00:00
|
|
|
h2.textContent = config.siteName;
|
|
|
|
el.appendChild(h2);
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var p = document.createElement('p');
|
|
|
|
p.classList.add('legend');
|
2017-01-20 14:06:06 +00:00
|
|
|
p.innerHTML = '<span class="legend-new"><span class="symbol"></span> Neuer Knoten</span>' +
|
|
|
|
'<span class="legend-online"><span class="symbol"></span> Knoten ist online</span>' +
|
|
|
|
'<span class="legend-offline"><span class="symbol"></span> Knoten ist offline</span>';
|
2016-05-22 11:23:43 +00:00
|
|
|
el.appendChild(p);
|
2017-01-26 22:52:34 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
p.appendChild(document.createElement('br'));
|
2017-01-26 22:52:34 +00:00
|
|
|
p.appendChild(stats);
|
2017-01-29 23:51:08 +00:00
|
|
|
p.appendChild(document.createElement('br'));
|
2017-01-26 22:52:34 +00:00
|
|
|
p.appendChild(timestamp);
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-08-26 23:31:19 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|