luci-app-bmx6: Fix topology graph with backwards compatibility
authorPau Escrich <p4u@dabax.net>
Tue, 25 Feb 2014 17:13:05 +0000 (18:13 +0100)
committerPau Escrich <p4u@dabax.net>
Tue, 25 Feb 2014 17:14:07 +0000 (18:14 +0100)
Signed-off-by: Pau Escrich <p4u@dabax.net>
luci-app-bmx6/files/usr/lib/lua/luci/controller/bmx6.lua
luci-app-bmx6/files/usr/lib/lua/luci/view/bmx6/graph.htm

index 26e1cb3..9529cf8 100644 (file)
@@ -240,10 +240,10 @@ function action_topology()
                                if first then
                                        first = false
                                else
-                                       topology = topology .. ', '
+                                               topology = topology .. ', '
                                end
            
-                               topology = topology .. '{ "globalId": "%s", "links": [' %o.globalId:match("^[^%.]+")
+                                       topology = topology .. '{ "name": "%s", "links": [' %o.name
            
                                local first2 = true
            
@@ -252,10 +252,10 @@ function action_topology()
                                                first2 = false
                                        else
                                                topology = topology .. ', '
-                                       end
-           
-                                       topology = topology .. '{ "globalId": "%s", "rxRate": %s, "txRate": %s }'
-                                               %{ l.globalId:match("^[^%.]+"), l.rxRate, l.txRate }
+                                               end
+                                               name = l.name or l.llocalIp or "unknown"
+                                               topology = topology .. '{ "name": "%s", "rxRate": %s, "txRate": %s }'
+                                                       %{ name, l.rxRate, l.txRate }
            
                                end
            
index a4dabb7..401e932 100644 (file)
@@ -57,20 +57,20 @@ the file called "COPYING".
                        for (var i = 0; i < (data.length); i++)
                        {
                                // node->node
-                               if (data[i].globalId)
+                               if (data[i].name)
                                        {
                                        for (var j = 0; j < (data[i].links.length); j++)
                                                 {
-                                                var key = (data[i].globalId < data[i].links[j].globalId)
-                                                       ? data[i].globalId + '|' + data[i].links[j].globalId
-                                                       : data[i].links[j].globalId + '|' + data[i].globalId;
+                                                       var key = (data[i].name < data[i].links[j].name)
+                                                       ? data[i].name + '|' + data[i].links[j].name
+                                                       : data[i].links[j].name + '|' + data[i].name;
 
                                                        var rxRate = data[i].links[j].rxRate;
                                                        var txRate = data[i].links[j].txRate;
 
                                                        if (!seen[key] && rxRate>0 && txRate>0)
                                                        {
-                                                        g.addEdge(data[i].globalId, data[i].links[j].globalId,
+                                                        g.addEdge(data[i].name, data[i].links[j].name,
                                                                { label: rxRate + '/' + txRate,
                                                                directed: false, stroke: '#aaaaaa', fill: '#ffffff',
                                                                'label-style': { 'font-size': 8 }});