mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-08-07 17:48:54 +00:00
[ADF-551] sorting for document list (#1891)
* table cell component - table cell component with performance improvements * permissions and sorting fixes - fixed ability to set default sorting - fixed permission evaluation - new: context menu now also works with permissions - disabled tags column in demo shell due to performance implications * fix unit tests * fix tsconfig for unit testing
This commit is contained in:
committed by
Eugenio Romano
parent
ef5bb6333c
commit
da18a21e7c
@@ -47,6 +47,9 @@ export class ContentActionComponent implements OnInit, OnChanges {
|
||||
@Input()
|
||||
disableWithNoPermission: boolean;
|
||||
|
||||
@Input()
|
||||
disabled: boolean = false;
|
||||
|
||||
@Output()
|
||||
execute = new EventEmitter();
|
||||
|
||||
@@ -68,7 +71,8 @@ export class ContentActionComponent implements OnInit, OnChanges {
|
||||
icon: this.icon,
|
||||
permission: this.permission,
|
||||
disableWithNoPermission: this.disableWithNoPermission,
|
||||
target: this.target
|
||||
target: this.target,
|
||||
disabled: this.disabled
|
||||
});
|
||||
|
||||
if (this.handler) {
|
||||
|
@@ -30,6 +30,8 @@ describe('ContentColumnList', () => {
|
||||
let service = new DocumentListServiceMock();
|
||||
documentList = new DocumentListComponent(service, null, null, null);
|
||||
columnList = new ContentColumnListComponent(documentList);
|
||||
|
||||
documentList.ngOnInit();
|
||||
});
|
||||
|
||||
it('should register column within parent document list', () => {
|
||||
|
@@ -29,6 +29,8 @@ describe('ContentColumn', () => {
|
||||
let service = new DocumentListServiceMock();
|
||||
documentList = new DocumentListComponent(service, null, null, null);
|
||||
columnList = new ContentColumnListComponent(documentList);
|
||||
|
||||
documentList.ngOnInit();
|
||||
});
|
||||
|
||||
it('should register model within parent column list', () => {
|
||||
|
@@ -157,11 +157,11 @@ describe('DocumentList', () => {
|
||||
|
||||
let actions = documentList.getNodeActions(new FolderNode());
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0]).toBe(folderMenu);
|
||||
expect(actions[0].target).toBe(folderMenu.target);
|
||||
|
||||
actions = documentList.getNodeActions(new FileNode());
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0]).toBe(documentMenu);
|
||||
expect(actions[0].target).toBe(documentMenu.target);
|
||||
});
|
||||
|
||||
it('should disable the action if there is no permission for the file and disableWithNoPermission true', () => {
|
||||
|
@@ -28,7 +28,8 @@ import {
|
||||
ObjectDataColumn,
|
||||
DataCellEvent,
|
||||
DataRowActionEvent,
|
||||
DataColumn
|
||||
DataColumn,
|
||||
DataSorting
|
||||
} from 'ng2-alfresco-datatable';
|
||||
import { DocumentListService } from './../services/document-list.service';
|
||||
import { ContentActionModel } from './../models/content-action.model';
|
||||
@@ -156,8 +157,6 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
private translateService: AlfrescoTranslationService,
|
||||
private el: ElementRef) {
|
||||
|
||||
this.data = new ShareDataTableAdapter(this.documentListService);
|
||||
|
||||
if (translateService) {
|
||||
translateService.addTranslationFolder('ng2-alfresco-documentlist', 'node_modules/ng2-alfresco-documentlist/src');
|
||||
}
|
||||
@@ -186,6 +185,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.data = new ShareDataTableAdapter(this.documentListService, null, this.getDefaultSorting());
|
||||
this.data.thumbnails = this.thumbnails;
|
||||
this.contextActionHandler.subscribe(val => this.contextActionCallback(val));
|
||||
|
||||
@@ -200,7 +200,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
}
|
||||
|
||||
if (!this.data) {
|
||||
this.data = new ShareDataTableAdapter(this.documentListService, schema);
|
||||
this.data = new ShareDataTableAdapter(this.documentListService, schema, this.getDefaultSorting());
|
||||
} else if (schema && schema.length > 0) {
|
||||
this.data.setColumns(schema);
|
||||
}
|
||||
@@ -209,18 +209,6 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
if (!columns || columns.length === 0) {
|
||||
this.setupDefaultColumns();
|
||||
}
|
||||
|
||||
// TODO: commented out as Permissions feature (Context Menus and Row Actions) breaks all component functionality
|
||||
/*
|
||||
if (this.sorting) {
|
||||
const [ key, direction ] = this.sorting;
|
||||
|
||||
this.data.setSorting({
|
||||
key,
|
||||
direction: direction || 'asc'
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
@@ -294,28 +282,21 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
|
||||
if (target) {
|
||||
let ltarget = target.toLowerCase();
|
||||
let actionWithPermission = this.checkPermissions(node);
|
||||
|
||||
let actionsByTarget = actionWithPermission.filter(entry => {
|
||||
let actionsByTarget = this.actions.filter(entry => {
|
||||
return entry.target.toLowerCase() === ltarget;
|
||||
}).map(action => new ContentActionModel(action));
|
||||
|
||||
actionsByTarget.forEach((action) => {
|
||||
this.checkPermission(node, action);
|
||||
});
|
||||
|
||||
let cloneActions = Object.create(actionsByTarget);
|
||||
return cloneActions;
|
||||
return actionsByTarget;
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
@@ -562,4 +543,13 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
this.navigationMode = DocumentListComponent.SINGLE_CLICK_NAVIGATION;
|
||||
}
|
||||
}
|
||||
|
||||
private getDefaultSorting(): DataSorting {
|
||||
let defaultSorting: DataSorting;
|
||||
if (this.sorting) {
|
||||
const [ key, direction ] = this.sorting;
|
||||
defaultSorting = new DataSorting(key, direction);
|
||||
}
|
||||
return defaultSorting;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user