1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 01:12:03 +00:00

File size sort

This commit is contained in:
zxj96
2019-05-29 13:57:12 +08:00
parent d057518f5f
commit 8eba860bcb
9 changed files with 97 additions and 10 deletions

View File

@@ -616,6 +616,18 @@ export const Utils = {
return a.last_modified < b.last_modified ? 1 : -1;
};
break;
case 'size-asc':
comparator = function(a, b) {
let reult = _this.compareTwoSize(a.size, b.size);
return reult;
};
break;
case 'size-desc':
comparator = function(a, b) {
let reult = _this.compareTwoSize(a.size, b.size);
return -reult;
};
break;
}
repos.sort(comparator);
@@ -649,6 +661,28 @@ export const Utils = {
return a.mtime < b.mtime ? 1 : -1;
};
break;
case 'size-asc':
comparator = function(a, b) {
if (a.type == 'dir' && b.type == 'dir') {
let reult = _this.compareTwoWord(a.name, b.name);
return reult;
} else {
let reult = _this.compareTwoSize(a.size, b.size);
return reult;
}
};
break;
case 'size-desc':
comparator = function(a, b) {
if (a.type == 'dir' && b.type == 'dir') {
let reult = _this.compareTwoWord(a.name, b.name);
return -reult;
} else {
let reult = _this.compareTwoSize(a.size, b.size);
return -reult;
}
};
break;
}
items.sort((a, b) => {
@@ -663,6 +697,28 @@ export const Utils = {
return items;
},
compareTwoSize: function(a, b) {
let suffix = /[A-Za-z]+/g;
let fileSizeName = /(\-|\+)?\d+(\.\d+)?/g;
let sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
let aSuffixName = a.match(suffix)[0];
let bSuffixName = b.match(suffix)[0];
let aIndex = sizes.indexOf(aSuffixName);
let bIndex = sizes.indexOf(bSuffixName);
if (aIndex === bIndex) {
let aFileName = a.match(fileSizeName)[0];
let bFileName = b.match(fileSizeName)[0];
let aBytes = aFileName * (1000 ** aIndex);
let bBytes = bFileName * (1000 ** bIndex);
return aBytes < bBytes ? -1 : 1;
} else {
return aIndex < bIndex ? -1 : 1;
}
},
changeMarkdownNodes: function(nodes, fn) {
nodes.map((item) => {
fn(item);