[TASK] Remove outdated code

This commit is contained in:
Xaver Maierhofer 2017-10-29 20:52:17 +01:00 committed by GitHub
parent d6b84eba22
commit af589ee227
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 68 additions and 127 deletions

View File

@ -16,7 +16,7 @@ define(function () {
} }
function run(d) { function run(d) {
return (d !== undefined ? d.hostname.toLowerCase().includes(input.value.toLowerCase()) : ''); return d.hostname.toLowerCase().includes(input.value.toLowerCase());
} }
function setRefresh(f) { function setRefresh(f) {

View File

@ -46,9 +46,8 @@ define(['helper', 'snabbdom'], function (helper, V) {
} }
}, helper.showTq(d.source_tq) + ' - ' + helper.showTq(d.target_tq)))); }, helper.showTq(d.source_tq) + ' - ' + helper.showTq(d.target_tq))));
children.push(helper.attributeEntry(V, 'node.distance', helper.showDistance(d))); children.push(helper.attributeEntry(V, 'node.distance', helper.showDistance(d)));
children.push(helper.attributeEntry(V, 'node.hardware', children.push(helper.attributeEntry(V, 'node.hardware', (d.source.model ? d.source.model + ' ' : '') +
helper.dictGet(d.source, ['model']) + ' ' + helper.dictGet(d.target, ['model'])) (d.target.model ? d.target.model : '')));
);
var elNew = V.h('table', children); var elNew = V.h('table', children);
table = V.patch(table, elNew); table = V.patch(table, elNew);

View File

@ -18,7 +18,7 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
function showStatus(d) { function showStatus(d) {
return V.h('td', return V.h('td',
{ props: { className: d.is_unseen ? 'unseen' : (d.is_online ? 'online' : 'offline') } }, { props: { className: d.is_online ? 'online' : 'offline' } },
_.t((d.is_online ? 'node.lastOnline' : 'node.lastOffline'), { _.t((d.is_online ? 'node.lastOnline' : 'node.lastOffline'), {
time: d.lastseen.fromNow(), time: d.lastseen.fromNow(),
date: d.lastseen.format('DD.MM.YYYY, H:mm:ss') date: d.lastseen.format('DD.MM.YYYY, H:mm:ss')
@ -35,32 +35,15 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
} }
function showSite(d, config) { function showSite(d, config) {
var site = helper.dictGet(d, ['site_code']); var rt = d.site_code;
var rt = site;
if (config.siteNames) { if (config.siteNames) {
config.siteNames.forEach(function (t) { config.siteNames.forEach(function (t) {
if (site === t.site) { if (d.site_code === t.site) {
rt = t.name; rt = t.name;
} }
}); });
} }
return rt || undefined; return rt;
}
function showUptime(d) {
if (!('uptime' in d)) {
return undefined;
}
return moment.utc(d.uptime).local().fromNow(true);
}
function showFirstseen(d) {
if (!('firstseen' in d)) {
return undefined;
}
return d.firstseen.fromNow(true);
} }
function showClients(d) { function showClients(d) {
@ -101,22 +84,15 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
} }
function showIPs(d) { function showIPs(d) {
var ips = helper.dictGet(d, ['network', 'addresses']);
if (ips === null) {
return undefined;
}
ips.sort();
var string = []; var string = [];
var ips = d.network.addresses;
ips.sort();
ips.forEach(function (ip, i) { ips.forEach(function (ip, i) {
var link = !ip.startsWith('fe80:');
if (i > 0) { if (i > 0) {
string.push(V.h('br')); string.push(V.h('br'));
} }
if (link) { if (!ip.startsWith('fe80:')) {
string.push(V.h('a', { props: { href: 'http://[' + ip + ']/', target: '_blank' } }, ip)); string.push(V.h('a', { props: { href: 'http://[' + ip + ']/', target: '_blank' } }, ip));
} else { } else {
string.push(ip); string.push(ip);
@ -142,37 +118,18 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
if (!('loadavg' in d)) { if (!('loadavg' in d)) {
return undefined; return undefined;
} }
return showBar(d.loadavg.toFixed(2), d.loadavg % 1, d.loadavg >= d.nproc);
var value = d.loadavg.toFixed(2);
var width = d.loadavg % 1;
var warning = false;
if (d.loadavg >= d.nproc) {
warning = true;
}
return showBar(value, width, warning);
} }
function showRAM(d) { function showRAM(d) {
if (!('memory_usage' in d)) { if (!('memory_usage' in d)) {
return undefined; return undefined;
} }
return showBar(Math.round(d.memory_usage * 100) + ' %', d.memory_usage, d.memory_usage >= 0.8);
var value = Math.round(d.memory_usage * 100) + ' %';
var width = d.memory_usage;
var warning = false;
if (d.memory_usage >= 0.8) {
warning = true;
}
return showBar(value, width, warning);
} }
function showAutoupdate(d) { function showAutoupdate(d) {
var au = helper.dictGet(d, ['autoupdater']); return d.autoupdater.enabled ? _.t('node.activated', { branch: d.autoupdater.branch }) : _.t('node.deactivated');
if (!au) {
return undefined;
}
return au.enabled ? _.t('node.activated', { branch: au.branch }) : _.t('node.deactivated');
} }
function showStatImg(o, d) { function showStatImg(o, d) {
@ -198,28 +155,28 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
}, node.hostname); }, node.hostname);
} }
function nodeidLink(nodeid) { function nodeIdLink(nodeId) {
if (nodeDict[nodeid]) { if (nodeDict[nodeId]) {
return nodeLink(nodeDict[nodeid]); return nodeLink(nodeDict[nodeId]);
} }
return nodeid; return nodeId;
} }
function showGateway(node) { function showGateway(node) {
var gatewayCols = [ var gatewayCols = [
V.h('span', [ V.h('span', [
nodeidLink(node.gateway_nexthop), nodeIdLink(node.gateway_nexthop),
V.h('br'), V.h('br'),
_.t('node.nexthop') _.t('node.nexthop')
]), ]),
V.h('span', { props: { className: 'ion-arrow-right-c' } }), V.h('span', { props: { className: 'ion-arrow-right-c' } }),
V.h('span', [ V.h('span', [
nodeidLink(node.gateway), nodeIdLink(node.gateway),
V.h('br'), V.h('br'),
'IPv4' 'IPv4'
]), ]),
V.h('span', [ V.h('span', [
nodeidLink(node.gateway6), nodeIdLink(node.gateway6),
V.h('br'), V.h('br'),
'IPv6' 'IPv6'
]) ])
@ -234,13 +191,13 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
icons = V.h('span', { props: { className: 'ion-location' } }); icons = V.h('span', { props: { className: 'ion-location' } });
} }
var td1 = V.h('td', icons); return V.h('tr', [
var td2 = V.h('td', nodeLink(n.node)); V.h('td', icons),
var td3 = V.h('td', (n.node.clients ? n.node.clients.toString() : '0')); V.h('td', nodeLink(n.node)),
var td4 = 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', n.node.clients),
var td5 = V.h('td', helper.showDistance(n.link)); 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))
return V.h('tr', [td1, td2, td3, td4, td5]); ]);
} }
var self = this; var self = this;
@ -260,8 +217,7 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
name: 'node.clients', name: 'node.clients',
class: 'ion-people', class: 'ion-people',
sort: function (a, b) { sort: function (a, b) {
return ('clients' in a.node ? a.node.clients : -1) - return a.node.clients - b.node.clients;
('clients' in b.node ? b.node.clients : -1);
}, },
reverse: true reverse: true
}, { }, {
@ -294,19 +250,19 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
var children = []; var children = [];
children.push(helper.attributeEntry(V, 'node.status', showStatus(d))); children.push(helper.attributeEntry(V, 'node.status', showStatus(d)));
children.push(helper.attributeEntry(V, 'node.gateway', d.is_gateway ? 'ja' : null)); children.push(helper.attributeEntry(V, 'node.gateway', d.is_gateway ? 'ja' : undefined));
children.push(helper.attributeEntry(V, 'node.coordinates', showGeoURI(d))); children.push(helper.attributeEntry(V, 'node.coordinates', showGeoURI(d)));
if (config.nodeInfobox && config.nodeInfobox.contact) { if (config.nodeInfobox && config.nodeInfobox.contact) {
children.push(helper.attributeEntry(V, 'node.contact', helper.dictGet(d, ['owner', 'contact']))); children.push(helper.attributeEntry(V, 'node.contact', helper.dictGet(d, ['owner', 'contact'])));
} }
children.push(helper.attributeEntry(V, 'node.hardware', helper.dictGet(d, ['model']))); children.push(helper.attributeEntry(V, 'node.hardware', d.model));
children.push(helper.attributeEntry(V, 'node.primaryMac', helper.dictGet(d, ['network', 'mac']))); children.push(helper.attributeEntry(V, 'node.primaryMac', d.network.mac));
children.push(helper.attributeEntry(V, 'node.firmware', showFirmware(d))); children.push(helper.attributeEntry(V, 'node.firmware', showFirmware(d)));
children.push(helper.attributeEntry(V, 'node.site', showSite(d, config))); children.push(helper.attributeEntry(V, 'node.site', showSite(d, config)));
children.push(helper.attributeEntry(V, 'node.uptime', showUptime(d))); children.push(helper.attributeEntry(V, 'node.uptime', moment.utc(d.uptime).local().fromNow(true)));
children.push(helper.attributeEntry(V, 'node.firstSeen', showFirstseen(d))); children.push(helper.attributeEntry(V, 'node.firstSeen', d.firstseen.fromNow(true)));
if (config.nodeInfobox && config.nodeInfobox.hardwareUsage) { if (config.nodeInfobox && config.nodeInfobox.hardwareUsage) {
children.push(helper.attributeEntry(V, 'node.systemLoad', showLoad(d))); children.push(helper.attributeEntry(V, 'node.systemLoad', showLoad(d)));
children.push(helper.attributeEntry(V, 'node.ram', showRAM(d))); children.push(helper.attributeEntry(V, 'node.ram', showRAM(d)));

View File

@ -10,7 +10,7 @@ define(['helper'], function (helper) {
var totalNodes = helper.sum(d.nodes.all.map(helper.one)); var totalNodes = helper.sum(d.nodes.all.map(helper.one));
var totalOnlineNodes = helper.sum(d.nodes.all.filter(helper.online).map(helper.one)); var totalOnlineNodes = helper.sum(d.nodes.all.filter(helper.online).map(helper.one));
var totalClients = helper.sum(d.nodes.all.filter(helper.online).map(function (n) { var totalClients = helper.sum(d.nodes.all.filter(helper.online).map(function (n) {
return n.clients ? n.clients : 0; return n.clients;
})); }));
var totalGateways = helper.sum(d.nodes.all.filter(helper.online).filter(function (n) { var totalGateways = helper.sum(d.nodes.all.filter(helper.online).filter(function (n) {
return n.is_gateway; return n.is_gateway;

View File

@ -43,11 +43,11 @@ define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) {
} }
}, linkName(d))]; }, linkName(d))];
var td1 = V.h('td', td1Content); return V.h('tr', [
var td2 = V.h('td', { style: { color: linkScale((d.source_tq + d.target_tq) / 2) } }, helper.showTq(d.source_tq) + ' - ' + helper.showTq(d.target_tq)); V.h('td', td1Content),
var td3 = V.h('td', helper.showDistance(d)); V.h('td', { style: { color: linkScale((d.source_tq + d.target_tq) / 2) } }, helper.showTq(d.source_tq) + ' - ' + helper.showTq(d.target_tq)),
V.h('td', helper.showDistance(d))
return V.h('tr', [td1, td2, td3]); ]);
} }
this.render = function render(d) { this.render = function render(d) {

View File

@ -47,7 +47,7 @@ define(['map/clientlayer', 'map/labellayer', 'map/button', 'leaflet'],
var layers = config.mapLayers.map(function (d) { var layers = config.mapLayers.map(function (d) {
return { return {
'name': d.name, 'name': d.name,
'layer': 'url' in d ? L.tileLayer(d.url.replace('{retina}', L.Browser.retina ? '@2x' : ''), d.config) : console.warn('Missing map url') 'layer': L.tileLayer(d.url.replace('{retina}', L.Browser.retina ? '@2x' : ''), d.config)
}; };
}); });

View File

@ -42,40 +42,36 @@ define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) {
name: 'node.clients', name: 'node.clients',
class: 'ion-people', class: 'ion-people',
sort: function (a, b) { sort: function (a, b) {
return ('clients' in a ? a.clients : -1) - return a.clients - b.clients;
('clients' in b ? b.clients : -1);
}, },
reverse: true reverse: true
}]; }];
return function (router) { return function (router) {
function renderRow(d) { function renderRow(d) {
var td0Content = []; var td0Content = '';
var td1Content = []; if (helper.hasLocation(d)) {
var aClass = ['hostname', d.is_online ? 'online' : 'offline']; td0Content = V.h('span', { props: { className: 'icon ion-location' } });
}
td1Content.push(V.h('a', { var td1Content = V.h('a', {
props: { props: {
className: aClass.join(' '), className: ['hostname', d.is_online ? 'online' : 'offline'].join(' '),
href: router.generateLink({ node: d.node_id }) href: router.generateLink({ node: d.node_id })
}, on: { }, on: {
click: function (e) { click: function (e) {
router.fullUrl({ node: d.node_id }, e); router.fullUrl({ node: d.node_id }, e);
} }
} }
}, d.hostname)); }, d.hostname);
if (helper.hasLocation(d)) { return V.h('tr', [
td0Content.push(V.h('span', { props: { className: 'icon ion-location' } })); V.h('td', td0Content),
} V.h('td', td1Content),
V.h('td', showUptime(d.uptime)),
var td0 = V.h('td', td0Content); V.h('td', d.neighbours.length),
var td1 = V.h('td', td1Content); V.h('td', d.clients)
var td2 = V.h('td', showUptime(d.uptime)); ]);
var td3 = V.h('td', d.neighbours.length);
var td4 = V.h('td', Number('clients' in d ? d.clients : 0).toFixed(0));
return V.h('tr', [td0, td1, td2, td3, td4]);
} }
var table = new SortTable(headings, 1, renderRow); var table = new SortTable(headings, 1, renderRow);

View File

@ -34,32 +34,27 @@ define(['moment', 'snabbdom', 'helper'], function (moment, V, helper) {
} }
var items = list.map(function (d) { var items = list.map(function (d) {
var time = moment(d[field]).from(data.now); var td0Content = '';
var td0Content = []; if (helper.hasLocation(d)) {
var td1Content = []; td0Content = V.h('span', { props: { className: 'icon ion-location' } });
}
var aClass = ['hostname', d.is_online ? 'online' : 'offline']; var td1Content = V.h('a', {
td1Content.push(V.h('a', {
props: { props: {
className: aClass.join(' '), className: ['hostname', d.is_online ? 'online' : 'offline'].join(' '),
href: router.generateLink({ node: d.node_id }) href: router.generateLink({ node: d.node_id })
}, on: { }, on: {
click: function (e) { click: function (e) {
router.fullUrl({ node: d.node_id }, e); router.fullUrl({ node: d.node_id }, e);
} }
} }
}, d.hostname)); }, d.hostname);
if (helper.hasLocation(d)) { return V.h('tr', [
td0Content.push(V.h('span', { props: { className: 'icon ion-location' } })); V.h('td', td0Content),
} V.h('td', td1Content),
V.h('td', moment(d[field]).from(data.now))
var td0 = V.h('td', td0Content); ]);
var td1 = V.h('td', td1Content);
var td2 = V.h('td', time);
return V.h('tr', [td0, td1, td2]);
}); });
var tbodyNew = V.h('tbody', items); var tbodyNew = V.h('tbody', items);

View File

@ -114,7 +114,7 @@ define({
}, },
attributeEntry: function attributeEntry(V, label, value) { attributeEntry: function attributeEntry(V, label, value) {
if (value === null || value === undefined) { if (value === undefined) {
return ''; return '';
} }

View File

@ -142,7 +142,3 @@
.offline { .offline {
color: $color-offline; color: $color-offline;
} }
.unseen {
color: $color-unseen;
}

View File

@ -9,7 +9,6 @@ $color-primary: #dc0067 !default;
$color-new: #459c18 !default; $color-new: #459c18 !default;
$color-online: #1566a9 !default; $color-online: #1566a9 !default;
$color-offline: #cf3e2a !default; $color-offline: #cf3e2a !default;
$color-unseen: #d89100 !default;
$color-24ghz: $color-primary !default; $color-24ghz: $color-primary !default;
$color-5ghz: #e3a619 !default; $color-5ghz: #e3a619 !default;