|
@@ -1,95 +1,82 @@
|
|
|
-define(["virtual-dom"],
|
|
|
- function (V) {
|
|
|
- return function(router) {
|
|
|
- function showUptime(now, d) {
|
|
|
- var uptime
|
|
|
- if (d.flags.online && "uptime" in d.statistics)
|
|
|
- uptime = Math.round(d.statistics.uptime / 3600)
|
|
|
- else if (!d.flags.online && "lastseen" in d)
|
|
|
- uptime = Math.round(-(now - d.lastseen) / 3600000)
|
|
|
-
|
|
|
- var s = ""
|
|
|
-
|
|
|
- if (uptime !== undefined)
|
|
|
- if (Math.abs(uptime) >= 24)
|
|
|
- s = Math.round(uptime / 24) + "d"
|
|
|
- else
|
|
|
- s = uptime + "h"
|
|
|
-
|
|
|
- return {v: s, sort: uptime !== undefined ? -uptime : 0}
|
|
|
- }
|
|
|
-
|
|
|
- var self = this
|
|
|
- var el, tbody
|
|
|
-
|
|
|
- self.render = function (d) {
|
|
|
- el = document.createElement("div")
|
|
|
- d.appendChild(el)
|
|
|
- }
|
|
|
-
|
|
|
- self.setData = function (data) {
|
|
|
- if (data.nodes.all.length === 0)
|
|
|
- return
|
|
|
-
|
|
|
- if (!tbody) {
|
|
|
- var h2 = document.createElement("h2")
|
|
|
- h2.textContent = "Alle Knoten"
|
|
|
- el.appendChild(h2)
|
|
|
+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)
|
|
|
+ else if (!d.flags.online && "lastseen" in d)
|
|
|
+ return Math.round(-(now - d.lastseen) / 3600000)
|
|
|
+ }
|
|
|
|
|
|
- var table = document.createElement("table")
|
|
|
- el.appendChild(table)
|
|
|
+ function showUptime(uptime) {
|
|
|
+ var s = ""
|
|
|
|
|
|
- var thead = document.createElement("thead")
|
|
|
+ if (uptime !== undefined)
|
|
|
+ if (Math.abs(uptime) >= 24)
|
|
|
+ s = Math.round(uptime / 24) + "d"
|
|
|
+ else
|
|
|
+ s = uptime + "h"
|
|
|
|
|
|
- var tr = document.createElement("tr")
|
|
|
- var th1 = document.createElement("th")
|
|
|
- th1.textContent = "Knoten"
|
|
|
- tr.appendChild(th1)
|
|
|
+ return s
|
|
|
+ }
|
|
|
|
|
|
- var th2 = document.createElement("th")
|
|
|
- th2.textContent = "Uptime"
|
|
|
- tr.appendChild(th2)
|
|
|
+ var headings = [{ name: "Knoten",
|
|
|
+ sort: function (a, b) {
|
|
|
+ return a.nodeinfo.hostname.localeCompare(b.nodeinfo.hostname)
|
|
|
+ },
|
|
|
+ reverse: false
|
|
|
+ },
|
|
|
+ { name: "Uptime",
|
|
|
+ sort: function (a, b) { return a.uptime - b.uptime},
|
|
|
+ reverse: true
|
|
|
+ },
|
|
|
+ { 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
|
|
|
+ }]
|
|
|
|
|
|
- var th3 = document.createElement("th")
|
|
|
- th3.textContent = "Clients"
|
|
|
- tr.appendChild(th3)
|
|
|
+ return function(router) {
|
|
|
+ function renderRow(d) {
|
|
|
+ var td1Content = []
|
|
|
+ var aClass = ["hostname", d.flags.online ? "online" : "offline"]
|
|
|
|
|
|
- thead.appendChild(tr)
|
|
|
- table.appendChild(thead)
|
|
|
+ td1Content.push(V.h("a", { className: aClass.join(" "),
|
|
|
+ onclick: router.node(d),
|
|
|
+ href: "#"
|
|
|
+ }, d.nodeinfo.hostname))
|
|
|
|
|
|
- tbody = document.createElement("tbody")
|
|
|
- tbody.last = V.h("tbody")
|
|
|
- table.appendChild(tbody)
|
|
|
- }
|
|
|
+ if (has_location(d))
|
|
|
+ td1Content.push(V.h("span", {className: "icon ion-location"}))
|
|
|
|
|
|
- var nodes = data.nodes.all.slice(0).sort( function (a, b) {
|
|
|
- return a.nodeinfo.hostname.localeCompare(b.nodeinfo.hostname)
|
|
|
- })
|
|
|
+ var td1 = V.h("td", td1Content)
|
|
|
+ var td2 = V.h("td", showUptime(d.uptime))
|
|
|
+ var td3 = V.h("td", numeral("clients" in d.statistics ? d.statistics.clients : "").format("0,0"))
|
|
|
|
|
|
- var items = nodes.map( function (d) {
|
|
|
- var td1Content = []
|
|
|
- var aClass = ["hostname", d.flags.online ? "online" : "offline"]
|
|
|
+ return V.h("tr", [td1, td2, td3])
|
|
|
+ }
|
|
|
|
|
|
- td1Content.push(V.h("a", { className: aClass.join(" "),
|
|
|
- onclick: router.node(d),
|
|
|
- href: "#"
|
|
|
- }, d.nodeinfo.hostname))
|
|
|
+ var table = new SortTable(headings, 0, renderRow)
|
|
|
|
|
|
- if (has_location(d))
|
|
|
- td1Content.push(V.h("span", {className: "icon ion-location"}))
|
|
|
+ this.render = function (d) {
|
|
|
+ var el = document.createElement("div")
|
|
|
+ d.appendChild(el)
|
|
|
|
|
|
- var uptime = showUptime(data.now, d)
|
|
|
+ var h2 = document.createElement("h2")
|
|
|
+ h2.textContent = "Alle Knoten"
|
|
|
+ el.appendChild(h2)
|
|
|
|
|
|
- var td1 = V.h("td", td1Content)
|
|
|
- var td2 = V.h("td", uptime.v)
|
|
|
- var td3 = V.h("td", "clients" in d.statistics ? d.statistics.clients : "")
|
|
|
+ el.appendChild(table.el)
|
|
|
+ }
|
|
|
|
|
|
- return V.h("tr", [td1, td2, td3])
|
|
|
+ this.setData = function (d) {
|
|
|
+ var data = d.nodes.all.map(function (e) {
|
|
|
+ var n = Object.create(e)
|
|
|
+ n.uptime = getUptime(d.now, e)
|
|
|
+ return n
|
|
|
})
|
|
|
|
|
|
- var tbodyNew = V.h("tbody", items)
|
|
|
- tbody = V.patch(tbody, V.diff(tbody.last, tbodyNew))
|
|
|
- tbody.last = tbodyNew
|
|
|
- }
|
|
|
+ table.setData(data)
|
|
|
+ }
|
|
|
}
|
|
|
})
|