meshviewer/lib/legend.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

define(['helper'], function (helper) {
'use strict';
2016-05-27 21:59:01 +00:00
return function (language) {
var self = this;
var stats = document.createTextNode('');
var timestamp = document.createTextNode('');
2017-01-26 22:52:34 +00:00
self.setData = function setData(d) {
2017-10-31 12:32:39 +00:00
var totalNodes = Object.keys(d.nodeDict).length;
var totalOnlineNodes = d.nodes.online.length;
var totalClients = helper.sum(d.nodes.online.map(function (n) {
2017-10-29 19:52:17 +00:00
return n.clients;
2017-01-26 22:52:34 +00:00
}));
2017-10-31 12:32:39 +00:00
var totalGateways = helper.sum(d.nodes.online.filter(function (n) {
return n.is_gateway;
2017-01-26 22:52:34 +00:00
}).map(helper.one));
2017-02-04 15:14:24 +00:00
stats.textContent = _.t('sidebar.nodes', { total: totalNodes, online: totalOnlineNodes }) + ' ' +
_.t('sidebar.clients', { smart_count: totalClients }) + ' ' +
_.t('sidebar.gateway', { smart_count: totalGateways });
2017-01-26 22:52:34 +00:00
2017-10-29 10:00:22 +00:00
timestamp.textContent = _.t('sidebar.lastUpdate') + ' ' + d.timestamp.fromNow();
2017-01-26 22:52:34 +00:00
};
2015-08-26 23:31:19 +00:00
self.render = function render(el) {
2017-10-21 00:06:42 +00:00
var h1 = document.createElement('h1');
h1.textContent = config.siteName;
el.appendChild(h1);
2017-01-26 22:52:34 +00:00
language.languageSelect(el);
var p = document.createElement('p');
p.classList.add('legend');
2017-01-26 22:52:34 +00:00
p.appendChild(stats);
p.appendChild(document.createElement('br'));
2017-01-26 22:52:34 +00:00
p.appendChild(timestamp);
2018-05-23 22:51:41 +00:00
if (config.linkList) {
p.appendChild(document.createElement('br'));
config.linkList.forEach(function (link) {
var a = document.createElement('a');
a.innerText = link.title;
a.href = link.href;
p.appendChild(a);
});
}
el.appendChild(p);
};
2015-08-26 23:31:19 +00:00
return self;
};
});