make linklist.setData idempotent
This commit is contained in:
parent
7b57a2245b
commit
7ddfbd964c
|
@ -1,7 +1,8 @@
|
||||||
define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
define(["tablesort", "virtual-dom", "tablesort.numeric"],
|
||||||
|
function (Tablesort, V) {
|
||||||
return function(linkScale, router) {
|
return function(linkScale, router) {
|
||||||
var self = this
|
var self = this
|
||||||
var el
|
var el, tbody, sort
|
||||||
|
|
||||||
self.render = function (d) {
|
self.render = function (d) {
|
||||||
el = document.createElement("div")
|
el = document.createElement("div")
|
||||||
|
@ -12,64 +13,60 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
||||||
if (data.graph.links.length === 0)
|
if (data.graph.links.length === 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
var h2 = document.createElement("h2")
|
if (!tbody) {
|
||||||
h2.textContent = "Verbindungen"
|
var h2 = document.createElement("h2")
|
||||||
el.appendChild(h2)
|
h2.textContent = "Verbindungen"
|
||||||
|
el.appendChild(h2)
|
||||||
|
|
||||||
var table = document.createElement("table")
|
var table = document.createElement("table")
|
||||||
var thead = document.createElement("thead")
|
el.appendChild(table)
|
||||||
|
|
||||||
var tr = document.createElement("tr")
|
var thead = document.createElement("thead")
|
||||||
var th1 = document.createElement("th")
|
|
||||||
th1.textContent = "Knoten"
|
|
||||||
tr.appendChild(th1)
|
|
||||||
|
|
||||||
var th2 = document.createElement("th")
|
var tr = document.createElement("tr")
|
||||||
th2.textContent = "TQ"
|
var th1 = document.createElement("th")
|
||||||
tr.appendChild(th2)
|
th1.textContent = "Knoten"
|
||||||
|
tr.appendChild(th1)
|
||||||
|
|
||||||
var th3 = document.createElement("th")
|
var th2 = document.createElement("th")
|
||||||
th3.textContent = "Entfernung"
|
th2.textContent = "TQ"
|
||||||
th3.classList.add("sort-default")
|
tr.appendChild(th2)
|
||||||
tr.appendChild(th3)
|
|
||||||
|
|
||||||
thead.appendChild(tr)
|
var th3 = document.createElement("th")
|
||||||
|
th3.textContent = "Entfernung"
|
||||||
|
th3.classList.add("sort-default")
|
||||||
|
tr.appendChild(th3)
|
||||||
|
|
||||||
table.appendChild(thead)
|
thead.appendChild(tr)
|
||||||
|
table.appendChild(thead)
|
||||||
|
|
||||||
var tbody = document.createElement("tbody")
|
tbody = document.createElement("tbody")
|
||||||
|
tbody.last = V.h("tbody")
|
||||||
|
table.appendChild(tbody)
|
||||||
|
|
||||||
data.graph.links.forEach( function (d) {
|
sort = new Tablesort(table)
|
||||||
var row = document.createElement("tr")
|
}
|
||||||
var td1 = document.createElement("td")
|
|
||||||
var a = document.createElement("a")
|
var items = data.graph.links.map( function (d) {
|
||||||
a.textContent = d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname
|
var name = d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname
|
||||||
a.href = "#"
|
var td1Content = [V.h("a", {href: "#", onclick: router.link(d)}, name)]
|
||||||
a.onclick = router.link(d)
|
|
||||||
td1.appendChild(a)
|
|
||||||
row.appendChild(td1)
|
|
||||||
|
|
||||||
if (d.vpn)
|
if (d.vpn)
|
||||||
td1.appendChild(document.createTextNode(" (VPN)"))
|
td1Content.push(" (VPN)")
|
||||||
|
|
||||||
var td2 = document.createElement("td")
|
var td1 = V.h("td", td1Content)
|
||||||
td2.textContent = showTq(d)
|
var td2 = V.h("td", {style: {color: linkScale(d.tq)}}, showTq(d))
|
||||||
td2.style.color = linkScale(d.tq)
|
var td3 = V.h("td", {attributes: {
|
||||||
row.appendChild(td2)
|
"data-sort": d.distance !== undefined ? -d.distance : 1
|
||||||
|
}}, showDistance(d))
|
||||||
|
|
||||||
var td3 = document.createElement("td")
|
return V.h("tr", [td1, td2, td3])
|
||||||
td3.textContent = showDistance(d)
|
|
||||||
td3.setAttribute("data-sort", d.distance !== undefined ? -d.distance : 1)
|
|
||||||
row.appendChild(td3)
|
|
||||||
|
|
||||||
tbody.appendChild(row)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
table.appendChild(tbody)
|
var tbodyNew = V.h("tbody", items)
|
||||||
|
tbody = V.patch(tbody, V.diff(tbody.last, tbodyNew))
|
||||||
new Tablesort(table)
|
tbody.last = tbodyNew
|
||||||
|
sort.refresh()
|
||||||
el.appendChild(table)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue