[BUGFIX] Fix uptime in nodelist
This commit is contained in:
parent
77ac4ca3f5
commit
4787aa7f62
@ -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) {
|
||||
|
@ -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';
|
||||
}
|
||||
s /= 60;
|
||||
if (Math.abs(s) < 24) {
|
||||
return Math.round(s) + ' h';
|
||||
}
|
||||
|
||||
return s;
|
||||
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;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user