[TASK] Simplify labellayer & remove unnessary condition

This commit is contained in:
Xaver Maierhofer 2017-11-01 19:51:30 +01:00 committed by Xaver Maierhofer
parent 1887a3270c
commit aa89f06342
No known key found for this signature in database
GPG Key ID: 7FDCE23FD2EC9FE8
2 changed files with 28 additions and 32 deletions

View File

@ -154,31 +154,29 @@ define(['leaflet', 'rbush', 'helper', 'moment'],
var lines = addLinksToMap(linkDict, linkScale, data.links, router); var lines = addLinksToMap(linkDict, linkScale, data.links, router);
groupLines = L.featureGroup(lines).addTo(map); groupLines = L.featureGroup(lines).addTo(map);
var nodesOnline = helper.subtract(data.nodes.online, data.nodes.new); var nodesOnline = helper.subtract(data.nodes.online, data.nodes.new).filter(helper.hasLocation);
var nodesOffline = helper.subtract(data.nodes.offline, data.nodes.lost); var nodesOffline = helper.subtract(data.nodes.offline, data.nodes.lost).filter(helper.hasLocation);
var nodesNew = data.nodes.new.filter(helper.hasLocation);
var nodesLost = data.nodes.lost.filter(helper.hasLocation);
var markersOnline = nodesOnline.filter(helper.hasLocation) var markersOnline = nodesOnline.map(mkMarker(nodeDict, function () {
.map(mkMarker(nodeDict, function () {
return iconOnline; return iconOnline;
}, router)); }, router));
var markersOffline = nodesOffline.filter(helper.hasLocation) var markersOffline = nodesOffline.map(mkMarker(nodeDict, function () {
.map(mkMarker(nodeDict, function () {
return iconOffline; return iconOffline;
}, router)); }, router));
var markersNew = data.nodes.new.filter(helper.hasLocation) var markersNew = nodesNew.map(mkMarker(nodeDict, function () {
.map(mkMarker(nodeDict, function () {
return iconNew; return iconNew;
}, router)); }, router));
var markersLost = data.nodes.lost.filter(helper.hasLocation) var markersLost = nodesLost.map(mkMarker(nodeDict, function (d) {
.map(mkMarker(nodeDict, function (d) { var age = moment(data.now).diff(d.lastseen, 'days', true);
if (d.lastseen.isAfter(moment(data.now).subtract(config.maxAgeAlert, 'days'))) { if (age <= config.maxAgeAlert) {
return iconAlert; return iconAlert;
} }
if (age <= config.maxAge) {
if (d.lastseen.isAfter(moment(data.now).subtract(config.maxAge, 'days'))) {
return iconLost; return iconLost;
} }
return null; return null;
@ -190,10 +188,10 @@ define(['leaflet', 'rbush', 'helper', 'moment'],
groupNew = L.featureGroup(markersNew).addTo(map); groupNew = L.featureGroup(markersNew).addTo(map);
this.data = { this.data = {
online: nodesOnline.filter(helper.hasLocation), online: nodesOnline,
offline: nodesOffline.filter(helper.hasLocation), offline: nodesOffline,
new: data.nodes.new.filter(helper.hasLocation), new: nodesNew,
lost: data.nodes.lost.filter(helper.hasLocation) lost: nodesLost
}; };
this.updateLayer(); this.updateLayer();
}, },

View File

@ -100,9 +100,7 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'],
}); });
var autoDict = count(nodes, ['autoupdater'], function (d) { var autoDict = count(nodes, ['autoupdater'], function (d) {
if (d === null) { if (d.enabled) {
return null;
} else if (d.enabled) {
return d.branch; return d.branch;
} }
return _.t('node.deactivated'); return _.t('node.deactivated');