mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2163] added target all for content actions (#2900)
* [ADF-2163] first step to target all
* [ADF-2163] start refactoring folder dulpication action
* [ADF-2163] start refactorin all approach
* [ADF-2163] added test for target action 'all'
* [ADF-2163] fixed test and added enum for target actions
* [ADF-2163] updated documentation for content action target all
* [ADF-2163] updated documentation adding ENUM
* [ADF-2163] added change to documentation after quick review
* [ADF-2163] moved to upper case enum
* Revert "[ADF-2163] moved to upper case enum"
This reverts commit 41da0a34dd
.
* [ADF-2163] fixed case for documentation
This commit is contained in:
@@ -195,11 +195,10 @@
|
|||||||
</data-columns>
|
</data-columns>
|
||||||
|
|
||||||
<content-actions>
|
<content-actions>
|
||||||
<!-- folder actions -->
|
<!-- common actions -->
|
||||||
<content-action
|
<content-action
|
||||||
icon="content_copy"
|
icon="content_copy"
|
||||||
target="folder"
|
title="DOCUMENT_LIST.ACTIONS.FOLDER.COPY"
|
||||||
title="{{'DOCUMENT_LIST.ACTIONS.FOLDER.COPY' | translate}}"
|
|
||||||
permission="update"
|
permission="update"
|
||||||
[disableWithNoPermission]="true"
|
[disableWithNoPermission]="true"
|
||||||
(error)="onContentActionError($event)"
|
(error)="onContentActionError($event)"
|
||||||
@@ -208,8 +207,7 @@
|
|||||||
</content-action>
|
</content-action>
|
||||||
<content-action
|
<content-action
|
||||||
icon="redo"
|
icon="redo"
|
||||||
target="folder"
|
title="DOCUMENT_LIST.ACTIONS.FOLDER.MOVE"
|
||||||
title="{{'DOCUMENT_LIST.ACTIONS.FOLDER.MOVE' | translate}}"
|
|
||||||
permission="update"
|
permission="update"
|
||||||
[disableWithNoPermission]="true"
|
[disableWithNoPermission]="true"
|
||||||
(error)="onContentActionError($event)"
|
(error)="onContentActionError($event)"
|
||||||
@@ -218,35 +216,14 @@
|
|||||||
</content-action>
|
</content-action>
|
||||||
<content-action
|
<content-action
|
||||||
icon="delete"
|
icon="delete"
|
||||||
target="folder"
|
|
||||||
permission="delete"
|
permission="delete"
|
||||||
[disableWithNoPermission]="true"
|
[disableWithNoPermission]="true"
|
||||||
title="{{'DOCUMENT_LIST.ACTIONS.FOLDER.DELETE' | translate}}"
|
title="DOCUMENT_LIST.ACTIONS.FOLDER.DELETE"
|
||||||
(permissionEvent)="handlePermissionError($event)"
|
(permissionEvent)="handlePermissionError($event)"
|
||||||
(success)="onDeleteActionSuccess($event)"
|
(success)="onDeleteActionSuccess($event)"
|
||||||
handler="delete">
|
handler="delete">
|
||||||
</content-action>
|
</content-action>
|
||||||
<!-- document actions -->
|
<!-- document actions -->
|
||||||
<content-action
|
|
||||||
icon="content_copy"
|
|
||||||
target="document"
|
|
||||||
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.COPY' | translate}}"
|
|
||||||
permission="update"
|
|
||||||
[disableWithNoPermission]="true"
|
|
||||||
(error)="onContentActionError($event)"
|
|
||||||
(success)="onContentActionSuccess($event)"
|
|
||||||
handler="copy">
|
|
||||||
</content-action>
|
|
||||||
<content-action
|
|
||||||
icon="redo"
|
|
||||||
target="document"
|
|
||||||
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.MOVE' | translate}}"
|
|
||||||
permission="update"
|
|
||||||
[disableWithNoPermission]="true"
|
|
||||||
(error)="onContentActionError($event)"
|
|
||||||
(success)="onContentActionSuccess($event)"
|
|
||||||
handler="move">
|
|
||||||
</content-action>
|
|
||||||
<content-action
|
<content-action
|
||||||
icon="storage"
|
icon="storage"
|
||||||
target="document"
|
target="document"
|
||||||
@@ -256,24 +233,14 @@
|
|||||||
<content-action
|
<content-action
|
||||||
icon="file_download"
|
icon="file_download"
|
||||||
target="document"
|
target="document"
|
||||||
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.DOWNLOAD' | translate}}"
|
title="DOCUMENT_LIST.ACTIONS.DOCUMENT.DOWNLOAD"
|
||||||
handler="download">
|
handler="download">
|
||||||
</content-action>
|
</content-action>
|
||||||
<content-action
|
|
||||||
icon="delete"
|
|
||||||
target="document"
|
|
||||||
permission="delete"
|
|
||||||
[disableWithNoPermission]="true"
|
|
||||||
(permissionEvent)="handlePermissionError($event)"
|
|
||||||
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.DELETE' | translate}}"
|
|
||||||
(success)="onDeleteActionSuccess($event)"
|
|
||||||
handler="delete">
|
|
||||||
</content-action>
|
|
||||||
<content-action
|
<content-action
|
||||||
*ngIf="authenticationService.isBpmLoggedIn()"
|
*ngIf="authenticationService.isBpmLoggedIn()"
|
||||||
icon="play_arrow"
|
icon="play_arrow"
|
||||||
target="document"
|
target="document"
|
||||||
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.PROCESS_ACTION' | translate}}"
|
title="DOCUMENT_LIST.ACTIONS.DOCUMENT.PROCESS_ACTION"
|
||||||
(execute)="startProcesAction($event)">
|
(execute)="startProcesAction($event)">
|
||||||
</content-action>
|
</content-action>
|
||||||
</content-actions>
|
</content-actions>
|
||||||
|
@@ -79,7 +79,7 @@ export class MyView {
|
|||||||
| title | `string` | `'Action'` | The title of the action as shown in the menu. |
|
| title | `string` | `'Action'` | The title of the action as shown in the menu. |
|
||||||
| icon | `string` | | The name of the icon to display next to the menu command (can be left blank). |
|
| icon | `string` | | The name of the icon to display next to the menu command (can be left blank). |
|
||||||
| handler | `string` | | System actions. Can be "delete", "download", "copy" or "move". |
|
| handler | `string` | | System actions. Can be "delete", "download", "copy" or "move". |
|
||||||
| target | `string` | | Type of item that the action appies to. Can be "document" or "folder" |
|
| target | `string` | [ContentActionTarget.All](https://github.com/Alfresco/alfresco-ng2-components/blob/development/lib/content-services/document-list/models/content-action.model.ts) | Type of item that the action applies to. Can be one of the values provided by the enum : **All**, **Folder**, **Document** |
|
||||||
| permission | `string` | | The permission type. |
|
| permission | `string` | | The permission type. |
|
||||||
| disableWithNoPermission | `boolean` | | Should this action be disabled in the menu if the user doesn't have permission for it? |
|
| disableWithNoPermission | `boolean` | | Should this action be disabled in the menu if the user doesn't have permission for it? |
|
||||||
| disabled | `boolean` | `false` | Is the menu item disabled? |
|
| disabled | `boolean` | `false` | Is the menu item disabled? |
|
||||||
|
@@ -21,9 +21,8 @@ import { async, TestBed } from '@angular/core/testing';
|
|||||||
import { ContentService } from '@alfresco/adf-core';
|
import { ContentService } from '@alfresco/adf-core';
|
||||||
import { DataTableModule } from '@alfresco/adf-core';
|
import { DataTableModule } from '@alfresco/adf-core';
|
||||||
import { MaterialModule } from '../../../material.module';
|
import { MaterialModule } from '../../../material.module';
|
||||||
|
|
||||||
import { DocumentListService } from '../../services/document-list.service';
|
|
||||||
import { FileNode } from '../../../mock';
|
import { FileNode } from '../../../mock';
|
||||||
|
import { DocumentListService } from '../../services/document-list.service';
|
||||||
import { ContentActionHandler } from './../../models/content-action.model';
|
import { ContentActionHandler } from './../../models/content-action.model';
|
||||||
import { DocumentActionsService } from './../../services/document-actions.service';
|
import { DocumentActionsService } from './../../services/document-actions.service';
|
||||||
import { FolderActionsService } from './../../services/folder-actions.service';
|
import { FolderActionsService } from './../../services/folder-actions.service';
|
||||||
@@ -31,6 +30,7 @@ import { NodeActionsService } from './../../services/node-actions.service';
|
|||||||
import { DocumentListComponent } from './../document-list.component';
|
import { DocumentListComponent } from './../document-list.component';
|
||||||
import { ContentActionListComponent } from './content-action-list.component';
|
import { ContentActionListComponent } from './content-action-list.component';
|
||||||
import { ContentActionComponent } from './content-action.component';
|
import { ContentActionComponent } from './content-action.component';
|
||||||
|
import { ContentActionModel } from './../../models/content-action.model';
|
||||||
|
|
||||||
describe('ContentAction', () => {
|
describe('ContentAction', () => {
|
||||||
|
|
||||||
@@ -131,25 +131,45 @@ describe('ContentAction', () => {
|
|||||||
expect(model.handler).toBe(handler);
|
expect(model.handler).toBe(handler);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should require target to get system handler', () => {
|
it('should create document and folder action when there is no target', () => {
|
||||||
spyOn(folderActions, 'getHandler').and.stub();
|
spyOn(folderActions, 'getHandler').and.stub();
|
||||||
spyOn(documentActions, 'getHandler').and.stub();
|
spyOn(documentActions, 'getHandler').and.stub();
|
||||||
|
|
||||||
let action = new ContentActionComponent(actionList, documentActions, folderActions);
|
let action = new ContentActionComponent(actionList, documentActions, folderActions);
|
||||||
action.handler = '<handler>';
|
action.handler = '<handler>';
|
||||||
|
|
||||||
|
action.ngOnInit();
|
||||||
|
expect(documentList.actions.length).toBe(2);
|
||||||
|
expect(folderActions.getHandler).toHaveBeenCalled();
|
||||||
|
expect(documentActions.getHandler).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create document action when target is document', () => {
|
||||||
|
spyOn(folderActions, 'getHandler').and.stub();
|
||||||
|
spyOn(documentActions, 'getHandler').and.stub();
|
||||||
|
|
||||||
|
let action = new ContentActionComponent(actionList, documentActions, folderActions);
|
||||||
|
action.handler = '<handler>';
|
||||||
|
action.target = 'document';
|
||||||
|
|
||||||
action.ngOnInit();
|
action.ngOnInit();
|
||||||
expect(documentList.actions.length).toBe(1);
|
expect(documentList.actions.length).toBe(1);
|
||||||
expect(folderActions.getHandler).not.toHaveBeenCalled();
|
expect(folderActions.getHandler).not.toHaveBeenCalled();
|
||||||
expect(documentActions.getHandler).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
action.target = 'document';
|
|
||||||
action.ngOnInit();
|
|
||||||
expect(documentActions.getHandler).toHaveBeenCalled();
|
expect(documentActions.getHandler).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create folder action when target is folder', () => {
|
||||||
|
spyOn(folderActions, 'getHandler').and.stub();
|
||||||
|
spyOn(documentActions, 'getHandler').and.stub();
|
||||||
|
|
||||||
|
let action = new ContentActionComponent(actionList, documentActions, folderActions);
|
||||||
|
action.handler = '<handler>';
|
||||||
action.target = 'folder';
|
action.target = 'folder';
|
||||||
|
|
||||||
action.ngOnInit();
|
action.ngOnInit();
|
||||||
|
expect(documentList.actions.length).toBe(1);
|
||||||
expect(folderActions.getHandler).toHaveBeenCalled();
|
expect(folderActions.getHandler).toHaveBeenCalled();
|
||||||
|
expect(documentActions.getHandler).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be case insensitive for document target', () => {
|
it('should be case insensitive for document target', () => {
|
||||||
@@ -193,20 +213,6 @@ describe('ContentAction', () => {
|
|||||||
model.execute('<obj>');
|
model.execute('<obj>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should sync localizable fields with model', () => {
|
|
||||||
|
|
||||||
let action = new ContentActionComponent(actionList, null, null);
|
|
||||||
action.title = 'title1';
|
|
||||||
action.ngOnInit();
|
|
||||||
|
|
||||||
expect(action.model.title).toBe(action.title);
|
|
||||||
|
|
||||||
action.title = 'title2';
|
|
||||||
action.ngOnChanges(null);
|
|
||||||
|
|
||||||
expect(action.model.title).toBe('title2');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not find document action handler with missing service', () => {
|
it('should not find document action handler with missing service', () => {
|
||||||
let action = new ContentActionComponent(actionList, null, null);
|
let action = new ContentActionComponent(actionList, null, null);
|
||||||
expect(action.getSystemHandler('document', 'name')).toBeNull();
|
expect(action.getSystemHandler('document', 'name')).toBeNull();
|
||||||
@@ -245,31 +251,31 @@ describe('ContentAction', () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should wire model with custom event handler', (done) => {
|
it('should wire model with custom event handler', async(() => {
|
||||||
let action = new ContentActionComponent(actionList, documentActions, folderActions);
|
let action = new ContentActionComponent(actionList, documentActions, folderActions);
|
||||||
let file = new FileNode();
|
let file = new FileNode();
|
||||||
|
|
||||||
let handler = new EventEmitter();
|
let handler = new EventEmitter();
|
||||||
handler.subscribe((e) => {
|
handler.subscribe((e) => {
|
||||||
expect(e.value).toBe(file);
|
expect(e.value).toBe(file);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
action.execute = handler;
|
action.execute = handler;
|
||||||
|
|
||||||
action.ngOnInit();
|
action.ngOnInit();
|
||||||
action.model.execute(file);
|
documentList.actions[0].execute(file);
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should allow registering model without handler', () => {
|
it('should allow registering model without handler', () => {
|
||||||
let action = new ContentActionComponent(actionList, documentActions, folderActions);
|
let action = new ContentActionComponent(actionList, documentActions, folderActions);
|
||||||
|
|
||||||
spyOn(actionList, 'registerAction').and.callThrough();
|
spyOn(actionList, 'registerAction').and.callThrough();
|
||||||
action.execute = null;
|
action.execute = null;
|
||||||
|
action.handler = null;
|
||||||
|
action.target = 'document';
|
||||||
action.ngOnInit();
|
action.ngOnInit();
|
||||||
|
|
||||||
expect(action.model.handler).toBeUndefined();
|
expect(actionList.registerAction).toHaveBeenCalledWith(documentList.actions[0]);
|
||||||
expect(actionList.registerAction).toHaveBeenCalledWith(action.model);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should register on init', () => {
|
it('should register on init', () => {
|
||||||
@@ -281,10 +287,11 @@ describe('ContentAction', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should require action list to register action with', () => {
|
it('should require action list to register action with', () => {
|
||||||
|
const fakeModel = new ContentActionModel();
|
||||||
let action = new ContentActionComponent(actionList, null, null);
|
let action = new ContentActionComponent(actionList, null, null);
|
||||||
expect(action.register()).toBeTruthy();
|
expect(action.register(fakeModel)).toBeTruthy();
|
||||||
|
|
||||||
action = new ContentActionComponent(null, null, null);
|
action = new ContentActionComponent(null, null, null);
|
||||||
expect(action.register()).toBeFalsy();
|
expect(action.register(fakeModel)).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -17,12 +17,12 @@
|
|||||||
|
|
||||||
/* tslint:disable:component-selector */
|
/* tslint:disable:component-selector */
|
||||||
|
|
||||||
import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core';
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||||
|
|
||||||
import { ContentActionHandler } from '../../models/content-action.model';
|
import { ContentActionHandler } from '../../models/content-action.model';
|
||||||
import { DocumentActionsService } from '../../services/document-actions.service';
|
import { DocumentActionsService } from '../../services/document-actions.service';
|
||||||
import { FolderActionsService } from '../../services/folder-actions.service';
|
import { FolderActionsService } from '../../services/folder-actions.service';
|
||||||
import { ContentActionModel } from './../../models/content-action.model';
|
import { ContentActionModel, ContentActionTarget } from './../../models/content-action.model';
|
||||||
import { ContentActionListComponent } from './content-action-list.component';
|
import { ContentActionListComponent } from './content-action-list.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -33,7 +33,7 @@ import { ContentActionListComponent } from './content-action-list.component';
|
|||||||
FolderActionsService
|
FolderActionsService
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class ContentActionComponent implements OnInit, OnChanges {
|
export class ContentActionComponent implements OnInit {
|
||||||
|
|
||||||
/** The title of the action as shown in the menu. */
|
/** The title of the action as shown in the menu. */
|
||||||
@Input()
|
@Input()
|
||||||
@@ -49,7 +49,7 @@ export class ContentActionComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
/** Type of item that the action appies to. Can be "document" or "folder" */
|
/** Type of item that the action appies to. Can be "document" or "folder" */
|
||||||
@Input()
|
@Input()
|
||||||
target: string;
|
target: string = ContentActionTarget.All;
|
||||||
|
|
||||||
/** The permission type. */
|
/** The permission type. */
|
||||||
@Input()
|
@Input()
|
||||||
@@ -83,58 +83,58 @@ export class ContentActionComponent implements OnInit, OnChanges {
|
|||||||
@Output()
|
@Output()
|
||||||
success = new EventEmitter();
|
success = new EventEmitter();
|
||||||
|
|
||||||
model: ContentActionModel;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private list: ContentActionListComponent,
|
private list: ContentActionListComponent,
|
||||||
private documentActions: DocumentActionsService,
|
private documentActions: DocumentActionsService,
|
||||||
private folderActions: FolderActionsService) {
|
private folderActions: FolderActionsService) {
|
||||||
this.model = new ContentActionModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.model = new ContentActionModel({
|
if (this.target === ContentActionTarget.All) {
|
||||||
title: this.title,
|
this.generateAction(ContentActionTarget.Folder);
|
||||||
icon: this.icon,
|
this.generateAction(ContentActionTarget.Document);
|
||||||
permission: this.permission,
|
} else {
|
||||||
disableWithNoPermission: this.disableWithNoPermission,
|
this.generateAction(this.target);
|
||||||
target: this.target,
|
|
||||||
disabled: this.disabled
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.handler) {
|
|
||||||
this.model.handler = this.getSystemHandler(this.target, this.handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.execute) {
|
|
||||||
this.model.execute = (value: any): void => {
|
|
||||||
this.execute.emit({ value });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
this.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
register(): boolean {
|
register(model: ContentActionModel): boolean {
|
||||||
if (this.list) {
|
if (this.list) {
|
||||||
return this.list.registerAction(this.model);
|
return this.list.registerAction(model);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes) {
|
private generateAction(target: string) {
|
||||||
// update localizable properties
|
let model = new ContentActionModel({
|
||||||
this.model.title = this.title;
|
title: this.title,
|
||||||
|
icon: this.icon,
|
||||||
|
permission: this.permission,
|
||||||
|
disableWithNoPermission: this.disableWithNoPermission,
|
||||||
|
target: target,
|
||||||
|
disabled: this.disabled
|
||||||
|
});
|
||||||
|
if (this.handler) {
|
||||||
|
model.handler = this.getSystemHandler(target, this.handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.execute) {
|
||||||
|
model.execute = (value: any): void => {
|
||||||
|
this.execute.emit({ value });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.register(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSystemHandler(target: string, name: string): ContentActionHandler {
|
getSystemHandler(target: string, name: string): ContentActionHandler {
|
||||||
if (target) {
|
if (target) {
|
||||||
let ltarget = target.toLowerCase();
|
let ltarget = target.toLowerCase();
|
||||||
|
|
||||||
if (ltarget === 'document') {
|
if (ltarget === ContentActionTarget.Document) {
|
||||||
if (this.documentActions) {
|
if (this.documentActions) {
|
||||||
this.documentActions.permissionEvent.subscribe((permision) => {
|
this.documentActions.permissionEvent.subscribe((permission) => {
|
||||||
this.permissionEvent.emit(permision);
|
this.permissionEvent.emit(permission);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.documentActions.error.subscribe((errors) => {
|
this.documentActions.error.subscribe((errors) => {
|
||||||
@@ -150,10 +150,10 @@ export class ContentActionComponent implements OnInit, OnChanges {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ltarget === 'folder') {
|
if (ltarget === ContentActionTarget.Folder) {
|
||||||
if (this.folderActions) {
|
if (this.folderActions) {
|
||||||
this.folderActions.permissionEvent.subscribe((permision) => {
|
this.folderActions.permissionEvent.subscribe((permission) => {
|
||||||
this.permissionEvent.emit(permision);
|
this.permissionEvent.emit(permission);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.folderActions.error.subscribe((errors) => {
|
this.folderActions.error.subscribe((errors) => {
|
||||||
|
@@ -39,6 +39,12 @@ export class ContentActionModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ContentActionTarget {
|
||||||
|
Document = 'document',
|
||||||
|
Folder = 'folder',
|
||||||
|
All = 'all'
|
||||||
|
}
|
||||||
|
|
||||||
export type ContentActionHandler = (obj: any, target?: any, permission?: string) => any;
|
export type ContentActionHandler = (obj: any, target?: any, permission?: string) => any;
|
||||||
|
|
||||||
export class DocumentActionModel extends ContentActionModel {
|
export class DocumentActionModel extends ContentActionModel {
|
||||||
|
Reference in New Issue
Block a user