sort file in fileview tag

This commit is contained in:
lxsang 2021-01-02 13:47:59 +01:00
parent 5b6e6f8d94
commit 7488f4625c
2 changed files with 39 additions and 40 deletions

Binary file not shown.

View File

@ -265,31 +265,8 @@ namespace OS {
if (!data) { if (!data) {
return; return;
} }
// sort file by type, then by name
data this.data = data.sort(this.sortByName).sort(this.sortByType);
.sort(function(a:API.FileInfoType,b:API.FileInfoType): number{
if(a.filename)
{
a.name = a.filename;
}
if(b.filename)
{
b.name = b.filename;
}
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
})
.sort(function(a:API.FileInfoType,b:API.FileInfoType): number{
if(!a.type)
{
a.type = "none";
}
if(!b.type)
{
b.type = "none";
}
return a.type.toLowerCase().localeCompare(b.type.toLowerCase());
});
this.data = data;
if (this.status) { if (this.status) {
(this.refs.status as LabelTag).text = " "; (this.refs.status as LabelTag).text = " ";
} }
@ -336,25 +313,47 @@ namespace OS {
} }
/** /**
* sort file by it type * Sort file by its type
* *
* @private * @private
* @param {API.FileInfoType} a first file meta-data * @param {API.FileInfoType} a
* @param {API.FileInfoType} b second file meta-data * @param {API.FileInfoType} b
* @returns {(0|-1|1)} * @return {*} {number}
* @memberof FileViewTag * @memberof FileViewTag
*/ */
private sortByType( private sortByType(
a: API.FileInfoType, a: API.FileInfoType,
b: API.FileInfoType b: API.FileInfoType
): 0 | -1 | 1 { ): number {
if (a.type < b.type) { if (!a.type) {
return -1; a.type = "none";
} else if (a.type > b.type) {
return 1;
} else {
return 0;
} }
if (!b.type) {
b.type = "none";
}
return a.type.toLowerCase().localeCompare(b.type.toLowerCase());
}
/**
* sort file by its name
*
* @private
* @param {API.FileInfoType} a first file meta-data
* @param {API.FileInfoType} b second file meta-data
* @returns {number}
* @memberof FileViewTag
*/
private sortByName(
a: API.FileInfoType,
b: API.FileInfoType
): number {
// sort file by type, then by name
if (a.filename) {
a.name = a.filename;
}
if (b.filename) {
b.name = b.filename;
}
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
} }
/** /**
@ -491,7 +490,7 @@ namespace OS {
if (!this.data) { if (!this.data) {
return; return;
} }
this.data.sort(this.sortByType); this.data.sort(this.sortByName).sort(this.sortByType);
switch (this.view) { switch (this.view) {
case "icon": case "icon":
return this.refreshList(); return this.refreshList();
@ -597,7 +596,7 @@ namespace OS {
.then((d: API.FileInfoType[]) => .then((d: API.FileInfoType[]) =>
resolve( resolve(
this.getTreeData( this.getTreeData(
d.sort(this.sortByType) d.sort(this.sortByName).sort(this.sortByType)
) )
) )
) )