2015-04-03 00:32:32 +00:00
|
|
|
|
define(["virtual-dom"],
|
|
|
|
|
function (V) {
|
2015-03-25 18:45:21 +00:00
|
|
|
|
return function(linkScale, router) {
|
2015-03-25 15:04:23 +00:00
|
|
|
|
var self = this
|
2015-04-03 00:32:32 +00:00
|
|
|
|
var el, tbody
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
|
|
|
|
self.render = function (d) {
|
|
|
|
|
el = document.createElement("div")
|
|
|
|
|
d.appendChild(el)
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-29 15:48:25 +00:00
|
|
|
|
self.setData = function (data) {
|
2015-03-31 15:21:58 +00:00
|
|
|
|
if (data.graph.links.length === 0)
|
2015-03-25 15:04:23 +00:00
|
|
|
|
return
|
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
if (!tbody) {
|
|
|
|
|
var h2 = document.createElement("h2")
|
|
|
|
|
h2.textContent = "Verbindungen"
|
|
|
|
|
el.appendChild(h2)
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
var table = document.createElement("table")
|
|
|
|
|
el.appendChild(table)
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
var thead = document.createElement("thead")
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
var tr = document.createElement("tr")
|
|
|
|
|
var th1 = document.createElement("th")
|
|
|
|
|
th1.textContent = "Knoten"
|
|
|
|
|
tr.appendChild(th1)
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
var th2 = document.createElement("th")
|
|
|
|
|
th2.textContent = "TQ"
|
|
|
|
|
tr.appendChild(th2)
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
var th3 = document.createElement("th")
|
|
|
|
|
th3.textContent = "Entfernung"
|
|
|
|
|
tr.appendChild(th3)
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
thead.appendChild(tr)
|
|
|
|
|
table.appendChild(thead)
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
tbody = document.createElement("tbody")
|
|
|
|
|
tbody.last = V.h("tbody")
|
|
|
|
|
table.appendChild(tbody)
|
|
|
|
|
}
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-03 00:32:32 +00:00
|
|
|
|
var links = data.graph.links.slice(0).sort( function (a, b) {
|
|
|
|
|
a = a.distance === undefined ? -1 : a.distance
|
|
|
|
|
b = b.distance === undefined ? -1 : b.distance
|
|
|
|
|
|
|
|
|
|
return b - a
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
var items = links.map( function (d) {
|
2015-04-02 18:58:30 +00:00
|
|
|
|
var name = d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname
|
|
|
|
|
var td1Content = [V.h("a", {href: "#", onclick: router.link(d)}, name)]
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
if (d.vpn)
|
|
|
|
|
td1Content.push(" (VPN)")
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
var td1 = V.h("td", td1Content)
|
2015-04-03 00:32:32 +00:00
|
|
|
|
var td2 = V.h("td", {style: {color: linkScale(d.tq).hex()}}, showTq(d))
|
|
|
|
|
var td3 = V.h("td", showDistance(d))
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
return V.h("tr", [td1, td2, td3])
|
2015-03-25 15:04:23 +00:00
|
|
|
|
})
|
|
|
|
|
|
2015-04-02 18:58:30 +00:00
|
|
|
|
var tbodyNew = V.h("tbody", items)
|
|
|
|
|
tbody = V.patch(tbody, V.diff(tbody.last, tbodyNew))
|
|
|
|
|
tbody.last = tbodyNew
|
2015-03-25 15:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|