2015-04-07 15:41:17 +00:00
|
|
|
define(["sorttable", "virtual-dom", "numeral"], function (SortTable, V, numeral) {
|
|
|
|
function getUptime(now, d) {
|
|
|
|
if (d.flags.online && "uptime" in d.statistics)
|
2015-04-12 21:23:15 +00:00
|
|
|
return Math.round(d.statistics.uptime)
|
2015-04-07 15:41:17 +00:00
|
|
|
else if (!d.flags.online && "lastseen" in d)
|
2015-04-19 11:35:49 +00:00
|
|
|
return Math.round(-(now.unix() - d.lastseen.unix()))
|
2015-04-07 15:41:17 +00:00
|
|
|
}
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
function showUptime(uptime) {
|
|
|
|
var s = ""
|
2015-04-12 21:23:15 +00:00
|
|
|
uptime /= 3600
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
if (uptime !== undefined)
|
|
|
|
if (Math.abs(uptime) >= 24)
|
|
|
|
s = Math.round(uptime / 24) + "d"
|
|
|
|
else
|
2015-04-12 21:23:15 +00:00
|
|
|
s = Math.round(uptime) + "h"
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
return s
|
|
|
|
}
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
var headings = [{ name: "Knoten",
|
|
|
|
sort: function (a, b) {
|
|
|
|
return a.nodeinfo.hostname.localeCompare(b.nodeinfo.hostname)
|
|
|
|
},
|
|
|
|
reverse: false
|
|
|
|
},
|
|
|
|
{ name: "Uptime",
|
2015-04-12 21:23:15 +00:00
|
|
|
sort: function (a, b) {
|
|
|
|
return a.uptime - b.uptime
|
|
|
|
},
|
2015-04-07 15:41:17 +00:00
|
|
|
reverse: true
|
|
|
|
},
|
2015-12-28 16:53:10 +00:00
|
|
|
{ name: "Neighbours",
|
|
|
|
sort: function (a, b) {
|
|
|
|
return a.meshlinks - b.meshlinks
|
|
|
|
},
|
|
|
|
reverse: true
|
|
|
|
},
|
2015-04-07 15:41:17 +00:00
|
|
|
{ name: "Clients",
|
|
|
|
sort: function (a, b) {
|
|
|
|
return ("clients" in a.statistics ? a.statistics.clients : -1) -
|
|
|
|
("clients" in b.statistics ? b.statistics.clients : -1)
|
|
|
|
},
|
|
|
|
reverse: true
|
|
|
|
}]
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
return function(router) {
|
|
|
|
function renderRow(d) {
|
|
|
|
var td1Content = []
|
|
|
|
var aClass = ["hostname", d.flags.online ? "online" : "offline"]
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
td1Content.push(V.h("a", { className: aClass.join(" "),
|
|
|
|
onclick: router.node(d),
|
|
|
|
href: "#"
|
|
|
|
}, d.nodeinfo.hostname))
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
if (has_location(d))
|
|
|
|
td1Content.push(V.h("span", {className: "icon ion-location"}))
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
var td1 = V.h("td", td1Content)
|
|
|
|
var td2 = V.h("td", showUptime(d.uptime))
|
2015-12-28 16:53:10 +00:00
|
|
|
var td3 = V.h("td", d.meshlinks.toString())
|
|
|
|
var td4 = V.h("td", numeral("clients" in d.statistics ? d.statistics.clients : "").format("0,0"))
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-12-28 16:53:10 +00:00
|
|
|
return V.h("tr", [td1, td2, td3, td4])
|
2015-04-07 15:41:17 +00:00
|
|
|
}
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
var table = new SortTable(headings, 0, renderRow)
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
this.render = function (d) {
|
|
|
|
var el = document.createElement("div")
|
|
|
|
d.appendChild(el)
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
var h2 = document.createElement("h2")
|
|
|
|
h2.textContent = "Alle Knoten"
|
|
|
|
el.appendChild(h2)
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
el.appendChild(table.el)
|
|
|
|
}
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
this.setData = function (d) {
|
|
|
|
var data = d.nodes.all.map(function (e) {
|
|
|
|
var n = Object.create(e)
|
2015-04-12 21:23:15 +00:00
|
|
|
n.uptime = getUptime(d.now, e) || 0
|
2015-12-28 16:53:10 +00:00
|
|
|
n.meshlinks = e.meshlinks || 0
|
2015-04-07 15:41:17 +00:00
|
|
|
return n
|
2015-04-02 19:28:21 +00:00
|
|
|
})
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
table.setData(data)
|
|
|
|
}
|
2015-03-26 00:31:46 +00:00
|
|
|
}
|
|
|
|
})
|