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