From a945cd1fff78624c08217f9fbd92056b8d893717 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 27 Jul 2016 11:44:20 +0100 Subject: [PATCH] #482 populate action/context menu with bpm processes --- .../app/components/files/files.component.ts | 43 ++++++++++++++++--- .../src/services/form.service.ts | 12 +++++- .../ng2-alfresco-documentlist/index.ts | 4 ++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/demo-shell-ng2/app/components/files/files.component.ts b/demo-shell-ng2/app/components/files/files.component.ts index 98c21b3d1f..6d3cac70b3 100644 --- a/demo-shell-ng2/app/components/files/files.component.ts +++ b/demo-shell-ng2/app/components/files/files.component.ts @@ -15,11 +15,13 @@ * limitations under the License. */ -import { Component } from '@angular/core'; +import { Component, OnInit, ViewChild } from '@angular/core'; import { DOCUMENT_LIST_DIRECTIVES, DOCUMENT_LIST_PROVIDERS, - DocumentActionsService + DocumentActionsService, + DocumentList, + ContentActionModel, ContentActionHandler } from 'ng2-alfresco-documentlist'; import { MDL, @@ -30,6 +32,7 @@ import { import { PaginationComponent } from 'ng2-alfresco-datatable'; import { ALFRESCO_ULPOAD_COMPONENTS } from 'ng2-alfresco-upload'; import { VIEWERCOMPONENT } from 'ng2-alfresco-viewer'; +import { FormService } from 'ng2-activiti-form'; declare let __moduleName: string; @@ -46,10 +49,10 @@ declare let __moduleName: string; CONTEXT_MENU_DIRECTIVES, PaginationComponent ], - providers: [DOCUMENT_LIST_PROVIDERS], + providers: [DOCUMENT_LIST_PROVIDERS, FormService], pipes: [AlfrescoPipeTranslate] }) -export class FilesComponent { +export class FilesComponent implements OnInit { currentPath: string = '/Sites/swsdp/documentLibrary'; urlFile: string; @@ -62,8 +65,12 @@ export class FilesComponent { acceptedFilesType: string = '.jpg,.pdf,.js'; + @ViewChild(DocumentList) + documentList: DocumentList; + constructor(private contentService: AlfrescoContentService, - documentActions: DocumentActionsService) { + private documentActions: DocumentActionsService, + private formService: FormService) { documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this)); } @@ -111,4 +118,30 @@ export class FilesComponent { this.acceptedFilesTypeShow = !this.acceptedFilesTypeShow; return this.acceptedFilesTypeShow; } + + ngOnInit() { + console.log(this.documentList); + this.formService.getProcessDefinitions().subscribe( + defs => this.setupBpmActions(defs || []), + err => console.log(err) + ); + } + + private setupBpmActions(actions: any[]) { + actions.map(def => { + let action = new ContentActionModel(); + action.target = 'document'; + action.title = 'Activiti: ' + (def.name || 'Unknown process'); + action.handler = this.getBpmActionHandler(def); + this.documentList.actions.push(action); + }); + + console.log(this.documentList.actions); + } + + private getBpmActionHandler(processDefinition: any): ContentActionHandler { + return function (obj: any, target?: any) { + window.alert(`Starting BPM process: ${processDefinition.id}`); + }.bind(this); + } } diff --git a/ng2-components/ng2-activiti-form/src/services/form.service.ts b/ng2-components/ng2-activiti-form/src/services/form.service.ts index 2202583a2d..686a74743e 100644 --- a/ng2-components/ng2-activiti-form/src/services/form.service.ts +++ b/ng2-components/ng2-activiti-form/src/services/form.service.ts @@ -24,7 +24,17 @@ import { AlfrescoSettingsService } from 'ng2-alfresco-core'; @Injectable() export class FormService { - constructor(private http: Http, private alfrescoSettingsService: AlfrescoSettingsService) { + constructor(private http: Http, + private alfrescoSettingsService: AlfrescoSettingsService) { + } + + getProcessDefinitions(): Observable { + let url = `${this.alfrescoSettingsService.bpmHost}/activiti-app/api/enterprise/process-definitions`; + let options = this.getRequestOptions(); + return this.http + .get(url, options) + .map(this.toJsonArray) + .catch(this.handleError); } getTasks(): Observable { diff --git a/ng2-components/ng2-alfresco-documentlist/index.ts b/ng2-components/ng2-alfresco-documentlist/index.ts index 7c2f142c61..71ed776fef 100644 --- a/ng2-components/ng2-alfresco-documentlist/index.ts +++ b/ng2-components/ng2-alfresco-documentlist/index.ts @@ -41,6 +41,10 @@ export * from './src/services/folder-actions.service'; export * from './src/services/document-actions.service'; export * from './src/services/document-list.service'; +// models +export * from './src/models/content-action.model'; +export * from './src/models/document-library.model'; + export const DOCUMENT_LIST_DIRECTIVES: [any] = [ DocumentList, ContentColumn,