mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 14:04:23 +00:00
Merge pull request #19069 from Chocobo1/sort
WebUI: use natural sort on tracker list
This commit is contained in:
commit
83e6afcb71
@ -116,8 +116,7 @@ function getHost(url) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// hack: URL can not get hostname from udp protocol
|
// hack: URL can not get hostname from udp protocol
|
||||||
url = url.replace(/^udp:/, 'https:');
|
const parsedUrl = new URL(url.replace(/^udp:/, 'https:'));
|
||||||
const parsedUrl = new URL(url);
|
|
||||||
// host: "example.com:8443"
|
// host: "example.com:8443"
|
||||||
// hostname: "example.com"
|
// hostname: "example.com"
|
||||||
const host = parsedUrl.hostname;
|
const host = parsedUrl.hostname;
|
||||||
@ -623,16 +622,12 @@ window.addEvent('load', function() {
|
|||||||
|
|
||||||
// Sort trackers by hostname
|
// Sort trackers by hostname
|
||||||
const sortedList = [...trackerList.entries()].sort((left, right) => {
|
const sortedList = [...trackerList.entries()].sort((left, right) => {
|
||||||
const leftHost = getHost(left[1].url.toLowerCase());
|
const leftHost = getHost(left[1].url);
|
||||||
const rightHost = getHost(right[1].url.toLowerCase());
|
const rightHost = getHost(right[1].url);
|
||||||
if (leftHost < rightHost)
|
return window.qBittorrent.Misc.naturalSortCollator.compare(leftHost, rightHost);
|
||||||
return -1;
|
|
||||||
if (leftHost > rightHost)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
});
|
});
|
||||||
for (const [hash, tracker] of sortedList) {
|
for (const [hash, tracker] of sortedList) {
|
||||||
trackerFilterList.appendChild(createLink(hash, getHost(tracker.url) + ' (%1)', tracker.torrents.length));
|
trackerFilterList.appendChild(createLink(hash, (getHost(tracker.url) + ' (%1)'), tracker.torrents.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
highlightSelectedTracker();
|
highlightSelectedTracker();
|
||||||
|
@ -57,8 +57,6 @@ window.qBittorrent.DynamicTable = (function() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const naturalSortCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
|
|
||||||
|
|
||||||
const compareNumbers = (val1, val2) => {
|
const compareNumbers = (val1, val2) => {
|
||||||
if (val1 < val2)
|
if (val1 < val2)
|
||||||
return -1;
|
return -1;
|
||||||
@ -412,7 +410,7 @@ window.qBittorrent.DynamicTable = (function() {
|
|||||||
const value2 = this.getRowValue(row2);
|
const value2 = this.getRowValue(row2);
|
||||||
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
||||||
return compareNumbers(value1, value2);
|
return compareNumbers(value1, value2);
|
||||||
return naturalSortCollator.compare(value1, value2);
|
return window.qBittorrent.Misc.naturalSortCollator.compare(value1, value2);
|
||||||
};
|
};
|
||||||
column['updateTd'] = function(td, row) {
|
column['updateTd'] = function(td, row) {
|
||||||
const value = this.getRowValue(row);
|
const value = this.getRowValue(row);
|
||||||
@ -2705,7 +2703,7 @@ window.qBittorrent.DynamicTable = (function() {
|
|||||||
const value2 = this.getRowValue(row2);
|
const value2 = this.getRowValue(row2);
|
||||||
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
||||||
return compareNumbers(value1, value2);
|
return compareNumbers(value1, value2);
|
||||||
return naturalSortCollator.compare(value1, value2);
|
return window.qBittorrent.Misc.naturalSortCollator.compare(value1, value2);
|
||||||
};
|
};
|
||||||
column['updateTd'] = function(td, row) {
|
column['updateTd'] = function(td, row) {
|
||||||
const value = this.getRowValue(row);
|
const value = this.getRowValue(row);
|
||||||
@ -2801,7 +2799,7 @@ window.qBittorrent.DynamicTable = (function() {
|
|||||||
const value2 = this.getRowValue(row2);
|
const value2 = this.getRowValue(row2);
|
||||||
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
||||||
return compareNumbers(value1, value2);
|
return compareNumbers(value1, value2);
|
||||||
return naturalSortCollator.compare(value1, value2);
|
return window.qBittorrent.Misc.naturalSortCollator.compare(value1, value2);
|
||||||
};
|
};
|
||||||
column['updateTd'] = function(td, row) {
|
column['updateTd'] = function(td, row) {
|
||||||
const value = this.getRowValue(row);
|
const value = this.getRowValue(row);
|
||||||
@ -2887,7 +2885,7 @@ window.qBittorrent.DynamicTable = (function() {
|
|||||||
const value2 = this.getRowValue(row2);
|
const value2 = this.getRowValue(row2);
|
||||||
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
||||||
return compareNumbers(value1, value2);
|
return compareNumbers(value1, value2);
|
||||||
return naturalSortCollator.compare(value1, value2);
|
return window.qBittorrent.Misc.naturalSortCollator.compare(value1, value2);
|
||||||
};
|
};
|
||||||
column['updateTd'] = function(td, row) {
|
column['updateTd'] = function(td, row) {
|
||||||
const value = this.getRowValue(row);
|
const value = this.getRowValue(row);
|
||||||
@ -2974,7 +2972,7 @@ window.qBittorrent.DynamicTable = (function() {
|
|||||||
const value2 = this.getRowValue(row2);
|
const value2 = this.getRowValue(row2);
|
||||||
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
||||||
return compareNumbers(value1, value2);
|
return compareNumbers(value1, value2);
|
||||||
return naturalSortCollator.compare(value1, value2);
|
return window.qBittorrent.Misc.naturalSortCollator.compare(value1, value2);
|
||||||
};
|
};
|
||||||
column['updateTd'] = function(td, row) {
|
column['updateTd'] = function(td, row) {
|
||||||
const value = this.getRowValue(row);
|
const value = this.getRowValue(row);
|
||||||
@ -3024,7 +3022,7 @@ window.qBittorrent.DynamicTable = (function() {
|
|||||||
const value2 = this.getRowValue(row2);
|
const value2 = this.getRowValue(row2);
|
||||||
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
if ((typeof(value1) === 'number') && (typeof(value2) === 'number'))
|
||||||
return compareNumbers(value1, value2);
|
return compareNumbers(value1, value2);
|
||||||
return naturalSortCollator.compare(value1, value2);
|
return window.qBittorrent.Misc.naturalSortCollator.compare(value1, value2);
|
||||||
};
|
};
|
||||||
column['updateTd'] = function(td, row) {
|
column['updateTd'] = function(td, row) {
|
||||||
const value = this.getRowValue(row);
|
const value = this.getRowValue(row);
|
||||||
|
@ -41,6 +41,7 @@ window.qBittorrent.Misc = (function() {
|
|||||||
friendlyFloat: friendlyFloat,
|
friendlyFloat: friendlyFloat,
|
||||||
parseHtmlLinks: parseHtmlLinks,
|
parseHtmlLinks: parseHtmlLinks,
|
||||||
escapeHtml: escapeHtml,
|
escapeHtml: escapeHtml,
|
||||||
|
naturalSortCollator: naturalSortCollator,
|
||||||
safeTrim: safeTrim,
|
safeTrim: safeTrim,
|
||||||
toFixedPointString: toFixedPointString,
|
toFixedPointString: toFixedPointString,
|
||||||
containsAllTerms: containsAllTerms,
|
containsAllTerms: containsAllTerms,
|
||||||
@ -178,6 +179,8 @@ window.qBittorrent.Misc = (function() {
|
|||||||
return escapedString;
|
return escapedString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const naturalSortCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
|
||||||
|
|
||||||
const safeTrim = function(value) {
|
const safeTrim = function(value) {
|
||||||
try {
|
try {
|
||||||
return value.trim();
|
return value.trim();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user