mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[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:
parent
416d8c2a1b
commit
b0be88ec37
@ -18,6 +18,7 @@
|
||||
[contextMenuActions]="true"
|
||||
[contentActions]="true"
|
||||
[allowDropFiles]="true"
|
||||
[sorting]="['name', 'desc']"
|
||||
(error)="onNavigationError($event)"
|
||||
(success)="resetError()"
|
||||
(preview)="showFile($event)"
|
||||
|
@ -415,86 +415,4 @@ describe('DataTable', () => {
|
||||
expect(event.target.src).toBe(originalSrc);
|
||||
});
|
||||
|
||||
it('should disable the action if there is no permission and disableWithNoPermission true', () => {
|
||||
|
||||
dataTable.data = new ObjectDataTableAdapter(
|
||||
[{id: 1, name: 'xyz', allowableOperations: ['create', 'update']}],
|
||||
[]
|
||||
);
|
||||
|
||||
let row = dataTable.data.getRows();
|
||||
let actions = [
|
||||
{
|
||||
disableWithNoPermission: true,
|
||||
permission: 'delete',
|
||||
target: 'folder',
|
||||
title: 'action2'
|
||||
}
|
||||
];
|
||||
|
||||
let updateActions = dataTable.checkPermissions(row[0], actions);
|
||||
expect(updateActions[0].disabled).toBe(true);
|
||||
});
|
||||
|
||||
it('should not disable the action if there is no permission and disableWithNoPermission false', () => {
|
||||
|
||||
dataTable.data = new ObjectDataTableAdapter(
|
||||
[{id: 1, name: 'xyz', allowableOperations: ['create', 'update']}],
|
||||
[]
|
||||
);
|
||||
|
||||
let row = dataTable.data.getRows();
|
||||
let actions = [
|
||||
{
|
||||
disableWithNoPermission: false,
|
||||
permission: 'delete',
|
||||
target: 'folder',
|
||||
title: 'action2'
|
||||
}
|
||||
];
|
||||
|
||||
let updateActions = dataTable.checkPermissions(row[0], actions);
|
||||
expect(updateActions[0].disabled).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not disable the action if there is the right permission', () => {
|
||||
|
||||
dataTable.data = new ObjectDataTableAdapter(
|
||||
[{ id: 1, name: 'xyz', allowableOperations: ['create', 'update', 'delete'] }],
|
||||
[]
|
||||
);
|
||||
|
||||
let row = dataTable.data.getRows();
|
||||
let actions = [
|
||||
{
|
||||
permission: 'delete',
|
||||
target: 'folder',
|
||||
title: 'action2'
|
||||
}
|
||||
];
|
||||
|
||||
let updateActions = dataTable.checkPermissions(row[0], actions);
|
||||
expect(updateActions[0].disabled).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not disable the action if there are no permissions', () => {
|
||||
|
||||
dataTable.data = new ObjectDataTableAdapter(
|
||||
[{id: 1, name: 'xyz', allowableOperations: null}],
|
||||
[]
|
||||
);
|
||||
|
||||
let row = dataTable.data.getRows();
|
||||
let actions = [
|
||||
{
|
||||
permission: 'delete',
|
||||
target: 'folder',
|
||||
title: 'action2'
|
||||
}
|
||||
];
|
||||
|
||||
let updateActions = dataTable.checkPermissions(row[0], actions);
|
||||
expect(updateActions[0].disabled).toBeUndefined();
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -235,33 +235,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges {
|
||||
getRowActions(row: DataRow, col: DataColumn): any[] {
|
||||
let event = new DataCellEvent(row, col, []);
|
||||
this.showRowActionsMenu.emit(event);
|
||||
|
||||
return this.checkPermissions(row, event.value.actions);
|
||||
}
|
||||
|
||||
checkPermissions(row: DataRow, actions: any[]) {
|
||||
let actionsPermission = [];
|
||||
actions.forEach((action) => {
|
||||
actionsPermission.push(this.checkPermission(row, action));
|
||||
});
|
||||
return actionsPermission;
|
||||
}
|
||||
|
||||
checkPermission(row: DataRow, action) {
|
||||
if (action.permission) {
|
||||
if (this.hasPermissions(row)) {
|
||||
let permissions = row.getValue('allowableOperations');
|
||||
let findPermission = permissions.find(permission => permission === action.permission);
|
||||
if (!findPermission && action.disableWithNoPermission === true) {
|
||||
action.disabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
private hasPermissions(row: DataRow): boolean {
|
||||
return row.getValue('allowableOperations') ? true : false;
|
||||
return event.value.actions;
|
||||
}
|
||||
|
||||
onExecuteRowAction(row: DataRow, action: any) {
|
||||
|
@ -192,6 +192,7 @@ The properties currentFolderId, folderNode and node are the entry initialization
|
||||
| `rowFilter` | `RowFilter` | | Custom row filter, [see more](#custom-row-filter). |
|
||||
| `imageResolver` | `ImageResolver` | | Custom image resolver, [see more](#custom-image-resolver). |
|
||||
| `allowDropFiles` | boolean | false | Toggle file drop support for rows (see **ng2-alfresco-core/UploadDirective** for more details) |
|
||||
| `sorting` | string[] | | Defines default sorting. The format is an array of 2 strings `[key, direction]` i.e. `['name', 'desc']` or `['name', 'asc']`. Set this value only if you want to override default sorting detected by the component based on columns. |
|
||||
|
||||
### Events
|
||||
|
||||
|
@ -164,6 +164,166 @@ describe('DocumentList', () => {
|
||||
expect(actions[0]).toBe(documentMenu);
|
||||
});
|
||||
|
||||
it('should disable the action if there is no permission for the file and disableWithNoPermission true', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
disableWithNoPermission: true,
|
||||
permission: 'delete',
|
||||
target: 'document',
|
||||
title: 'FileAction'
|
||||
});
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {entry: {isFile: true, name: 'xyz', allowableOperations: ['create', 'update']}};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FileAction');
|
||||
expect(actions[0].disabled).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
it('should disable the action if there is no permission for the folder and disableWithNoPermission true', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
disableWithNoPermission: true,
|
||||
permission: 'delete',
|
||||
target: 'folder',
|
||||
title: 'FolderAction'
|
||||
});
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {entry: {isFolder: true, name: 'xyz', allowableOperations: ['create', 'update']}};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FolderAction');
|
||||
expect(actions[0].disabled).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
it('should not disable the action if there is no permission for the file and disableWithNoPermission false', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
disableWithNoPermission: false,
|
||||
permission: 'delete',
|
||||
target: 'document',
|
||||
title: 'FileAction'
|
||||
});
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {entry: {isFile: true, name: 'xyz', allowableOperations: ['create', 'update']}};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FileAction');
|
||||
expect(actions[0].disabled).toBeUndefined(true);
|
||||
});
|
||||
|
||||
it('should not disable the action if there is no permission for the folder and disableWithNoPermission false', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
disableWithNoPermission: false,
|
||||
permission: 'delete',
|
||||
target: 'folder',
|
||||
title: 'FolderAction'
|
||||
});
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {entry: {isFolder: true, name: 'xyz', allowableOperations: ['create', 'update']}};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FolderAction');
|
||||
expect(actions[0].disabled).toBeUndefined(true);
|
||||
});
|
||||
|
||||
it('should not disable the action if there is the right permission for the file', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
disableWithNoPermission: true,
|
||||
permission: 'delete',
|
||||
target: 'document',
|
||||
title: 'FileAction'
|
||||
});
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {entry: {isFile: true, name: 'xyz', allowableOperations: ['create', 'update', 'delete']}};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FileAction');
|
||||
expect(actions[0].disabled).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not disable the action if there is the right permission for the folder', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
disableWithNoPermission: true,
|
||||
permission: 'delete',
|
||||
target: 'folder',
|
||||
title: 'FolderAction'
|
||||
});
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {entry: {isFolder: true, name: 'xyz', allowableOperations: ['create', 'update', 'delete']}};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FolderAction');
|
||||
expect(actions[0].disabled).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not disable the action if there are no permissions for the file', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
permission: 'delete',
|
||||
target: 'document',
|
||||
title: 'FileAction'
|
||||
});
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {entry: {isFile: true, name: 'xyz', allowableOperations: null}};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FileAction');
|
||||
expect(actions[0].disabled).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not disable the action if there are no permissions for the folder', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
permission: 'delete',
|
||||
target: 'folder',
|
||||
title: 'FolderAction'
|
||||
});
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {entry: {isFolder: true, name: 'xyz', allowableOperations: null}};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FolderAction');
|
||||
expect(actions[0].disabled).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should find no content actions', () => {
|
||||
let documentButton = new ContentActionModel();
|
||||
documentButton.target = 'document';
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ export class ContentActionModel {
|
||||
target: string;
|
||||
permission: string;
|
||||
disableWithNoPermission: boolean;
|
||||
disabled: boolean;
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user