From dde828934ed58bd6c4ebd93f702916866a061ca0 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sun, 12 Apr 2015 23:23:15 +0200 Subject: [PATCH] nodelist: fix uptime sorting --- lib/nodelist.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/nodelist.js b/lib/nodelist.js index 1ab4113..e867eed 100644 --- a/lib/nodelist.js +++ b/lib/nodelist.js @@ -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 })