2017-01-28 14:33:13 +00:00
|
|
|
define(['chroma-js', 'moment', 'tablesort', 'helper'],
|
|
|
|
function (chroma, moment, Tablesort, helper) {
|
2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showGeoURI(d) {
|
2016-05-26 16:37:24 +00:00
|
|
|
if (!helper.hasLocation(d)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return function (el) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var a = document.createElement('a');
|
|
|
|
a.textContent = Number(d.nodeinfo.location.latitude.toFixed(6)) + ', ' + Number(d.nodeinfo.location.longitude.toFixed(6));
|
|
|
|
a.href = 'geo:' + d.nodeinfo.location.latitude + ',' + d.nodeinfo.location.longitude;
|
2016-05-22 12:51:30 +00:00
|
|
|
el.appendChild(a);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function showStatus(d) {
|
|
|
|
return function (el) {
|
2017-01-29 23:51:08 +00:00
|
|
|
el.classList.add(d.flags.unseen ? 'unseen' : (d.flags.online ? 'online' : 'offline'));
|
2016-05-22 12:51:30 +00:00
|
|
|
if (d.flags.online) {
|
2017-01-28 14:33:13 +00:00
|
|
|
el.textContent = _.t('node.lastOnline', {
|
|
|
|
time: d.lastseen.fromNow(),
|
|
|
|
date: d.lastseen.format('DD.MM.YYYY, H:mm:ss')
|
|
|
|
});
|
2016-05-22 12:51:30 +00:00
|
|
|
} else {
|
2017-01-28 14:33:13 +00:00
|
|
|
el.textContent = _.t('node.lastOffline', {
|
|
|
|
time: d.lastseen.fromNow(),
|
|
|
|
date: d.lastseen.format('DD.MM.YYYY, H:mm:ss')
|
|
|
|
});
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
};
|
2015-04-11 11:48:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showFirmware(d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var release = helper.dictGet(d.nodeinfo, ['software', 'firmware', 'release']);
|
|
|
|
var base = helper.dictGet(d.nodeinfo, ['software', 'firmware', 'base']);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
if (release === null || base === null) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2015-04-11 11:48:16 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
return release + ' / ' + base;
|
2015-04-11 11:48:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showSite(d, config) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var site = helper.dictGet(d.nodeinfo, ['system', 'site_code']);
|
2016-05-22 12:51:30 +00:00
|
|
|
var rt = site;
|
|
|
|
if (config.siteNames) {
|
|
|
|
config.siteNames.forEach(function (t) {
|
|
|
|
if (site === t.site) {
|
|
|
|
rt = t.name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return rt;
|
|
|
|
}
|
2015-04-11 11:48:16 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showUptime(d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
if (!('uptime' in d.statistics)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2015-04-11 11:48:16 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
return moment.duration(d.statistics.uptime, 'seconds').humanize();
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-06 23:00:30 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showFirstseen(d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
if (!('firstseen' in d)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return d.firstseen.fromNow(true);
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showClients(d) {
|
|
|
|
if (!d.flags.online) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (el) {
|
2017-01-28 14:33:13 +00:00
|
|
|
el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : _.t('none')));
|
2017-01-29 23:51:08 +00:00
|
|
|
el.appendChild(document.createElement('br'));
|
2015-07-18 14:28:07 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var span = document.createElement('span');
|
|
|
|
span.classList.add('clients');
|
|
|
|
span.innerHTML = '<i class="ion-ios-person"></i>'.repeat(d.statistics.clients);
|
2016-05-22 12:51:30 +00:00
|
|
|
el.appendChild(span);
|
|
|
|
};
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showIPs(d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var ips = helper.dictGet(d.nodeinfo, ['network', 'addresses']);
|
2016-05-22 12:51:30 +00:00
|
|
|
if (ips === null) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
ips.sort();
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (el) {
|
|
|
|
ips.forEach(function (ip, i) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var link = !ip.startsWith('fe80:');
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (i > 0) {
|
2017-01-29 23:51:08 +00:00
|
|
|
el.appendChild(document.createElement('br'));
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (link) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var a = document.createElement('a');
|
|
|
|
a.href = 'http://[' + ip + ']/';
|
2016-05-22 12:51:30 +00:00
|
|
|
a.textContent = ip;
|
|
|
|
el.appendChild(a);
|
|
|
|
} else {
|
|
|
|
el.appendChild(document.createTextNode(ip));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
|
2016-06-03 17:44:07 +00:00
|
|
|
function showBar(v) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var span = document.createElement('span');
|
|
|
|
span.classList.add('bar');
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var bar = document.createElement('span');
|
|
|
|
bar.style.width = (v * 100) + '%';
|
2016-05-22 12:51:30 +00:00
|
|
|
span.appendChild(bar);
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var label = document.createElement('label');
|
|
|
|
label.textContent = (Math.round(v * 100)) + ' %';
|
2016-05-22 12:51:30 +00:00
|
|
|
span.appendChild(label);
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return span;
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2017-01-07 15:09:35 +00:00
|
|
|
function showLoadBar(v, p) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var span = document.createElement('span');
|
|
|
|
span.classList.add('bar');
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var bar = document.createElement('span');
|
|
|
|
bar.style.width = ((v * 100) % 100) + '%';
|
2017-01-07 15:09:35 +00:00
|
|
|
if (v >= p) {
|
2017-01-29 23:51:08 +00:00
|
|
|
span.classList.add('warning');
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2016-06-03 17:44:07 +00:00
|
|
|
span.appendChild(bar);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var label = document.createElement('label');
|
2016-05-22 12:51:30 +00:00
|
|
|
label.textContent = (v);
|
|
|
|
span.appendChild(label);
|
|
|
|
|
|
|
|
return span;
|
2016-02-25 13:44:11 +00:00
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
function showLoad(d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
if (!('loadavg' in d.statistics)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return function (el) {
|
2017-01-07 15:09:35 +00:00
|
|
|
el.appendChild(showLoadBar(d.statistics.loadavg.toFixed(2), d.nodeinfo.hardware.nproc));
|
2016-05-22 12:51:30 +00:00
|
|
|
};
|
2016-02-25 13:44:11 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showRAM(d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
if (!('memory_usage' in d.statistics)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2016-02-25 13:44:11 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (el) {
|
2016-06-03 17:44:07 +00:00
|
|
|
el.appendChild(showBar(d.statistics.memory_usage));
|
2016-05-22 12:51:30 +00:00
|
|
|
};
|
|
|
|
}
|
2016-02-25 13:44:11 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showAutoupdate(d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var au = helper.dictGet(d.nodeinfo, ['software', 'autoupdater']);
|
2016-05-22 12:51:30 +00:00
|
|
|
if (!au) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2017-01-28 14:33:13 +00:00
|
|
|
return au.enabled ? _.t('node.activated', {branch: au.branch}) : _.t('node.deactivated');
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showStatImg(o, d) {
|
|
|
|
var subst = {};
|
2017-01-28 14:33:13 +00:00
|
|
|
subst['{NODE_ID}'] = d.nodeinfo.node_id ? d.nodeinfo.node_id : _.t('unknown');
|
|
|
|
subst['{NODE_NAME}'] = d.nodeinfo.hostname ? d.nodeinfo.hostname.replace(/[^a-z0-9\-]/ig, '_') : _.t('unknown');
|
2017-01-29 23:51:08 +00:00
|
|
|
subst['{TIME}'] = d.lastseen.format('DDMMYYYYHmmss');
|
2017-01-28 14:33:13 +00:00
|
|
|
subst['{LOCALE}'] = _.locale();
|
2016-05-26 16:37:24 +00:00
|
|
|
return helper.showStat(o, subst);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-03-25 10:21:09 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (config, el, router, d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var linkScale = chroma.scale(chroma.bezier(['#04C714', '#FF5500', '#F02311'])).domain([1, 5]);
|
|
|
|
var h2 = document.createElement('h2');
|
2016-05-22 12:51:30 +00:00
|
|
|
h2.textContent = d.nodeinfo.hostname;
|
|
|
|
el.appendChild(h2);
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var attributes = document.createElement('table');
|
|
|
|
attributes.classList.add('attributes');
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.attributeEntry(attributes, 'node.status', showStatus(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.gateway', d.flags.gateway ? 'ja' : null);
|
|
|
|
helper.attributeEntry(attributes, 'node.coordinates', showGeoURI(d));
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-21 00:53:55 +00:00
|
|
|
if (config.nodeInfobox && config.nodeInfobox.contact) {
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.attributeEntry(attributes, 'node.contact', helper.dictGet(d.nodeinfo, ['owner', 'contact']));
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.attributeEntry(attributes, 'node.hardware', helper.dictGet(d.nodeinfo, ['hardware', 'model']));
|
|
|
|
helper.attributeEntry(attributes, 'node.primaryMac', helper.dictGet(d.nodeinfo, ['network', 'mac']));
|
|
|
|
helper.attributeEntry(attributes, 'node.id', helper.dictGet(d.nodeinfo, ['node_id']));
|
|
|
|
helper.attributeEntry(attributes, 'node.firmware', showFirmware(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.site', showSite(d, config));
|
|
|
|
helper.attributeEntry(attributes, 'node.uptime', showUptime(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.firstSeen', showFirstseen(d));
|
2017-01-21 00:53:55 +00:00
|
|
|
if (config.nodeInfobox && config.nodeInfobox.hardwareUsage) {
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.attributeEntry(attributes, 'node.systemLoad', showLoad(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.ram', showRAM(d));
|
2017-01-21 00:53:55 +00:00
|
|
|
}
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.attributeEntry(attributes, 'node.ipAddresses', showIPs(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.selectedGateway', helper.dictGet(d.statistics, ['gateway']));
|
|
|
|
helper.attributeEntry(attributes, 'node.update', showAutoupdate(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.clients', showClients(d));
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
el.appendChild(attributes);
|
|
|
|
|
|
|
|
if (config.nodeInfos) {
|
|
|
|
config.nodeInfos.forEach(function (nodeInfo) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var h4 = document.createElement('h4');
|
2016-05-22 12:51:30 +00:00
|
|
|
h4.textContent = nodeInfo.name;
|
|
|
|
el.appendChild(h4);
|
|
|
|
el.appendChild(showStatImg(nodeInfo, d));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d.neighbours.length > 0) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var h3 = document.createElement('h3');
|
2017-01-28 14:33:13 +00:00
|
|
|
h3.textContent = _.t('node.link', d.neighbours.length) + '(' + d.neighbours.length + ')';
|
2016-05-22 12:51:30 +00:00
|
|
|
el.appendChild(h3);
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var table = document.createElement('table');
|
|
|
|
var thead = document.createElement('thead');
|
2016-02-18 17:42:42 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var tr = document.createElement('tr');
|
|
|
|
var th1 = document.createElement('th');
|
|
|
|
th1.textContent = ' ';
|
2016-05-22 12:51:30 +00:00
|
|
|
tr.appendChild(th1);
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var th2 = document.createElement('th');
|
2017-01-28 14:33:13 +00:00
|
|
|
th2.textContent = _.t('node.node', d.neighbours.length);
|
2017-01-29 23:51:08 +00:00
|
|
|
th2.classList.add('sort-default');
|
2016-05-22 12:51:30 +00:00
|
|
|
tr.appendChild(th2);
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var th3 = document.createElement('th');
|
2017-01-28 14:33:13 +00:00
|
|
|
th3.textContent = _.t('node.tq');
|
2016-05-22 12:51:30 +00:00
|
|
|
tr.appendChild(th3);
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var th4 = document.createElement('th');
|
2017-01-28 14:33:13 +00:00
|
|
|
th4.textContent = _.t('node.distance');
|
2016-05-22 12:51:30 +00:00
|
|
|
tr.appendChild(th4);
|
|
|
|
|
|
|
|
thead.appendChild(tr);
|
|
|
|
table.appendChild(thead);
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var tbody = document.createElement('tbody');
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
d.neighbours.forEach(function (n) {
|
|
|
|
var unknown = !(n.node);
|
|
|
|
var tr1 = document.createElement('tr');
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var td1 = document.createElement('td');
|
2016-05-26 23:34:42 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var direction = document.createElement('span');
|
|
|
|
direction.classList.add(n.incoming ? 'ion-ios-arrow-thin-left' : 'ion-ios-arrow-thin-right');
|
2016-05-26 23:34:42 +00:00
|
|
|
td1.appendChild(direction);
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
if (!unknown && helper.hasLocation(n.node)) {
|
|
|
|
var span = document.createElement('span');
|
|
|
|
span.classList.add('ion-location');
|
2016-05-26 23:34:42 +00:00
|
|
|
td1.appendChild(span);
|
|
|
|
}
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
tr1.appendChild(td1);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var td2 = document.createElement('td');
|
2016-06-03 19:04:48 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (!unknown) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var a1 = document.createElement('a');
|
|
|
|
a1.textContent = n.node.nodeinfo.hostname;
|
|
|
|
a1.classList.add('online');
|
|
|
|
a1.href = '#';
|
|
|
|
a1.onclick = router.node(n.node);
|
2016-06-03 19:04:48 +00:00
|
|
|
td2.appendChild(a1);
|
|
|
|
} else {
|
2017-01-29 23:51:08 +00:00
|
|
|
td2.textContent = n.id;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2016-06-22 01:15:53 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
tr1.appendChild(td2);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var td3 = document.createElement('td');
|
|
|
|
td3.textContent = helper.showTq(n.link);
|
|
|
|
td3.style.color = linkScale(n.link.tq).hex();
|
|
|
|
tr1.appendChild(td3);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var td4 = document.createElement('td');
|
|
|
|
td4.textContent = helper.showDistance(n.link);
|
|
|
|
td4.setAttribute('data-sort', n.link.distance !== undefined ? -n.link.distance : 1);
|
|
|
|
tr1.appendChild(td4);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
tbody.appendChild(tr);
|
|
|
|
});
|
|
|
|
|
|
|
|
table.appendChild(tbody);
|
2017-01-29 23:51:08 +00:00
|
|
|
table.classList.add('node-links');
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
tablesort(table);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
el.appendChild(table);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|