nodelist: fix uptime sorting

This commit is contained in:
Nils Schneider 2015-04-12 23:23:15 +02:00
parent 2fcce92bce
commit dde828934e

View File

@ -1,19 +1,20 @@
define(["sorttable", "virtual-dom", "numeral"], function (SortTable, V, numeral) {
function getUptime(now, d) {
if (d.flags.online && "uptime" in d.statistics)
return Math.round(d.statistics.uptime / 3600)
return Math.round(d.statistics.uptime)
else if (!d.flags.online && "lastseen" in d)
return Math.round(-(now - d.lastseen) / 3600000)
return Math.round(-(now - d.lastseen) / 3600)
}
function showUptime(uptime) {
var s = ""
uptime /= 3600
if (uptime !== undefined)
if (Math.abs(uptime) >= 24)
s = Math.round(uptime / 24) + "d"
else
s = uptime + "h"
s = Math.round(uptime) + "h"
return s
}
@ -25,7 +26,9 @@ define(["sorttable", "virtual-dom", "numeral"], function (SortTable, V, numeral)
reverse: false
},
{ name: "Uptime",
sort: function (a, b) { return a.uptime - b.uptime},
sort: function (a, b) {
return a.uptime - b.uptime
},
reverse: true
},
{ name: "Clients",
@ -72,7 +75,7 @@ define(["sorttable", "virtual-dom", "numeral"], function (SortTable, V, numeral)
this.setData = function (d) {
var data = d.nodes.all.map(function (e) {
var n = Object.create(e)
n.uptime = getUptime(d.now, e)
n.uptime = getUptime(d.now, e) || 0
return n
})