meshviewer/lib/infobox/link.js

50 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-03-25 10:21:09 +00:00
define(function () {
2016-03-08 19:01:38 +00:00
function showStatImg(o, source, target) {
2016-03-16 19:40:08 +00:00
var subst = {}
subst["{SOURCE}"] = source
subst["{TARGET}"] = target
return showStat(o, subst)
2016-03-08 19:01:38 +00:00
}
2015-03-25 18:45:21 +00:00
return function (config, el, router, d) {
var unknown = !(d.source.node)
2015-03-25 10:21:09 +00:00
var h2 = document.createElement("h2")
2015-03-30 01:20:43 +00:00
var a1 = document.createElement("a")
if (!unknown) {
a1.href = "#"
a1.onclick = router.node(d.source.node)
}
a1.textContent = unknown ? d.source.id : d.source.node.nodeinfo.hostname
2015-03-25 10:21:09 +00:00
h2.appendChild(a1)
2016-02-18 16:38:36 +00:00
h2.appendChild(document.createTextNode(" → "))
2015-03-30 01:20:43 +00:00
var a2 = document.createElement("a")
2015-03-25 10:21:09 +00:00
a2.href = "#"
2015-03-25 18:45:21 +00:00
a2.onclick = router.node(d.target.node)
2015-03-25 10:21:09 +00:00
a2.textContent = d.target.node.nodeinfo.hostname
h2.appendChild(a2)
el.appendChild(h2)
var attributes = document.createElement("table")
attributes.classList.add("attributes")
attributeEntry(attributes, "TQ", showTq(d))
attributeEntry(attributes, "Entfernung", showDistance(d))
2016-02-18 19:26:05 +00:00
attributeEntry(attributes, "Typ", d.type)
var hw1 = unknown ? null : dictGet(d.source.node.nodeinfo, ["hardware", "model"])
2015-05-30 10:29:43 +00:00
var hw2 = dictGet(d.target.node.nodeinfo, ["hardware", "model"])
attributeEntry(attributes, "Hardware", (hw1 != null ? hw1 : "unbekannt") + " " + (hw2 != null ? hw2 : "unbekannt"))
2015-03-25 10:21:09 +00:00
el.appendChild(attributes)
2016-03-08 19:01:38 +00:00
if (config.linkInfos) {
var source = d.source.node_id
var target = d.target.node_id
config.linkInfos.forEach( function (linkInfo) {
var h4 = document.createElement("h4")
h4.textContent = linkInfo.name
el.appendChild(h4)
el.appendChild(showStatImg(linkInfo, source, target))
})
}
2015-03-25 10:21:09 +00:00
}
})