diff --git a/lib/infobox/main.js b/lib/infobox/main.js index 2822ed3..e436efd 100644 --- a/lib/infobox/main.js +++ b/lib/infobox/main.js @@ -36,9 +36,9 @@ define(['infobox/link', 'infobox/node', 'infobox/location'], function (link, nod self.resetView = destroy; - self.gotoNode = function gotoNode(d) { + self.gotoNode = function gotoNode(d, gateways) { create(); - node(config, el, router, d); + node(config, el, router, d, gateways); }; self.gotoLink = function gotoLink(d) { diff --git a/lib/infobox/node.js b/lib/infobox/node.js index 22ae9f8..871d149 100644 --- a/lib/infobox/node.js +++ b/lib/infobox/node.js @@ -178,7 +178,7 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'], return helper.showStat(o, subst); } - return function (config, el, router, d) { + return function (config, el, router, d, gateways) { var linkScale = d3Interpolate.interpolate('#F02311', '#04C714'); function renderNeighbourRow(n) { @@ -235,7 +235,7 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'], helper.attributeEntry(attributes, 'node.ram', showRAM(d)); } helper.attributeEntry(attributes, 'node.ipAddresses', showIPs(d)); - helper.attributeEntry(attributes, 'node.selectedGateway', helper.dictGet(d.statistics, ['gateway'])); + helper.attributeEntry(attributes, 'node.selectedGateway', gateways[helper.dictGet(d.statistics, ['gateway'])]); helper.attributeEntry(attributes, 'node.update', showAutoupdate(d)); helper.attributeEntry(attributes, 'node.clients', showClients(d)); diff --git a/lib/main.js b/lib/main.js index 5836c13..ca34e48 100644 --- a/lib/main.js +++ b/lib/main.js @@ -10,6 +10,7 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'], dataGraph.batadv = {}; dataGraph.batadv.nodes = []; dataGraph.batadv.links = []; + var gateways = {}; function rearrangeLinks(d) { d.source += dataGraph.batadv.nodes.length; @@ -86,6 +87,12 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'], nodes.forEach(function (d) { d.neighbours = []; + if (d.flags.gateway) { + var mesh = d.nodeinfo.network.mesh; + mesh[Object.keys(mesh)[0]].interfaces.tunnel.forEach(function (mac) { + gateways[mac] = d.nodeinfo.hostname; + }); + } }); links.forEach(function (d) { @@ -123,7 +130,8 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'], graph: { links: links, nodes: graph.nodes - } + }, + gateways: gateways }; } diff --git a/lib/proportions.js b/lib/proportions.js index 83cdb21..8c8af49 100644 --- a/lib/proportions.js +++ b/lib/proportions.js @@ -12,8 +12,10 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'], var hwTable; var geoTable; var autoTable; + var gatewayTable; var siteTable; + function showStatGlobal(o) { return helper.showStat(o); } @@ -105,16 +107,25 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'], return _.t('node.deactivated'); }); + var gatewayDict = count(nodes, ['statistics', 'gateway'], function (d) { + for (var mac in data.gateways) { + if (data.gateways.hasOwnProperty(mac) && mac === d) { + d = data.gateways[mac]; + return d; + } + } + return null; + }); + var siteDict = count(nodes, ['nodeinfo', 'system', 'site_code'], function (d) { - var rt = d; if (config.siteNames) { config.siteNames.forEach(function (t) { if (d === t.site) { - rt = t.name; + d = t.name; } }); } - return rt; + return d; }); statusTable = fillTable('node.status', statusTable, statusDict.sort(function (a, b) { @@ -138,6 +149,9 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'], autoTable = fillTable('node.update', autoTable, autoDict.sort(function (a, b) { return b[1] - a[1]; })); + gatewayTable = fillTable('node.gateway', gatewayTable, gatewayDict.sort(function (a, b) { + return b[1] - a[1]; + })); siteTable = fillTable('node.site', siteTable, siteDict.sort(function (a, b) { return b[1] - a[1]; })); @@ -150,6 +164,7 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'], self.renderSingle(el, 'node.hardware', hwTable); self.renderSingle(el, 'node.visible', geoTable); self.renderSingle(el, 'node.update', autoTable); + self.renderSingle(el, 'node.gateway', gatewayTable); self.renderSingle(el, 'node.site', siteTable); if (config.globalInfos) { diff --git a/lib/utils/helper.js b/lib/utils/helper.js index 1ee8ac2..3587542 100644 --- a/lib/utils/helper.js +++ b/lib/utils/helper.js @@ -48,10 +48,6 @@ define({ return 1; }, - trueDefault: function trueDefault(d) { - return d === undefined ? true : d; - }, - dictGet: function dictGet(dict, key) { var k = key.shift(); diff --git a/lib/utils/router.js b/lib/utils/router.js index 2fb1988..55ba478 100644 --- a/lib/utils/router.js +++ b/lib/utils/router.js @@ -3,7 +3,7 @@ define(['Navigo'], function (Navigo) { return function (language) { var init = false; - var objects = { nodes: {}, links: {} }; + var objects = { nodes: {}, links: {}, gateways: {} }; var targets = []; var views = {}; var current = {}; @@ -18,7 +18,7 @@ define(['Navigo'], function (Navigo) { function gotoNode(d) { if (d.nodeId in objects.nodes) { targets.forEach(function (t) { - t.gotoNode(objects.nodes[d.nodeId]); + t.gotoNode(objects.nodes[d.nodeId], objects.gateways); }); } } @@ -141,6 +141,7 @@ define(['Navigo'], function (Navigo) { router.setData = function setData(data) { objects.nodes = {}; objects.links = {}; + objects.gateways = data.gateways; data.nodes.all.forEach(function (d) { objects.nodes[d.nodeinfo.node_id] = d;