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/workflow.service.ts | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'sdc-workflow-designer-ui/src/app/services/workflow.service.ts') 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