luci-base: network.js: sort interface statuses by metric, then name
[project/luci.git] / modules / luci-base / htdocs / luci-static / resources / network.js
index 0cd4f29bc4d5aa3b3a28f25a37aed87d0e05aaf5..1e24915f979ff700a7961cfef1f86c0227b15344 100644 (file)
@@ -108,7 +108,7 @@ function getProtocolHandlers(cache) {
                        Object.assign(protos, { none: { no_device: false } });
 
                /* Hack: emulate relayd protocol */
-               if (!protos.hasOwnProperty('relay'))
+               if (!protos.hasOwnProperty('relay') && L.hasSystemFeature('relayd'))
                        Object.assign(protos, { relay: { no_device: true } });
 
                Object.assign(_protospecs, protos);
@@ -356,7 +356,9 @@ function initNetworkState(refresh) {
                        L.resolveDefault(callLuciWirelessDevices(), {}),
                        L.resolveDefault(callLuciHostHints(), {}),
                        getProtocolHandlers(),
-                       uci.load(['network', 'wireless', 'luci'])
+                       L.resolveDefault(uci.load('network')),
+                       L.resolveDefault(uci.load('wireless')),
+                       L.resolveDefault(uci.load('luci'))
                ]).then(function(data) {
                        var netifd_ifaces = data[0],
                            board_json    = data[1],
@@ -1222,6 +1224,22 @@ Network = baseclass.extend(/** @lends LuCI.network.prototype */ {
                                devices[netid] = this.instantiateDevice(netid);
                        }
 
+                       /* find uci declared devices */
+                       var uciDevices = uci.sections('network', 'device');
+
+                       for (var i = 0; i < uciDevices.length; i++) {
+                               var type = uciDevices[i].type,
+                                   name = uciDevices[i].name;
+
+                               if (!type || !name || devices.hasOwnProperty(name))
+                                       continue;
+
+                               if (type == 'bridge')
+                                       _state.isBridge[name] = true;
+
+                               devices[name] = this.instantiateDevice(name);
+                       }
+
                        var rv = [];
 
                        for (var netdev in devices)
@@ -1435,6 +1453,18 @@ Network = baseclass.extend(/** @lends LuCI.network.prototype */ {
                                }
                        }
 
+                       rv.sort(function(a, b) {
+                               if (a.metric != b.metric)
+                                       return (a.metric - b.metric);
+
+                               if (a.interface < b.interface)
+                                       return -1;
+                               else if (a.interface > b.interface)
+                                       return 1;
+
+                               return 0;
+                       });
+
                        return rv;
                }, this));
        },
@@ -3552,6 +3582,24 @@ WifiNetwork = baseclass.extend(/** @lends LuCI.network.WifiNetwork.prototype */
                return ifname;
        },
 
+       /**
+        * Get the Linux VLAN network device names.
+        *
+        * @returns {string[]}
+        * Returns the current Linux VLAN network device name as resolved
+        * from `ubus` runtime information or empty array if this network
+        * has no associated VLAN network devices.
+        */
+       getVlanIfnames: function() {
+               var vlans = L.toArray(this.ubus('net', 'vlans')),
+                   ifnames = [];
+
+               for (var i = 0; i < vlans.length; i++)
+                       ifnames.push(vlans[i]['ifname']);
+
+               return ifnames;
+       },
+
        /**
         * Get the name of the corresponding wifi radio device.
         *
@@ -3862,7 +3910,15 @@ WifiNetwork = baseclass.extend(/** @lends LuCI.network.WifiNetwork.prototype */
         * with this network.
         */
        getAssocList: function() {
-               return callIwinfoAssoclist(this.getIfname());
+               var tasks = [];
+               var ifnames = [ this.getIfname() ].concat(this.getVlanIfnames());
+
+               for (var i = 0; i < ifnames.length; i++)
+                       tasks.push(callIwinfoAssoclist(ifnames[i]));
+
+               return Promise.all(tasks).then(function(values) {
+                       return Array.prototype.concat.apply([], values);
+               });
        },
 
        /**