Fully resolve gateway names in hopglass (#57)

Depends on hopglass/hopglass-server#56
This commit is contained in:
Marvin W 2016-08-05 19:47:25 +02:00 committed by PetaByteBoy // Milan Pässler
parent bf2e858c24
commit cb065d8d07
4 changed files with 48 additions and 23 deletions

View file

@ -240,7 +240,20 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
}
}
function showGateway(d) {
function createLink(target, router) {
var link = document.createElement("a")
if (!target) return link
var unknown = !(target.node)
link.classList.add("hostname")
link.textContent = unknown ? (target.id ? target.id : target) : target.node.nodeinfo.hostname
if (!unknown) {
link.href = "#"
link.onclick = router.node(target.node)
}
return link
}
function showGateway(d, router) {
var nh
if (dictGet(d.statistics, ["nexthop"]))
nh = dictGet(d.statistics, ["nexthop"])
@ -248,13 +261,16 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
nh = dictGet(d.statistics, ["gateway_nexthop"])
var gw = dictGet(d.statistics, ["gateway"])
if (gw && !nh)
return gw
if (gw && nh)
if (gw === nh)
return gw
else
return nh + " -> ... -> " + gw
if (!gw) return null
return function (el) {
if (nh) {
el.appendChild(createLink(nh, router))
if (gw !== nh)
el.appendChild(document.createTextNode(" -> ... -> "))
}
if (gw !== nh)
el.appendChild(createLink(gw, router))
}
}
function showPages(d) {
@ -333,7 +349,7 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
attributeEntry(attributes, "Arbeitsspeicher", showRAM(d))
attributeEntry(attributes, "IP Adressen", showIPs(d))
attributeEntry(attributes, "Webseite", showPages(d))
attributeEntry(attributes, "Gewähltes Gateway", showGateway(d))
attributeEntry(attributes, "Gewähltes Gateway", showGateway(d, router))
attributeEntry(attributes, "Autom. Updates", showAutoupdate(d))
attributeEntry(attributes, "Clients", showClients(d))
@ -392,13 +408,7 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
tr.appendChild(td1)
var td2 = document.createElement("td")
var a1 = document.createElement("a")
a1.classList.add("hostname")
a1.textContent = unknown ? d.id : d.node.nodeinfo.hostname
if (!unknown)
a1.href = "#"
a1.onclick = router.node(d.node)
td2.appendChild(a1)
td2.appendChild(createLink(d, router))
if (!unknown && has_location(d.node)) {
var span = document.createElement("span")

View file

@ -123,6 +123,15 @@ function (moment, Router, L, GUI, numeral) {
nodes.forEach( function (d) {
d.neighbours = []
if (d.statistics) {
/*eslint camelcase:0*/
if ("gateway" in d.statistics && d.statistics.gateway in graphnodes)
d.statistics.gateway = {"node": graphnodes[d.statistics.gateway], "id": d.statistics.gateway}
if ("nexthop" in d.statistics && d.statistics.nexthop in graphnodes)
d.statistics.nexthop = {"node": graphnodes[d.statistics.nexthop], "id": d.statistics.nexthop}
if ("gateway_nexthop" in d.statistics && d.statistics.gateway_nexthop in graphnodes)
d.statistics.gateway_nexthop = {"node": graphnodes[d.statistics.gateway_nexthop], "id": d.statistics.gateway_nexthop}
}
})
links.forEach( function (d) {

View file

@ -13,7 +13,7 @@ define(function () {
return d.statistics.clients ? d.statistics.clients : 0
}))
var totalGateways = sum(Array.from(new Set(d.nodes.all.filter(online).map( function(d) {
return d.statistics.gateway
return ("gateway" in d.statistics && d.statistics.gateway.id) ? d.statistics.gateway.id : d.statistics.gateway
}).concat(d.nodes.all.filter( function (d) {
return d.flags.gateway
})))).map(function(d) {

View file

@ -156,8 +156,11 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc
if (d === null)
return null
if (d in nodeDict)
return nodeDict[d].nodeinfo.hostname
if (d.node)
return d.node.nodeinfo.hostname
if (d.id)
return d.id
return d
})
@ -166,8 +169,11 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc
if (d === null)
return null
if (d in nodeDict)
return nodeDict[d].nodeinfo.hostname
if (d.node)
return d.node.nodeinfo.hostname
if (d.id)
return d.id
return d
})
@ -188,8 +194,8 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc
fillTable("Koordinaten", geoTable, geoDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Uplink", uplinkTable, uplinkDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Autom. Updates", autoTable, autoDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Nodes an Gateway", gwNodesTable, gwNodesDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Clients an Gateway", gwClientsTable, gwClientsDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Gateway", gwNodesTable, gwNodesDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Gateway", gwClientsTable, gwClientsDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Site", siteTable, siteDict.sort(function (a, b) { return b[1] - a[1] }))
}