2017-02-18 22:13:29 +00:00
|
|
|
define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
|
2017-03-09 23:53:23 +00:00
|
|
|
function (SortTable, V, d3Interpolate, moment, helper) {
|
2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2017-02-18 22:13:29 +00:00
|
|
|
V = V.default;
|
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;
|
|
|
|
}
|
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
return V.h('td',
|
|
|
|
V.h('a',
|
|
|
|
{ props: { href: 'geo:' + d.location.latitude + ',' + d.location.longitude } },
|
|
|
|
Number(d.location.latitude.toFixed(6)) + ', ' + Number(d.location.longitude.toFixed(6))
|
|
|
|
)
|
|
|
|
);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showStatus(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
return V.h('td',
|
2017-10-29 19:52:17 +00:00
|
|
|
{ props: { className: d.is_online ? 'online' : 'offline' } },
|
2017-10-29 14:11:24 +00:00
|
|
|
_.t((d.is_online ? 'node.lastOnline' : 'node.lastOffline'), {
|
2017-02-12 21:18:23 +00:00
|
|
|
time: d.lastseen.fromNow(),
|
|
|
|
date: d.lastseen.format('DD.MM.YYYY, H:mm:ss')
|
2017-10-29 14:11:24 +00:00
|
|
|
}));
|
2015-04-11 11:48:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showFirmware(d) {
|
2017-09-05 21:37:59 +00:00
|
|
|
return [
|
2017-10-29 14:11:24 +00:00
|
|
|
helper.dictGet(d, ['firmware', 'release']),
|
|
|
|
helper.dictGet(d, ['firmware', 'base'])
|
2017-09-05 21:37:59 +00:00
|
|
|
].filter(function (n) {
|
|
|
|
return n !== null;
|
|
|
|
}).join(' / ') || undefined;
|
2015-04-11 11:48:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showSite(d, config) {
|
2017-10-29 19:52:17 +00:00
|
|
|
var rt = d.site_code;
|
2016-05-22 12:51:30 +00:00
|
|
|
if (config.siteNames) {
|
|
|
|
config.siteNames.forEach(function (t) {
|
2017-10-29 19:52:17 +00:00
|
|
|
if (d.site_code === t.site) {
|
2016-05-22 12:51:30 +00:00
|
|
|
rt = t.name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-10-29 19:52:17 +00:00
|
|
|
return rt;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showClients(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
if (!d.is_online) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
var clients = [
|
2017-10-15 19:59:31 +00:00
|
|
|
V.h('span', [
|
|
|
|
d.clients > 0 ? d.clients : _.t('none'),
|
|
|
|
V.h('br'),
|
|
|
|
V.h('i', { props: { className: 'ion-people', title: _.t('node.clients') } })
|
|
|
|
]),
|
2017-10-28 23:38:43 +00:00
|
|
|
V.h('span',
|
2017-10-29 15:10:25 +00:00
|
|
|
{ props: { className: 'legend-24ghz' } },
|
2017-10-28 23:38:43 +00:00
|
|
|
[
|
|
|
|
d.clients_wifi24,
|
|
|
|
V.h('br'),
|
2017-10-29 15:10:25 +00:00
|
|
|
V.h('span', { props: { className: 'symbol', title: '2,4 Ghz' } })
|
2017-10-28 23:38:43 +00:00
|
|
|
]),
|
|
|
|
V.h('span',
|
2017-10-29 15:10:25 +00:00
|
|
|
{ props: { className: 'legend-5ghz' } },
|
2017-10-28 23:38:43 +00:00
|
|
|
[
|
|
|
|
d.clients_wifi5,
|
|
|
|
V.h('br'),
|
2017-10-29 15:10:25 +00:00
|
|
|
V.h('span', { props: { className: 'symbol', title: '5 Ghz' } })
|
2017-10-28 23:38:43 +00:00
|
|
|
]),
|
|
|
|
V.h('span',
|
2017-10-29 15:10:25 +00:00
|
|
|
{ props: { className: 'legend-others' } },
|
2017-10-28 23:38:43 +00:00
|
|
|
[
|
|
|
|
d.clients_other,
|
|
|
|
V.h('br'),
|
2017-10-29 15:10:25 +00:00
|
|
|
V.h('span', { props: { className: 'symbol', title: _.t('others') } })
|
2017-10-28 23:38:43 +00:00
|
|
|
])
|
2017-10-29 14:11:24 +00:00
|
|
|
];
|
2015-07-18 14:28:07 +00:00
|
|
|
|
2017-10-15 19:59:31 +00:00
|
|
|
return V.h('td', { props: { className: 'clients' } }, clients);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showIPs(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
var string = [];
|
2017-10-29 19:52:17 +00:00
|
|
|
var ips = d.network.addresses;
|
|
|
|
ips.sort();
|
2017-10-29 14:11:24 +00:00
|
|
|
ips.forEach(function (ip, i) {
|
|
|
|
if (i > 0) {
|
|
|
|
string.push(V.h('br'));
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2017-10-29 19:52:17 +00:00
|
|
|
if (!ip.startsWith('fe80:')) {
|
2017-10-29 14:11:24 +00:00
|
|
|
string.push(V.h('a', { props: { href: 'http://[' + ip + ']/', target: '_blank' } }, ip));
|
|
|
|
} else {
|
|
|
|
string.push(ip);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return V.h('td', string);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
|
2017-02-12 21:18:23 +00:00
|
|
|
function showBar(v, width, warning) {
|
2017-10-29 14:11:24 +00:00
|
|
|
return V.h('span',
|
|
|
|
{ props: { className: 'bar' + (warning ? ' warning' : '') } },
|
|
|
|
[
|
|
|
|
V.h('span',
|
|
|
|
{
|
|
|
|
style: { width: (width * 100) + '%' }
|
|
|
|
}),
|
|
|
|
V.h('label', v)
|
|
|
|
]
|
|
|
|
);
|
2016-02-25 13:44:11 +00:00
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
function showLoad(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
if (!('loadavg' in d)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2017-10-29 19:52:17 +00:00
|
|
|
return showBar(d.loadavg.toFixed(2), d.loadavg % 1, d.loadavg >= d.nproc);
|
2016-02-25 13:44:11 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showRAM(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
if (!('memory_usage' in d)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2017-10-29 19:52:17 +00:00
|
|
|
return showBar(Math.round(d.memory_usage * 100) + ' %', d.memory_usage, d.memory_usage >= 0.8);
|
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-10-29 19:52:17 +00:00
|
|
|
return d.autoupdater.enabled ? _.t('node.activated', { branch: d.autoupdater.branch }) : _.t('node.deactivated');
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showStatImg(o, d) {
|
|
|
|
var subst = {};
|
2017-10-29 14:11:24 +00:00
|
|
|
subst['{NODE_ID}'] = d.node_id;
|
|
|
|
subst['{NODE_NAME}'] = d.hostname.replace(/[^a-z0-9\-]/ig, '_');
|
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();
|
2017-10-29 14:11:24 +00:00
|
|
|
return helper.showStat(V, o, subst);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-03-25 10:21:09 +00:00
|
|
|
|
2017-10-29 15:10:25 +00:00
|
|
|
return function (config, el, router, d, linkScale, nodeDict) {
|
|
|
|
function nodeLink(node) {
|
|
|
|
return V.h('a', {
|
2017-02-18 22:13:29 +00:00
|
|
|
props: {
|
2017-10-29 15:10:25 +00:00
|
|
|
className: node.is_online ? 'online' : 'offline',
|
|
|
|
href: router.generateLink({ node: node.node_id })
|
2017-02-18 22:13:29 +00:00
|
|
|
}, on: {
|
|
|
|
click: function (e) {
|
2017-10-29 15:10:25 +00:00
|
|
|
router.fullUrl({ node: node.node_id }, e);
|
2017-02-18 22:13:29 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-29 15:10:25 +00:00
|
|
|
}, node.hostname);
|
|
|
|
}
|
|
|
|
|
2017-10-29 19:52:17 +00:00
|
|
|
function nodeIdLink(nodeId) {
|
|
|
|
if (nodeDict[nodeId]) {
|
|
|
|
return nodeLink(nodeDict[nodeId]);
|
2017-10-29 15:10:25 +00:00
|
|
|
}
|
2017-10-29 19:52:17 +00:00
|
|
|
return nodeId;
|
2017-10-29 15:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showGateway(node) {
|
|
|
|
var gatewayCols = [
|
|
|
|
V.h('span', [
|
2017-10-29 19:52:17 +00:00
|
|
|
nodeIdLink(node.gateway_nexthop),
|
2017-10-29 15:10:25 +00:00
|
|
|
V.h('br'),
|
|
|
|
_.t('node.nexthop')
|
|
|
|
]),
|
|
|
|
V.h('span', { props: { className: 'ion-arrow-right-c' } }),
|
|
|
|
V.h('span', [
|
2017-10-29 19:52:17 +00:00
|
|
|
nodeIdLink(node.gateway),
|
2017-10-29 15:10:25 +00:00
|
|
|
V.h('br'),
|
|
|
|
'IPv4'
|
|
|
|
]),
|
|
|
|
V.h('span', [
|
2017-10-29 19:52:17 +00:00
|
|
|
nodeIdLink(node.gateway6),
|
2017-10-29 15:10:25 +00:00
|
|
|
V.h('br'),
|
|
|
|
'IPv6'
|
|
|
|
])
|
|
|
|
];
|
|
|
|
|
|
|
|
return V.h('td', { props: { className: 'gateway' } }, gatewayCols);
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderNeighbourRow(n) {
|
2017-10-29 19:14:09 +00:00
|
|
|
var icons = '';
|
2017-10-29 15:10:25 +00:00
|
|
|
if (helper.hasLocation(n.node)) {
|
2017-10-29 19:14:09 +00:00
|
|
|
icons = V.h('span', { props: { className: 'ion-location' } });
|
2017-10-29 15:10:25 +00:00
|
|
|
}
|
2017-02-04 17:59:21 +00:00
|
|
|
|
2017-10-29 19:52:17 +00:00
|
|
|
return V.h('tr', [
|
|
|
|
V.h('td', icons),
|
|
|
|
V.h('td', nodeLink(n.node)),
|
|
|
|
V.h('td', n.node.clients),
|
|
|
|
V.h('td', { style: { color: linkScale((n.link.source_tq + n.link.target_tq) / 2) } }, helper.showTq(n.link.source_tq) + ' - ' + helper.showTq(n.link.target_tq)),
|
|
|
|
V.h('td', helper.showDistance(n.link))
|
|
|
|
]);
|
2017-02-04 17:59:21 +00:00
|
|
|
}
|
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
var self = this;
|
|
|
|
var header = document.createElement('h2');
|
|
|
|
var table = document.createElement('table');
|
|
|
|
var images = document.createElement('div');
|
|
|
|
var neighbours = document.createElement('h3');
|
|
|
|
var headings = [{
|
|
|
|
name: ''
|
|
|
|
}, {
|
|
|
|
name: 'node.nodes',
|
|
|
|
sort: function (a, b) {
|
|
|
|
return a.node.hostname.localeCompare(b.node.hostname);
|
|
|
|
},
|
|
|
|
reverse: false
|
|
|
|
}, {
|
|
|
|
name: 'node.clients',
|
|
|
|
class: 'ion-people',
|
|
|
|
sort: function (a, b) {
|
2017-10-29 19:52:17 +00:00
|
|
|
return a.node.clients - b.node.clients;
|
2017-10-29 14:11:24 +00:00
|
|
|
},
|
|
|
|
reverse: true
|
|
|
|
}, {
|
|
|
|
name: 'node.tq',
|
|
|
|
class: 'ion-connection-bars',
|
|
|
|
sort: function (a, b) {
|
|
|
|
return a.link.source_tq - b.link.source_tq;
|
|
|
|
},
|
|
|
|
reverse: true
|
|
|
|
}, {
|
|
|
|
name: 'node.distance',
|
|
|
|
class: 'ion-arrow-resize',
|
|
|
|
sort: function (a, b) {
|
|
|
|
return (a.link.distance === undefined ? -1 : a.link.distance) -
|
|
|
|
(b.link.distance === undefined ? -1 : b.link.distance);
|
|
|
|
},
|
|
|
|
reverse: true
|
|
|
|
}];
|
|
|
|
var tableNeighbour = new SortTable(headings, 1, renderNeighbourRow);
|
|
|
|
|
|
|
|
el.appendChild(header);
|
|
|
|
el.appendChild(table);
|
|
|
|
el.appendChild(neighbours);
|
|
|
|
el.appendChild(tableNeighbour.el);
|
|
|
|
el.appendChild(images);
|
|
|
|
|
|
|
|
self.render = function render() {
|
|
|
|
V.patch(header, V.h('h2', d.hostname));
|
|
|
|
|
|
|
|
var children = [];
|
|
|
|
|
|
|
|
children.push(helper.attributeEntry(V, 'node.status', showStatus(d)));
|
2017-10-29 19:52:17 +00:00
|
|
|
children.push(helper.attributeEntry(V, 'node.gateway', d.is_gateway ? 'ja' : undefined));
|
2017-10-29 14:11:24 +00:00
|
|
|
children.push(helper.attributeEntry(V, 'node.coordinates', showGeoURI(d)));
|
|
|
|
|
|
|
|
if (config.nodeInfobox && config.nodeInfobox.contact) {
|
|
|
|
children.push(helper.attributeEntry(V, 'node.contact', helper.dictGet(d, ['owner', 'contact'])));
|
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-10-29 19:52:17 +00:00
|
|
|
children.push(helper.attributeEntry(V, 'node.hardware', d.model));
|
|
|
|
children.push(helper.attributeEntry(V, 'node.primaryMac', d.network.mac));
|
2017-10-29 14:11:24 +00:00
|
|
|
children.push(helper.attributeEntry(V, 'node.firmware', showFirmware(d)));
|
|
|
|
children.push(helper.attributeEntry(V, 'node.site', showSite(d, config)));
|
2017-10-29 19:52:17 +00:00
|
|
|
children.push(helper.attributeEntry(V, 'node.uptime', moment.utc(d.uptime).local().fromNow(true)));
|
|
|
|
children.push(helper.attributeEntry(V, 'node.firstSeen', d.firstseen.fromNow(true)));
|
2017-10-29 14:11:24 +00:00
|
|
|
if (config.nodeInfobox && config.nodeInfobox.hardwareUsage) {
|
|
|
|
children.push(helper.attributeEntry(V, 'node.systemLoad', showLoad(d)));
|
|
|
|
children.push(helper.attributeEntry(V, 'node.ram', showRAM(d)));
|
|
|
|
}
|
|
|
|
children.push(helper.attributeEntry(V, 'node.ipAddresses', showIPs(d)));
|
|
|
|
children.push(helper.attributeEntry(V, 'node.update', showAutoupdate(d)));
|
|
|
|
children.push(helper.attributeEntry(V, 'node.clients', showClients(d)));
|
2017-10-29 15:10:25 +00:00
|
|
|
children.push(helper.attributeEntry(V, 'node.gateway', showGateway(d)));
|
2017-10-29 14:11:24 +00:00
|
|
|
|
|
|
|
var elNew = V.h('table', children);
|
|
|
|
table = V.patch(table, elNew);
|
|
|
|
table.elm.classList.add('attributes');
|
|
|
|
|
|
|
|
V.patch(neighbours, V.h('h3', _.t('node.link', d.neighbours.length) + ' (' + d.neighbours.length + ')'));
|
|
|
|
if (d.neighbours.length > 0) {
|
|
|
|
tableNeighbour.setData(d.neighbours);
|
|
|
|
tableNeighbour.el.elm.classList.add('node-links');
|
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
if (config.nodeInfos) {
|
|
|
|
var img = [];
|
|
|
|
config.nodeInfos.forEach(function (nodeInfo) {
|
|
|
|
img.push(V.h('h4', nodeInfo.name));
|
|
|
|
img.push(showStatImg(nodeInfo, d));
|
|
|
|
});
|
|
|
|
images = V.patch(images, V.h('div', img));
|
|
|
|
}
|
|
|
|
};
|
2017-02-05 22:15:50 +00:00
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
self.setData = function setData(data) {
|
2017-10-31 12:32:39 +00:00
|
|
|
if (data.nodeDict[d.node_id]) {
|
|
|
|
d = data.nodeDict[d.node_id];
|
|
|
|
}
|
2017-10-29 14:11:24 +00:00
|
|
|
self.render();
|
|
|
|
};
|
|
|
|
return self;
|
2016-05-22 12:51:30 +00:00
|
|
|
};
|
|
|
|
});
|