infobox/node: resolve nexthop and gateway from data

not perfect yet: the mac address doesn't always match
This commit is contained in:
Milan Paessler 2016-11-19 02:17:08 +01:00
parent 7d145141c1
commit 9e7049c9e3
4 changed files with 30 additions and 8 deletions

View file

@ -34,6 +34,11 @@ define(["filters/nodefilter"], function (NodeFilter) {
filteredData = new NodeFilter(filter)(data) filteredData = new NodeFilter(filter)(data)
filteredData.nodeDict = {}
filteredData.nodes.all.forEach(function (d) {
filteredData.nodeDict[dictGet(d, ["nodeinfo", "network", "mac"]).substr(9)] = d
})
targets.forEach( function (t) { targets.forEach( function (t) {
t.setData(filteredData) t.setData(filteredData)
}) })

View file

@ -85,6 +85,7 @@ function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Legend, Linklist,
fanoutUnfiltered.add(meshstats) fanoutUnfiltered.add(meshstats)
fanoutUnfiltered.add(newnodeslist) fanoutUnfiltered.add(newnodeslist)
fanoutUnfiltered.add(lostnodeslist) fanoutUnfiltered.add(lostnodeslist)
fanoutUnfiltered.add(infobox)
fanout.add(nodelist) fanout.add(nodelist)
fanout.add(linklist) fanout.add(linklist)
fanout.add(statistics) fanout.add(statistics)

View file

@ -2,6 +2,7 @@ define(["infobox/link", "infobox/node", "infobox/location"], function (Link, Nod
return function (config, sidebar, router) { return function (config, sidebar, router) {
var self = this var self = this
var el var el
var nodeDict
function destroy() { function destroy() {
if (el && el.parentNode) { if (el && el.parentNode) {
@ -33,7 +34,7 @@ define(["infobox/link", "infobox/node", "infobox/location"], function (Link, Nod
self.gotoNode = function (d) { self.gotoNode = function (d) {
create() create()
new Node(config, el, router, d) new Node(config, el, router, d, nodeDict)
} }
self.gotoLink = function (d) { self.gotoLink = function (d) {
@ -46,6 +47,10 @@ define(["infobox/link", "infobox/node", "infobox/location"], function (Link, Nod
new Location(config, el, router, d) new Location(config, el, router, d)
} }
self.setData = function (d) {
nodeDict = d.nodeDict
}
return self return self
} }
}) })

View file

@ -311,7 +311,18 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
return link return link
} }
function showGateway(d, router) { function lookupNode(d, nodeDict) {
if (!d)
return null
var node = nodeDict[d.substr(9)]
if (!node)
return d
return {node: node}
}
function showGateway(d, router, nodeDict) {
var nh var nh
if (dictGet(d.statistics, ["nexthop"])) if (dictGet(d.statistics, ["nexthop"]))
nh = dictGet(d.statistics, ["nexthop"]) nh = dictGet(d.statistics, ["nexthop"])
@ -322,12 +333,12 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
if (!gw) return null if (!gw) return null
return function (el) { return function (el) {
if (nh) { if (nh) {
el.appendChild(createLink(nh, router)) el.appendChild(createLink(lookupNode(nh, nodeDict), router))
if (gw !== nh) if (nh.substr(9) !== gw.substr(9))
el.appendChild(document.createTextNode(" -> ... -> ")) el.appendChild(document.createTextNode(" -> ... -> "))
} }
if (gw !== nh) if (!nh || nh.substr(9) !== gw.substr(9))
el.appendChild(createLink(gw, router)) el.appendChild(createLink(lookupNode(gw, nodeDict), router))
} }
} }
@ -408,7 +419,7 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
return showStat(o, subst) return showStat(o, subst)
} }
return function(config, el, router, d) { return function(config, el, router, d, nodeDict) {
var attributes = document.createElement("table") var attributes = document.createElement("table")
attributes.classList.add("attributes") attributes.classList.add("attributes")
@ -455,7 +466,7 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
attributeEntry(attributes, "Arbeitsspeicher", showRAM(d)) attributeEntry(attributes, "Arbeitsspeicher", showRAM(d))
attributeEntry(attributes, "IP Adressen", showIPs(d)) attributeEntry(attributes, "IP Adressen", showIPs(d))
attributeEntry(attributes, "Webseite", showPages(d)) attributeEntry(attributes, "Webseite", showPages(d))
attributeEntry(attributes, "Gewähltes Gateway", showGateway(d, router)) attributeEntry(attributes, "Gewähltes Gateway", showGateway(d, router, nodeDict))
attributeEntry(attributes, "Autom. Updates", showAutoupdate(d)) attributeEntry(attributes, "Autom. Updates", showAutoupdate(d))
attributeEntry(attributes, "Clients", showClients(d), showMeshClients(d)) attributeEntry(attributes, "Clients", showClients(d), showMeshClients(d))