Customisation of global actions (folders and documents)

- support for registering custom global actions (folders, documents)
- documentation update with code samples and pictures

refs #9
This commit is contained in:
Denys Vuika 2016-05-03 15:15:23 +01:00
parent 43344881e9
commit 0ff5701900
13 changed files with 123 additions and 12 deletions

View File

@ -43,8 +43,8 @@
<folder-action title="Custom folder action" (execute)="myFolderAction1($event)"></folder-action>
</folder-actions>
<quick-document-actions>
<quick-document-action icon="extension" handler="system1"></quick-document-action>
<quick-document-action icon="thumb_up" handler="system2"></quick-document-action>
<quick-document-action icon="account_circle" handler="my-handler"></quick-document-action>
<quick-document-action icon="cloud_download" handler="download"></quick-document-action>
</quick-document-actions>
<document-actions>
<document-action title="Download" handler="DOWNLOAD"></document-action>

View File

@ -17,7 +17,8 @@
import {Component} from 'angular2/core';
import {
DOCUMENT_LIST_DIRECTIVES,
DOCUMENT_LIST_PROVIDERS
DOCUMENT_LIST_PROVIDERS,
DocumentActionsService
} from 'ng2-alfresco-documentlist/ng2-alfresco-documentlist';
import {MDL} from 'ng2-alfresco-core/material';
@ -36,6 +37,14 @@ export class FilesComponent {
navigation: boolean = true;
events: any[] = [];
constructor(documentActions: DocumentActionsService) {
documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this));
}
myDocumentActionHandler(obj: any) {
window.alert('my custom action handler');
}
onItemClick($event) {
console.log($event.value);

View File

@ -226,4 +226,70 @@ Every folder action is rendered as a separate button.
### Customizing default actions
TBD
It is possible extending or replacing the list of available system actions for documents and folders.
Actions for the documents and folders can be accessed via the following services:
- `DocumentActionsService`, document action menu and quick document actions
- `FolderActionsService`, folder action menu and quick folder actions
Example below demonstrates how a new action handler can be registered with the
`DocumentActionsService`.
```html
<alfresco-document-list ...>
<quick-document-actions>
<quick-document-action icon="account_circle" handler="my-handler"></quick-document-action>
</quick-document-actions>
</alfresco-document-list>
```
You register custom handler called `my-handler` that will be executing `myDocumentActionHandler`
function each time upon being invoked.
```ts
import {
DocumentActionsService
} from 'ng2-alfresco-documentlist/ng2-alfresco-documentlist';
export class MyView {
constructor(documentActions: DocumentActionsService) {
documentActions.setHandler(
'my-handler',
this.myDocumentActionHandler.bind(this)
);
}
myDocumentActionHandler(obj: any) {
window.alert('my custom action handler');
}
}
```
![Custom handler 1](docs/assets/custom-doc-handler-1.png)
Upon execution users will see the following dialog:
![Custom handler 2](docs/assets/custom-doc-handler-2.png)
The same approach allows changing the way out-of-box action handlers behave.
Registering custom action with the name `download` replaces default one:
```ts
export class MyView {
constructor(documentActions: DocumentActionsService) {
documentActions.setHandler(
'download',
this.customDownloadBehavior.bind(this)
);
}
customDownloadBehavior(obj: any) {
window.alert('my custom download behavior');
}
}
```
Typically you may want populating all your custom actions at the application root level or
by means of custom application service.

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -5,6 +5,7 @@ export declare class DocumentActionsService {
private handlers;
constructor(_alfrescoService: AlfrescoService);
getHandler(key: string): ContentActionHandler;
setHandler(key: string, handler: ContentActionHandler): void;
private setupActionHandlers();
private handleStandardAction1(obj);
private handleStandardAction2(obj);

View File

@ -50,6 +50,12 @@ System.register(['angular2/core', './alfresco.service'], function(exports_1, con
}
return null;
};
DocumentActionsService.prototype.setHandler = function (key, handler) {
if (key) {
var lkey = key.toLowerCase();
this.handlers[lkey] = handler;
}
};
DocumentActionsService.prototype.setupActionHandlers = function () {
this.handlers['download'] = this.download.bind(this);
// todo: just for dev/demo purposes, to be replaced with real actions

View File

@ -1 +1 @@
{"version":3,"file":"document-actions.service.js","sourceRoot":"","sources":["document-actions.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;;;;YAOH;gBAGI,gCAAoB,gBAAiC;oBAAjC,qBAAgB,GAAhB,gBAAgB,CAAiB;oBAF7C,aAAQ,GAA4C,EAAE,CAAC;oBAG3D,IAAI,CAAC,mBAAmB,EAAE,CAAC;gBAC/B,CAAC;gBAED,2CAAU,GAAV,UAA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oBACjE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACrE,CAAC;gBAEO,sDAAqB,GAA7B,UAA8B,GAAQ;oBAClC,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;gBAC/C,CAAC;gBAEO,sDAAqB,GAA7B,UAA8B,GAAQ;oBAClC,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;gBAC/C,CAAC;gBAEO,yCAAQ,GAAhB,UAAiB,GAAQ;oBACrB,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACvB,IAAI,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;wBACvC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;wBAChC,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;wBAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;wBACrD,IAAI,CAAC,KAAK,EAAE,CAAC;wBACb,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;oBACpC,CAAC;gBACL,CAAC;gBAhDL;oBAAC,iBAAU,EAAE;;0CAAA;gBAiDb,6BAAC;YAAD,CAAC,AAhDD,IAgDC;YAhDD,2DAgDC,CAAA"}

View File

@ -35,6 +35,13 @@ export class DocumentActionsService {
return null;
}
setHandler(key: string, handler: ContentActionHandler): void {
if (key) {
let lkey = key.toLowerCase();
this.handlers[lkey] = handler;
}
}
private setupActionHandlers() {
this.handlers['download'] = this.download.bind(this);

View File

@ -3,6 +3,7 @@ export declare class FolderActionsService {
private handlers;
constructor();
getHandler(key: string): ContentActionHandler;
setHandler(key: string, handler: ContentActionHandler): void;
private handleStandardAction1(document);
private handleStandardAction2(document);
}

View File

@ -38,11 +38,21 @@ System.register(['angular2/core'], function(exports_1, context_1) {
function FolderActionsService() {
this.handlers = {};
// todo: just for dev/demo purposes, to be replaced with real actions
this.handlers['system1'] = this.handleStandardAction1;
this.handlers['system2'] = this.handleStandardAction2;
this.handlers['system1'] = this.handleStandardAction1.bind(this);
this.handlers['system2'] = this.handleStandardAction2.bind(this);
}
FolderActionsService.prototype.getHandler = function (key) {
return this.handlers[key];
if (key) {
var lkey = key.toLowerCase();
return this.handlers[lkey];
}
return null;
};
FolderActionsService.prototype.setHandler = function (key, handler) {
if (key) {
var lkey = key.toLowerCase();
this.handlers[lkey] = handler;
}
};
FolderActionsService.prototype.handleStandardAction1 = function (document) {
window.alert('standard folder action 1');

View File

@ -1 +1 @@
{"version":3,"file":"folder-actions.service.js","sourceRoot":"","sources":["folder-actions.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;YAMH;gBAGI;oBAFQ,aAAQ,GAA4C,EAAE,CAAC;oBAG3D,qEAAqE;oBACrE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC;oBACtD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC;gBAC1D,CAAC;gBAED,yCAAU,GAAV,UAAW,GAAW;oBAClB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAC9B,CAAC;gBAEO,oDAAqB,GAA7B,UAA8B,QAAa;oBACvC,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;gBAC7C,CAAC;gBAEO,oDAAqB,GAA7B,UAA8B,QAAa;oBACvC,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;gBAC7C,CAAC;gBApBL;oBAAC,iBAAU,EAAE;;wCAAA;gBAqBb,2BAAC;YAAD,CAAC,AApBD,IAoBC;YApBD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View File

@ -24,12 +24,23 @@ export class FolderActionsService {
constructor() {
// todo: just for dev/demo purposes, to be replaced with real actions
this.handlers['system1'] = this.handleStandardAction1;
this.handlers['system2'] = this.handleStandardAction2;
this.handlers['system1'] = this.handleStandardAction1.bind(this);
this.handlers['system2'] = this.handleStandardAction2.bind(this);
}
getHandler(key: string): ContentActionHandler {
return this.handlers[key];
if (key) {
let lkey = key.toLowerCase();
return this.handlers[lkey];
}
return null;
}
setHandler(key: string, handler: ContentActionHandler): void {
if (key) {
let lkey = key.toLowerCase();
this.handlers[lkey] = handler;
}
}
private handleStandardAction1(document: any) {