#66 Initial sorting support for document list

This commit is contained in:
Denys Vuika
2016-05-17 15:57:13 +01:00
parent 5a4bfb5ea8
commit a0848ea825
7 changed files with 85 additions and 9 deletions

View File

@@ -28,6 +28,7 @@ import { AlfrescoService } from './../services/alfresco.service';
import { MinimalNodeEntity, NodePaging } from './../models/document-library.model';
import { ContentActionModel } from './../models/content-action.model';
import { ContentColumnModel } from './../models/content-column.model';
import { ColumnSortingModel } from './../models/column-sorting.model';
declare var componentHandler;
declare let __moduleName: string;
@@ -74,6 +75,11 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
actions: ContentActionModel[] = [];
columns: ContentColumnModel[] = [];
sorting: ColumnSortingModel = {
key: 'name',
direction: 'asc'
};
/**
* Determines whether navigation to parent folder is available.
* @returns {boolean}
@@ -255,7 +261,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
this._alfrescoService
.getFolder(path)
.subscribe(
folder => this.folder = folder,
folder => this.folder = this.sort(folder, this.sorting),
error => this.errorMessage = <any>error
);
}
@@ -316,7 +322,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
let nameCol = new ContentColumnModel();
nameCol.title = 'Name';
nameCol.source = 'displayName';
nameCol.source = 'name';
nameCol.cssClass = 'full-width name-column';
this.columns = [
@@ -324,4 +330,42 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
nameCol
];
}
onColumnHeaderClick(column: ContentColumnModel) {
if (column) {
if (this.sorting.key === column.source) {
this.sorting.direction = this.sorting.direction === 'asc' ? 'desc' : 'asc';
} else {
this.sorting = <ColumnSortingModel> {
key: column.source,
direction: 'asc'
};
}
this.sort(this.folder, this.sorting);
}
}
sort(node: NodePaging, options: ColumnSortingModel) {
if (this._hasEntries(node)) {
node.list.entries.sort((a: MinimalNodeEntity, b: MinimalNodeEntity) => {
if (a.entry.isFolder != b.entry.isFolder) {
return options.direction === 'asc'
? (a.entry.isFolder ? -1 : 1)
: (a.entry.isFolder ? 1 : -1);
}
var left = this.getObjectValue(a.entry, options.key).toString();
var right = this.getObjectValue(b.entry, options.key).toString();
return options.direction === 'asc'
? left.localeCompare(right)
: right.localeCompare(left);
});
}
return node;
}
private _hasEntries(node: NodePaging): boolean {
return (node && node.list && node.list.entries && node.list.entries.length > 0);
}
}