[BUGFIX] Fix uptime in nodelist

This commit is contained in:
Martin Geno 2017-10-26 15:58:28 +02:00 committed by Xaver Maierhofer
parent 77ac4ca3f5
commit 4787aa7f62
No known key found for this signature in database
GPG Key ID: 7FDCE23FD2EC9FE8
2 changed files with 16 additions and 22 deletions

View File

@ -52,7 +52,7 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
return undefined;
}
return moment.duration(d.uptime, 'seconds').humanize();
return moment.utc(d.uptime).local().fromNow(true);
}
function showFirstseen(d) {

View File

@ -2,28 +2,18 @@ define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) {
'use strict';
V = V.default;
function getUptime(now, d) {
if (d.is_online && 'uptime' in d) {
return Math.round(d.uptime);
} else if (!d.is_online && 'lastseen' in d) {
return Math.round(-(now.unix() - d.lastseen.unix()));
}
return 0;
}
function showUptime(uptime) {
var s = '';
uptime /= 3600;
if (uptime !== undefined) {
if (Math.abs(uptime) >= 24) {
s = Math.round(uptime / 24) + 'd';
} else {
s = Math.round(uptime) + 'h';
}
// 1000ms are 1 second and 60 second are 1min: 60 * 1000 = 60000
var s = uptime / 60000;
if (Math.abs(s) < 60) {
return Math.round(s) + ' m';
}
return s;
s /= 60;
if (Math.abs(s) < 24) {
return Math.round(s) + ' h';
}
s /= 24;
return Math.round(s) + ' d';
}
var headings = [{
@ -101,7 +91,11 @@ define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) {
this.setData = function setData(d) {
var data = d.nodes.all.map(function (e) {
var n = Object.create(e);
n.uptime = getUptime(d.now, e);
if (e.is_online) {
n.uptime = d.now - new Date(e.uptime).getTime();
} else {
n.uptime = e.lastseen - d.now;
}
n.neighbours = e.neighbours;
return n;
});