From fc2765c62ee3cced8ca9115e62879be8c400c631 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 7 Oct 2021 09:09:14 -0700 Subject: [PATCH] Sorting fix, #3178 --- views/default-mobile.handlebars | 16 ++++++++++++++++ views/default.handlebars | 23 +++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/views/default-mobile.handlebars b/views/default-mobile.handlebars index 8c77713b..76f97c81 100644 --- a/views/default-mobile.handlebars +++ b/views/default-mobile.handlebars @@ -3222,10 +3222,26 @@ deviceHeaderTotal = 0; } + /* 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; } 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; } function deviceSort(a, b) { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; } function deviceHostSort(a, b) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; } + */ + + var sortCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }) + function meshSort(a, b) { + var x = sortCollator.compare(a.meshnamel, b.meshnamel); + if (x != 0) return x; + x = sortCollator.compare(a.meshid, b.meshid); + if (x != 0) return x; + if (showRealNames == true) { return sortCollator.compare(a.rnamel, b.rnamel); } + return sortCollator.compare(a.namel, b.namel); + } + 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); } } } + function deviceSort(a, b) { return sortCollator.compare(a.namel, b.namel); } + function deviceHostSort(a, b) { return sortCollator.compare(a.rnamel, b.rnamel); } + // // MY DEVICE diff --git a/views/default.handlebars b/views/default.handlebars index 496b3b4f..1935d99b 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -4009,7 +4009,8 @@ if ((sort == 3) || (sort == 4)) { var groupNames = [], tagDeviceHeaderId = 0; for (var i in groups) { groupNames.push(i); } - groupNames.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); }); + //groupNames.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); }); + groupNames.sort(function (a, b) { return sortCollator.compare(a.toLowerCase(), b.toLowerCase()); }); for (var j in groupNames) { var i = groupNames[j]; if (view == 2) { @@ -5411,7 +5412,8 @@ if (!skipsave) { putstore('sort', sort); } } - 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; } + /* + function nameSort(a, b) { var aa = a.name.toLowerCase(), bb = b.name.toLowerCase(); return sortCollator.compare(a.namel, b.namel); } function meshSort(a, b) { if (a.meshnamel > b.meshnamel) return 1; if (a.meshnamel < b.meshnamel) return -1; @@ -5425,6 +5427,23 @@ function deviceSort(a, b) { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; } function deviceHostSort(a, b) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; } 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); } + */ + + var sortCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }) + function nameSort(a, b) { var aa = a.name.toLowerCase(), bb = b.name.toLowerCase(); return sortCollator.compare(aa, bb); } + function meshSort(a, b) { + var x = sortCollator.compare(a.meshnamel, b.meshnamel); + if (x != 0) return x; + x = sortCollator.compare(a.meshid, b.meshid); + if (x != 0) return x; + if (showRealNames == true) { return sortCollator.compare(a.rnamel, b.rnamel); } + return sortCollator.compare(a.namel, b.namel); + } + 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); } } } + function deviceSort(a, b) { return sortCollator.compare(a.namel, b.namel); } + function deviceHostSort(a, b) { return sortCollator.compare(a.rnamel, b.rnamel); } + 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); } + function onSearchFocus(x) { searchFocus = x; } function clearDeviceSearch() { Q('KvmSearchInput').value = Q('SearchInput').value = ''; Q('DevFilterSelect').value = 0; onOnlineCheckBox(); mainUpdate(1); } function onMapSearchFocus(x) { mapSearchFocus = x; }