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

View File

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