From 3b9daa6af92637841b8a60a3f4ce0912b3dab240 Mon Sep 17 00:00:00 2001 From: Lvbo163 Date: Sun, 17 Sep 2017 14:54:05 +0800 Subject: Add CRUD operation for workflows Add CRUD and export operation for workflows. Issue-ID: SDC-72 Change-Id: Ie2ef818a6979cc13b9e2dad7cea3b3121727146f Signed-off-by: Lvbo163 --- .../src/app/services/broadcast.service.ts | 7 +++++ .../app/services/data-access/catalog.service.ts | 1 + .../src/app/services/data-access/sdc.service.ts | 4 +-- .../src/app/services/jsplumb.service.ts | 22 +++++++++---- .../src/app/services/workflow.service.ts | 36 ++++++++++++++++++++-- 5 files changed, 60 insertions(+), 10 deletions(-) (limited to 'sdc-workflow-designer-ui/src/app/services') diff --git a/sdc-workflow-designer-ui/src/app/services/broadcast.service.ts b/sdc-workflow-designer-ui/src/app/services/broadcast.service.ts index ec182b36..dbf52f9f 100644 --- a/sdc-workflow-designer-ui/src/app/services/broadcast.service.ts +++ b/sdc-workflow-designer-ui/src/app/services/broadcast.service.ts @@ -14,6 +14,7 @@ import { Subject } from 'rxjs/Subject'; import { WorkflowNode } from '../model/workflow/workflow-node'; import { SequenceFlow } from "../model/workflow/sequence-flow"; +import { Workflow } from "../model/workflow/workflow"; /** * BroadcastService @@ -26,6 +27,12 @@ export class BroadcastService { public jsPlumbInstance = new Subject(); public jsPlumbInstance$ = this.jsPlumbInstance.asObservable(); + public workflows = new Subject(); + public workflows$ = this.workflows.asObservable(); + + public workflow = new Subject(); + public workflow$ = this.workflow.asObservable(); + public showProperty = new Subject(); public showProperty$ = this.showProperty.asObservable(); diff --git a/sdc-workflow-designer-ui/src/app/services/data-access/catalog.service.ts b/sdc-workflow-designer-ui/src/app/services/data-access/catalog.service.ts index abd73558..d5d998fe 100644 --- a/sdc-workflow-designer-ui/src/app/services/data-access/catalog.service.ts +++ b/sdc-workflow-designer-ui/src/app/services/data-access/catalog.service.ts @@ -26,6 +26,7 @@ export abstract class CatalogService { constructor(protected httpService: HttpService) {} public abstract loadWorkflow(workflowId: string): Observable; + public abstract loadWorkflows(): Observable; public abstract saveWorkflow(workflow: Workflow): Observable; } diff --git a/sdc-workflow-designer-ui/src/app/services/data-access/sdc.service.ts b/sdc-workflow-designer-ui/src/app/services/data-access/sdc.service.ts index 02ade955..81efbed9 100644 --- a/sdc-workflow-designer-ui/src/app/services/data-access/sdc.service.ts +++ b/sdc-workflow-designer-ui/src/app/services/data-access/sdc.service.ts @@ -28,10 +28,10 @@ export class SdcService extends CatalogService { super(httpService); } - public loadWorkflows(): Observable { + public loadWorkflows(): Observable { // TODO load data from sdc const url = 'api/workflows'; - return this.httpService.get(url); + return this.httpService.get(url).map(response => response.data); } public loadWorkflow(workflowId: string): Observable { diff --git a/sdc-workflow-designer-ui/src/app/services/jsplumb.service.ts b/sdc-workflow-designer-ui/src/app/services/jsplumb.service.ts index 6aa5028a..bf7a6901 100644 --- a/sdc-workflow-designer-ui/src/app/services/jsplumb.service.ts +++ b/sdc-workflow-designer-ui/src/app/services/jsplumb.service.ts @@ -27,15 +27,21 @@ export class JsPlumbService { public subscriptionMap = new Map(); constructor(private processService: WorkflowProcessService, private broadcastService: BroadcastService) { + this.jsplumbInstance = jsp.jsPlumb.getInstance({ + Container: 'canvas' + }); this.initJsPlumbInstance(); + this.broadcastService.workflow.subscribe(Workflow => { + this.jsplumbInstance.reset(); + this.unsubscriptionAll(); + this.initJsPlumbInstance(); + this.buttonDraggable(); + this.buttonDroppable(); + }); } public initJsPlumbInstance() { - this.jsplumbInstance = jsp.jsPlumb.getInstance({ - Container: 'canvas' - }); - this.jsplumbInstance.importDefaults({ Anchor: ['Top', 'RightMiddle', 'LeftMiddle', 'Bottom'], Connector: [ @@ -119,6 +125,10 @@ export class JsPlumbService { }); } + private unsubscriptionAll() { + this.subscriptionMap.forEach(subscription => subscription.unsubscribe()); + } + public initNode() { this.processService.getProcess().forEach(node => { this.jsplumbInstance.draggable(node.id, { @@ -154,8 +164,8 @@ export class JsPlumbService { source: sequenceFlow.sourceRef, target: sequenceFlow.targetRef, }); - if (sequenceFlow.condition) { - connection.setLabel(sequenceFlow.condition); + if (sequenceFlow.name) { + connection.setLabel(sequenceFlow.name); } }); } diff --git a/sdc-workflow-designer-ui/src/app/services/workflow.service.ts b/sdc-workflow-designer-ui/src/app/services/workflow.service.ts index c1eed4af..3f42fa26 100644 --- a/sdc-workflow-designer-ui/src/app/services/workflow.service.ts +++ b/sdc-workflow-designer-ui/src/app/services/workflow.service.ts @@ -14,6 +14,8 @@ import { Injectable } from '@angular/core'; import { DataAccessService } from "./data-access/data-access.service"; import { Observable } from "rxjs/Observable"; import { Workflow } from "../model/workflow/workflow"; +import { Configs } from "../model/workflow/configs"; +import { BroadcastService } from "./broadcast.service"; /** * WorkflowService @@ -22,10 +24,16 @@ import { Workflow } from "../model/workflow/workflow"; @Injectable() export class WorkflowService { + public workflows: Workflow[]; public workflow: Workflow; + public workflowIndex = 0; - constructor(private dataAccessService: DataAccessService) { - + constructor(private broadcastService: BroadcastService, private dataAccessService: DataAccessService) { + this.dataAccessService.catalogService.loadWorkflows().subscribe(workflows => { + this.workflows = workflows; + this.broadcastWorkflows(); + }); + this.broadcastService.workflow.subscribe(workflow => this.workflow = workflow); } public save(): Observable { @@ -33,4 +41,28 @@ export class WorkflowService { console.log(JSON.stringify(this.workflow)); return this.dataAccessService.catalogService.saveWorkflow(this.workflow); } + + public getWorkflows(): Workflow[] { + return this.workflows; + } + + public addWorkflow() { + this.workflows.push(new Workflow('wf' + this.workflowIndex, '', [], new Configs([]))); + this.workflowIndex++; + this.broadcastWorkflows(); + } + + public deleteWorkflow(workflowName: string): Workflow { + const index = this.workflows.findIndex(workflow => (workflow.name === workflowName)); + if(index !== -1) { + return this.workflows.splice(index, 1)[0]; + } + this.broadcastWorkflows(); + + return undefined; + } + + public broadcastWorkflows() { + this.broadcastService.broadcast(this.broadcastService.workflows, this.workflows); + } } -- cgit 1.2.3-korg