luci-mod-network: ensure consistent bridge port and network interface order
authorJo-Philipp Wich <[email protected]>
Wed, 27 Jul 2022 15:33:59 +0000 (17:33 +0200)
committerJo-Philipp Wich <[email protected]>
Mon, 3 Apr 2023 11:20:46 +0000 (13:20 +0200)
Ref: #5899
Signed-off-by: Jo-Philipp Wich <[email protected]>
(cherry picked from commit 801d4513b25117de20706695dda715ff34c9355b)

modules/luci-mod-network/htdocs/luci-static/resources/tools/network.js
modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js

index 11d2162d1116480c16a76af5c38dfe3f45d720ee..c31015a564cf76e663e4ee6c89dc8ab3bef0a74d 100644 (file)
@@ -780,6 +780,8 @@ return baseclass.extend({
                                return network.instantiateDevice(port)
                        }).filter(function(dev) {
                                return dev.getType() != 'wifi' || dev.isUp();
+                       }).sort(function(a, b) {
+                               return L.naturalCompare(a.getName(), b.getName());
                        });
 
                        this.children = this.children.filter(function(opt) { return !opt.option.match(/^port_/) });
@@ -893,18 +895,6 @@ return baseclass.extend({
                for (var port_name in seen_ports)
                        ports.push(port_name);
 
-               ports.sort(function(a, b) {
-                       var m1 = a.match(/^(.+?)([0-9]*)$/),
-                           m2 = b.match(/^(.+?)([0-9]*)$/);
-
-                       if (m1[1] < m2[1])
-                               return -1;
-                       else if (m1[1] > m2[1])
-                               return 1;
-                       else
-                               return +(m1[2] || 0) - +(m2[2] || 0);
-               });
-
                ss.updatePorts(ports);
        },
 
index e5376d07c878f8096b3ab26bea0760940fa9ace2..b88183d51f127661c1dbcff1047b25179e8821cf 100644 (file)
 
 var isReadonlyView = !L.hasViewPermission() || null;
 
-function strcmp(a, b) {
-       if (a < b)
-               return -1;
-
-       if (a > b)
-               return 1;
-
-       return 0;
-}
-
 function count_changes(section_id) {
        var changes = ui.changes.changes, n = 0;
 
@@ -545,7 +535,7 @@ return view.extend({
                                var protocols = network.getProtocols();
 
                                protocols.sort(function(a, b) {
-                                       return strcmp(a.getProtocol(), b.getProtocol());
+                                       return L.naturalCompare(a.getProtocol(), b.getProtocol());
                                });
 
                                o = s.taboption('general', form.DummyValue, '_ifacestat_modal', _('Status'));
@@ -1101,7 +1091,7 @@ return view.extend({
                            proto, name, device;
 
                        protocols.sort(function(a, b) {
-                               return a.getProtocol() > b.getProtocol();
+                               return L.naturalCompare(a.getProtocol(), b.getProtocol());
                        });
 
                        s2.render = function() {
@@ -1263,7 +1253,7 @@ return view.extend({
 
                s.cfgsections = function() {
                        var sections = uci.sections('network', 'device'),
-                           section_ids = sections.sort(function(a, b) { return strcmp(a.name, b.name) }).map(function(s) { return s['.name'] });
+                           section_ids = sections.sort(function(a, b) { return L.naturalCompare(a.name, b.name) }).map(function(s) { return s['.name'] });
 
                        for (var i = 0; i < netDevs.length; i++) {
                                if (sections.filter(function(s) { return s.name == netDevs[i].getName() }).length)