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

[dir view, repo wiki mode] added 'sort' (#2754)

This commit is contained in:
llj
2019-01-04 15:06:27 +08:00
committed by Daniel Pan
parent c5c419b915
commit 6004ccb6fe
6 changed files with 107 additions and 5 deletions

View File

@@ -479,5 +479,47 @@ export const Utils = {
repos.sort(comparator);
return repos;
},
sortDirents: function(items, sortBy, sortOrder) {
const _this = this;
let comparator;
switch (`${sortBy}-${sortOrder}`) {
case 'name-asc':
comparator = function(a, b) {
var result = _this.compareTwoWord(a.name, b.name);
return result;
};
break;
case 'name-desc':
comparator = function(a, b) {
var result = _this.compareTwoWord(a.name, b.name);
return -result;
};
break;
case 'time-asc':
comparator = function(a, b) {
return a.mtime < b.mtime ? -1 : 1;
};
break;
case 'time-desc':
comparator = function(a, b) {
return a.mtime < b.mtime ? 1 : -1;
};
break;
}
items.sort((a, b) => {
if (a.type == 'dir' && b.type == 'file') {
return -1;
} else if (a.type == 'file' && b.type == 'dir') {
return 1;
} else {
return comparator(a, b);
}
});
return items;
}
};