diff options
Diffstat (limited to 'sdc-workflow-designer-ui/src/app/services')
5 files changed, 60 insertions, 10 deletions
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<any>(); public jsPlumbInstance$ = this.jsPlumbInstance.asObservable(); + public workflows = new Subject<Workflow[]>(); + public workflows$ = this.workflows.asObservable(); + + public workflow = new Subject<Workflow>(); + public workflow$ = this.workflow.asObservable(); + public showProperty = new Subject<boolean>(); 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<Workflow>;
+ public abstract loadWorkflows(): Observable<Workflow[]>;
public abstract saveWorkflow(workflow: Workflow): Observable<boolean>;
}
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<WorkflowNode[]> {
+ public loadWorkflows(): Observable<Workflow[]> {
// 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<Workflow> {
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<string, Subscription>();
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<boolean> {
@@ -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);
+ }
}
|