Sorting fix, #3178
Ylian Saint-Hilaire committed
Oct 7, 2021 at 09:09 UTC
fc2765c62ee3cced8ca9115e62879be8c400c631
2 files changed
+37
-2
views/default-mobile.handlebars
+16
@@ -3222,10 +3222,26 @@
3222
deviceHeaderTotal = 0;
3223
}
3224
3225
+ /*
3226
function meshSort(a, b) { if (a.meshnamel > b.meshnamel) return 1; if (a.meshnamel < b.meshnamel) return -1; if (a.meshid == b.meshid) { if (showRealNames == true) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; } else { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; } } return 0; }
3227
function powerSort(a, b) { var ap = a.pwr ? a.pwr : 0; var bp = b.pwr ? b.pwr : 0; if (ap == bp) { if (showRealNames == true) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; } else { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; } } if (ap > bp) return 1; if (ap < bp) return -1; return 0; }
3228
function deviceSort(a, b) { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; }
3229
function deviceHostSort(a, b) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; }
3230
+ */
3231
+
3232
+ var sortCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
3233
+ function meshSort(a, b) {
3234
+ var x = sortCollator.compare(a.meshnamel, b.meshnamel);
3235
+ if (x != 0) return x;
3236
+ x = sortCollator.compare(a.meshid, b.meshid);
3237
+ if (x != 0) return x;
3238
+ if (showRealNames == true) { return sortCollator.compare(a.rnamel, b.rnamel); }
3239
+ return sortCollator.compare(a.namel, b.namel);
3240
+ }
3241
+ function powerSort(a, b) { var ap = a.pwr ? a.pwr : 0; var bp = b.pwr ? b.pwr : 0; if (ap > bp) return -1; if (ap < bp) return 1; if (ap == bp) { if (showRealNames == true) { return sortCollator.compare(a.rnamel, b.rnamel); } else { return sortCollator.compare(a.namel, b.namel); } } }
3242
+ function deviceSort(a, b) { return sortCollator.compare(a.namel, b.namel); }
3243
+ function deviceHostSort(a, b) { return sortCollator.compare(a.rnamel, b.rnamel); }
3244
+
3245
3246
//
3247
// MY DEVICE
views/default.handlebars
+21
-2
@@ -4009,7 +4009,8 @@
4009
if ((sort == 3) || (sort == 4)) {
4010
var groupNames = [], tagDeviceHeaderId = 0;
4011
for (var i in groups) { groupNames.push(i); }
4012
- groupNames.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); });
4012
+ //groupNames.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); });
4013
+ groupNames.sort(function (a, b) { return sortCollator.compare(a.toLowerCase(), b.toLowerCase()); });
4014
for (var j in groupNames) {
4015
var i = groupNames[j];
4016
if (view == 2) {
@@ -5411,7 +5412,8 @@
5412
if (!skipsave) { putstore('sort', sort); }
5413
}
5414
5414
- function nameSort(a, b) { var aa = a.name.toLowerCase(), bb = b.name.toLowerCase(); if (aa > bb) return 1; if (aa < bb) return -1; return 0; }
5415
+ /*
5416
+ function nameSort(a, b) { var aa = a.name.toLowerCase(), bb = b.name.toLowerCase(); return sortCollator.compare(a.namel, b.namel); }
5417
function meshSort(a, b) {
5418
if (a.meshnamel > b.meshnamel) return 1;
5419
if (a.meshnamel < b.meshnamel) return -1;
@@ -5425,6 +5427,23 @@
5427
function deviceSort(a, b) { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; }
5428
function deviceHostSort(a, b) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; }
5429
function lastConnectSort(a, b) { var aa = a.lastconnect, bb = b.lastconnect; if (aa == null) { aa = 99999999999999; } if (bb == null) { bb = 99999999999999; } if (a.conn > 0) { aa = 99999999999998; } if (b.conn > 0) { bb = 99999999999998; } if (aa == bb) { return nameSort(a, b); } return (aa - bb); }
5430
+ */
5431
+
5432
+ var sortCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
5433
+ function nameSort(a, b) { var aa = a.name.toLowerCase(), bb = b.name.toLowerCase(); return sortCollator.compare(aa, bb); }
5434
+ function meshSort(a, b) {
5435
+ var x = sortCollator.compare(a.meshnamel, b.meshnamel);
5436
+ if (x != 0) return x;
5437
+ x = sortCollator.compare(a.meshid, b.meshid);
5438
+ if (x != 0) return x;
5439
+ if (showRealNames == true) { return sortCollator.compare(a.rnamel, b.rnamel); }
5440
+ return sortCollator.compare(a.namel, b.namel);
5441
+ }
5442
+ function powerSort(a, b) { var ap = a.pwr?a.pwr:0; var bp = b.pwr?b.pwr:0; if (ap > bp) return -1; if (ap < bp) return 1; if (ap == bp) { if (showRealNames == true) { return sortCollator.compare(a.rnamel, b.rnamel); } else { return sortCollator.compare(a.namel, b.namel); } } }
5443
+ function deviceSort(a, b) { return sortCollator.compare(a.namel, b.namel); }
5444
+ function deviceHostSort(a, b) { return sortCollator.compare(a.rnamel, b.rnamel); }
5445
+ function lastConnectSort(a, b) { var aa = a.lastconnect, bb = b.lastconnect; if (aa == null) { aa = 99999999999999; } if (bb == null) { bb = 99999999999999; } if (a.conn > 0) { aa = 99999999999998; } if (b.conn > 0) { bb = 99999999999998; } if (aa == bb) { return nameSort(a, b); } return (aa - bb); }
5446
+
5447
function onSearchFocus(x) { searchFocus = x; }
5448
function clearDeviceSearch() { Q('KvmSearchInput').value = Q('SearchInput').value = ''; Q('DevFilterSelect').value = 0; onOnlineCheckBox(); mainUpdate(1); }
5449
function onMapSearchFocus(x) { mapSearchFocus = x; }