#99 improved date sorting

sort dates by numeric values rather than by formatted strings
This commit is contained in:
Denys Vuika
2016-06-02 12:25:47 +01:00
parent a397c05863
commit d2a1331342

View File

@@ -353,17 +353,11 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
if (this._hasEntries(node)) {
node.list.entries.sort((a: MinimalNodeEntity, b: MinimalNodeEntity) => {
if (a.entry.isFolder !== b.entry.isFolder) {
// Uncomment if it is needed to make files go top on desc
/*
return options.direction === 'asc'
? (a.entry.isFolder ? -1 : 1)
: (a.entry.isFolder ? 1 : -1);
*/
return a.entry.isFolder ? -1 : 1;
}
let left = this.getObjectValue(a.entry, options.key).toString();
let right = this.getObjectValue(b.entry, options.key).toString();
let left = this._getObjectValueRaw(a.entry, options.key).toString();
let right = this._getObjectValueRaw(b.entry, options.key).toString();
return options.direction === 'asc'
? left.localeCompare(right)
@@ -373,6 +367,16 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
return node;
}
private _getObjectValueRaw(target: any, key: string) {
let val = this.getObjectValue(target, key);
if (val instanceof Date) {
val = val.valueOf();
}
return val;
}
private _createRootFolder(path: string): any {
let parts = path.split('/');
let namePart = parts[parts.length - 1];