[ADF-551] allow setting sorting in html (#1857)

* allow setting sorting in html

* readme update

* update readme

* restore permissions code

* - Remove the check permission from the datatable and move inside the documentlist

* Remove commented test
This commit is contained in:
Denys Vuika
2017-05-10 15:43:38 +01:00
committed by Eugenio Romano
parent 416d8c2a1b
commit b0be88ec37
7 changed files with 216 additions and 120 deletions

View File

@@ -89,6 +89,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
@Input()
allowDropFiles: boolean = false;
@Input()
sorting: string[];
skipCount: number = 0;
pagination: Pagination;
@@ -189,12 +192,6 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
this.enforceSingleClickNavigationForMobile();
}
private enforceSingleClickNavigationForMobile(): void {
if (this.isMobile()) {
this.navigationMode = DocumentListComponent.SINGLE_CLICK_NAVIGATION;
}
}
ngAfterContentInit() {
let schema: DataColumn[] = [];
@@ -212,6 +209,15 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
if (!columns || columns.length === 0) {
this.setupDefaultColumns();
}
if (this.sorting) {
const [ key, direction ] = this.sorting;
this.data.setSorting({
key,
direction: direction || 'asc'
});
}
}
ngOnChanges(changes: SimpleChanges) {
@@ -271,7 +277,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
return this.enablePagination && !this.isEmpty();
}
getNodeActions(node: MinimalNodeEntity): ContentActionModel[] {
getNodeActions(node: MinimalNodeEntity | any): ContentActionModel[] {
let target = null;
if (node && node.entry) {
@@ -284,18 +290,46 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
}
if (target) {
let ltarget = target.toLowerCase();
let actionWithPermission = this.checkPermissions(node);
return this.actions.filter(entry => {
let actionsByTarget = actionWithPermission.filter(entry => {
return entry.target.toLowerCase() === ltarget;
});
let cloneActions = Object.create(actionsByTarget);
return cloneActions;
}
}
return [];
}
checkPermissions(node: MinimalNodeEntity): ContentActionModel[] {
let actionsPermission: ContentActionModel[] = [];
this.actions.forEach((action) => {
actionsPermission.push(this.checkPermission(node, action));
});
return actionsPermission;
}
checkPermission(node: any, action: ContentActionModel): ContentActionModel {
if (action.permission) {
if (this.hasPermissions(node)) {
let permissions = node.entry.allowableOperations;
let findPermission = permissions.find(permission => permission === action.permission);
if (!findPermission && action.disableWithNoPermission === true) {
action.disabled = true;
}
}
}
return action;
}
private hasPermissions(node: any): boolean {
return node.entry.allowableOperations ? true : false;
}
@HostListener('contextmenu', ['$event'])
onShowContextMenu(e?: Event) {
if (e && this.contextMenuActions) {
@@ -341,7 +375,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
this.skipCount = 0;
this.loadFolderNodesByFolderNodeId(node.id, this.pageSize, this.skipCount).catch(err => this.error.emit(err));
})
.catch(err => this.error.emit(err));
.catch(err => this.error.emit(err));
}
loadFolderNodesByFolderNodeId(id: string, maxItems: number, skipCount: number): Promise<any> {
@@ -353,7 +387,8 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
skipCount: skipCount,
rootFolderId: id
})
.subscribe(val => {
.subscribe(
val => {
this.data.loadPage(<NodePaging>val);
this.pagination = val.list.pagination;
resolve(true);
@@ -518,4 +553,10 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
onPermissionError(event) {
this.permissionError.emit(event);
}
private enforceSingleClickNavigationForMobile(): void {
if (this.isMobile()) {
this.navigationMode = DocumentListComponent.SINGLE_CLICK_NAVIGATION;
}
}
}