2015-03-29 03:35:10 +02:00
|
|
|
|
define(["moment"], function (moment) {
|
2015-03-25 19:45:21 +01:00
|
|
|
|
return function(config, field, router, title) {
|
2015-03-25 16:28:36 +01:00
|
|
|
|
var self = this
|
|
|
|
|
var el
|
|
|
|
|
|
2015-03-29 16:14:10 +02:00
|
|
|
|
self.render = function (d) {
|
2015-03-25 16:28:36 +01:00
|
|
|
|
el = document.createElement("div")
|
|
|
|
|
d.appendChild(el)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.setData = function (list) {
|
2015-03-29 16:14:10 +02:00
|
|
|
|
if (list.length === 0)
|
2015-03-25 16:28:36 +01:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
var h2 = document.createElement("h2")
|
|
|
|
|
h2.textContent = title
|
|
|
|
|
el.appendChild(h2)
|
|
|
|
|
var table = document.createElement("table")
|
|
|
|
|
el.appendChild(table)
|
|
|
|
|
|
|
|
|
|
var tbody = document.createElement("tbody")
|
|
|
|
|
|
|
|
|
|
list.forEach( function (d) {
|
|
|
|
|
var time = moment(d[field]).fromNow()
|
|
|
|
|
|
|
|
|
|
var row = document.createElement("tr")
|
|
|
|
|
var td1 = document.createElement("td")
|
|
|
|
|
var a = document.createElement("a")
|
|
|
|
|
a.classList.add("hostname")
|
|
|
|
|
a.classList.add(d.flags.online ? "online" : "offline")
|
|
|
|
|
a.textContent = d.nodeinfo.hostname
|
|
|
|
|
a.href = "#"
|
2015-03-25 19:45:21 +01:00
|
|
|
|
a.onclick = router.node(d)
|
2015-03-25 16:28:36 +01:00
|
|
|
|
td1.appendChild(a)
|
|
|
|
|
|
|
|
|
|
if (has_location(d)) {
|
|
|
|
|
var span = document.createElement("span")
|
|
|
|
|
span.classList.add("icon")
|
|
|
|
|
span.classList.add("ion-location")
|
|
|
|
|
td1.appendChild(span)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("owner" in d.nodeinfo && config.showContact) {
|
|
|
|
|
var contact = d.nodeinfo.owner.contact
|
|
|
|
|
td1.appendChild(document.createTextNode(" – " + contact + ""))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var td2 = document.createElement("td")
|
|
|
|
|
td2.textContent = time
|
|
|
|
|
|
|
|
|
|
row.appendChild(td1)
|
|
|
|
|
row.appendChild(td2)
|
|
|
|
|
tbody.appendChild(row)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
table.appendChild(tbody)
|
|
|
|
|
el.appendChild(table)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
})
|