aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-workflow-designer-ui/src
diff options
context:
space:
mode:
authorLvbo163 <lv.bo163@zte.com.cn>2018-01-09 19:31:52 +0800
committerLvbo163 <lv.bo163@zte.com.cn>2018-01-09 20:03:06 +0800
commiteb2d1c385e5c3d96e770b776f74ddbde9f2b133f (patch)
tree18c655f6dd331c7752f13d7f79a04ea20e774d59 /sdc-workflow-designer-ui/src
parent2356116cdf19843ba11bc0e781577b5a539ba712 (diff)
fix error while workflow is empty
workflow select list error while workflow list is empty Issue-ID: SDC-891 Change-Id: I3c92891efe4b323fcc6130b3ead6dcc7ff61af48 Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
Diffstat (limited to 'sdc-workflow-designer-ui/src')
-rw-r--r--sdc-workflow-designer-ui/src/app/app.module.ts4
-rw-r--r--sdc-workflow-designer-ui/src/app/components/canvas/canvas.component.ts4
-rw-r--r--sdc-workflow-designer-ui/src/app/components/menu/menu.component.ts13
-rw-r--r--sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.html2
-rw-r--r--sdc-workflow-designer-ui/src/app/components/property/properties.component.ts4
-rw-r--r--sdc-workflow-designer-ui/src/app/components/sequence-flow/sequence-flow.component.ts4
-rw-r--r--sdc-workflow-designer-ui/src/app/services/broadcast.service.ts2
-rw-r--r--sdc-workflow-designer-ui/src/app/services/jsplumb.service.ts4
-rw-r--r--sdc-workflow-designer-ui/src/app/services/workflow-process.service.ts224
9 files changed, 24 insertions, 237 deletions
diff --git a/sdc-workflow-designer-ui/src/app/app.module.ts b/sdc-workflow-designer-ui/src/app/app.module.ts
index 4ce9eedb..199bfcdf 100644
--- a/sdc-workflow-designer-ui/src/app/app.module.ts
+++ b/sdc-workflow-designer-ui/src/app/app.module.ts
@@ -43,12 +43,12 @@ import { RestTaskParametersComponent } from "./components/property/rest-task/res
import { ParameterTreeComponent } from "./components/parameter-tree/parameter-tree.component";
import { EditablePropertyComponent } from "./components/editable-property/editable-property.component";
import { SwaggerTreeConverterService } from "./services/swagger-tree-converter.service";
-import { WorkflowProcessService } from "./services/workflow-process.service";
import { IntermediateCatchEventComponent } from "./components/property/intermediate-catch-event/intermediate-catch-event.component";
import { SequenceFlowComponent } from "./components/sequence-flow/sequence-flow.component";
import { ScriptTaskComponent } from "./components/property/script-task/script-task.component";
import { DragSelectDirective } from "./directive/drag-select/drag-select.directive";
import { WorkflowsComponent } from "./components/menu/workflows/workflows.component";
+import { ModelService } from './services/model.service';
@NgModule({
declarations: [
@@ -98,7 +98,7 @@ import { WorkflowsComponent } from "./components/menu/workflows/workflows.compon
JsPlumbService,
SwaggerTreeConverterService,
WorkflowConfigService,
- WorkflowProcessService,
+ ModelService,
WorkflowService
],
bootstrap: [AppComponent]
diff --git a/sdc-workflow-designer-ui/src/app/components/canvas/canvas.component.ts b/sdc-workflow-designer-ui/src/app/components/canvas/canvas.component.ts
index 453e6d55..1cf197df 100644
--- a/sdc-workflow-designer-ui/src/app/components/canvas/canvas.component.ts
+++ b/sdc-workflow-designer-ui/src/app/components/canvas/canvas.component.ts
@@ -18,7 +18,7 @@ import { ActivatedRoute } from "@angular/router";
import { DataAccessService } from "../../services/data-access/data-access.service";
import { WorkflowService } from "../../services/workflow.service";
import { PlanModel } from "../../model/workflow/plan-model";
-import { WorkflowProcessService } from "../../services/workflow-process.service";
+import { ModelService } from "../../services/model.service";
import { SequenceFlow } from "../../model/workflow/sequence-flow";
import { WorkflowNode } from "../../model/workflow/workflow-node";
@@ -42,7 +42,7 @@ export class CanvasComponent implements AfterViewInit {
private jsPlumbService: JsPlumbService,
private route: ActivatedRoute,
private workflowService: WorkflowService,
- private processService: WorkflowProcessService) {
+ private processService: ModelService) {
}
ngOnInit(): void {
diff --git a/sdc-workflow-designer-ui/src/app/components/menu/menu.component.ts b/sdc-workflow-designer-ui/src/app/components/menu/menu.component.ts
index b3954911..adad16c1 100644
--- a/sdc-workflow-designer-ui/src/app/components/menu/menu.component.ts
+++ b/sdc-workflow-designer-ui/src/app/components/menu/menu.component.ts
@@ -26,8 +26,19 @@ export class MenuComponent {
@ViewChild(MicroserviceComponent) public microserviceComponent: MicroserviceComponent;
@ViewChild(WorkflowsComponent) public workflowsComponent: WorkflowsComponent;
public currentWorkflow = 'Workflows';
+ public workflows = [];
constructor(private broadcastService: BroadcastService, private workflowService: WorkflowService) {
+ this.broadcastService.workflows.subscribe(wfs => {
+ this.workflows.splice(0, this.workflows.length);
+ if(wfs) {
+ wfs.forEach((value, key, map) => {
+ this.workflows.push({label: value.planName, command: () => {
+ this.workflowSelected(value.planName, value.plan);
+ }});
+ });
+ }
+ });
}
public save(): void {
@@ -45,7 +56,7 @@ export class MenuComponent {
this.workflowsComponent.show();
}
- public getWorkflows(planId: number) {
+ public getWorkflows() {
const workflows = this.workflowService.getWorkflows();
if(workflows) {
const options = [];
diff --git a/sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.html b/sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.html
index 5568ba60..0f6c7ff2 100644
--- a/sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.html
+++ b/sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.html
@@ -24,7 +24,7 @@ tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="tru
<div class="modal-body">
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center"
- *ngFor="let key of workflows.keys()">
+ *ngFor="let key of workflows?.keys()">
<div style="width:380px"><input class="form-control" [(ngModel)]="workflows.get(key).planName"></div>
<div class="badge badge-danger badge-pill" (click)="deleteWorkflow(key)">
<i class="fa fa-minus"></i>
diff --git a/sdc-workflow-designer-ui/src/app/components/property/properties.component.ts b/sdc-workflow-designer-ui/src/app/components/property/properties.component.ts
index 2aa552ed..2091d83c 100644
--- a/sdc-workflow-designer-ui/src/app/components/property/properties.component.ts
+++ b/sdc-workflow-designer-ui/src/app/components/property/properties.component.ts
@@ -16,7 +16,7 @@ import { WorkflowNode } from '../../model/workflow/workflow-node';
import { BroadcastService } from '../../services/broadcast.service';
import { JsPlumbService } from '../../services/jsplumb.service';
import { PlanTreeviewItem } from "../../model/plan-treeview-item";
-import { WorkflowProcessService } from "../../services/workflow-process.service";
+import { ModelService } from "../../services/model.service";
/**
* property component presents information of a workflow node.
@@ -36,7 +36,7 @@ export class PropertiesComponent implements AfterViewInit {
constructor(private broadcastService: BroadcastService,
private jsPlumnService: JsPlumbService,
- private processService: WorkflowProcessService) {
+ private processService: ModelService) {
}
diff --git a/sdc-workflow-designer-ui/src/app/components/sequence-flow/sequence-flow.component.ts b/sdc-workflow-designer-ui/src/app/components/sequence-flow/sequence-flow.component.ts
index 0109e273..c4a70ec9 100644
--- a/sdc-workflow-designer-ui/src/app/components/sequence-flow/sequence-flow.component.ts
+++ b/sdc-workflow-designer-ui/src/app/components/sequence-flow/sequence-flow.component.ts
@@ -16,7 +16,7 @@ import { TreeNode } from 'primeng/primeng';
import { SequenceFlow } from '../../model/workflow/sequence-flow';
import { BroadcastService } from '../../services/broadcast.service';
import { JsPlumbService } from '../../services/jsplumb.service';
-import { WorkflowProcessService } from '../../services/workflow-process.service';
+import { ModelService } from '../../services/model.service';
/**
* property component presents information of a workflow node.
@@ -33,7 +33,7 @@ export class SequenceFlowComponent implements AfterViewInit {
public show = false;
constructor(private broadcastService: BroadcastService,
- private processService: WorkflowProcessService,
+ private processService: ModelService,
private jsPlumbService: JsPlumbService) {
}
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 f28c7a63..dd75c45c 100644
--- a/sdc-workflow-designer-ui/src/app/services/broadcast.service.ts
+++ b/sdc-workflow-designer-ui/src/app/services/broadcast.service.ts
@@ -27,7 +27,7 @@ export class BroadcastService {
public jsPlumbInstance = new Subject<any>();
public jsPlumbInstance$ = this.jsPlumbInstance.asObservable();
- public workflows = new Subject<PlanModel[]>();
+ public workflows = new Subject<Map<number, any>>();
public workflows$ = this.workflows.asObservable();
public workflow = new Subject<PlanModel>();
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 bf7a6901..f0013bc5 100644
--- a/sdc-workflow-designer-ui/src/app/services/jsplumb.service.ts
+++ b/sdc-workflow-designer-ui/src/app/services/jsplumb.service.ts
@@ -12,7 +12,7 @@
import { Injectable } from '@angular/core';
import * as jsp from 'jsplumb';
-import { WorkflowProcessService } from "./workflow-process.service";
+import { ModelService } from "./model.service";
import { BroadcastService } from "./broadcast.service";
import { Subscription } from 'rxjs/Subscription';
import { WorkflowNode } from "../model/workflow/workflow-node";
@@ -26,7 +26,7 @@ export class JsPlumbService {
public jsplumbInstance;
public subscriptionMap = new Map<string, Subscription>();
- constructor(private processService: WorkflowProcessService, private broadcastService: BroadcastService) {
+ constructor(private processService: ModelService, private broadcastService: BroadcastService) {
this.jsplumbInstance = jsp.jsPlumb.getInstance({
Container: 'canvas'
});
diff --git a/sdc-workflow-designer-ui/src/app/services/workflow-process.service.ts b/sdc-workflow-designer-ui/src/app/services/workflow-process.service.ts
deleted file mode 100644
index 5afb74df..00000000
--- a/sdc-workflow-designer-ui/src/app/services/workflow-process.service.ts
+++ /dev/null
@@ -1,224 +0,0 @@
-/**
- * Copyright (c) 2017 ZTE Corporation.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and the Apache License 2.0 which both accompany this distribution,
- * and are available at http://www.eclipse.org/legal/epl-v10.html
- * and http://www.apache.org/licenses/LICENSE-2.0
- *
- * Contributors:
- * ZTE - initial API and implementation and/or initial documentation
- */
-
-import { Injectable } from '@angular/core';
-import { WorkflowNode } from "../model/workflow/workflow-node";
-import { PlanModel } from "../model/workflow/plan-model";
-import { Position } from "../model/workflow/position";
-import { NodeType } from "../model/workflow/node-type.enum";
-import { StartEvent } from "../model/workflow/start-event";
-import { SequenceFlow } from "../model/workflow/sequence-flow";
-import { RestTask } from "../model/workflow/rest-task";
-import { PlanTreeviewItem } from "../model/plan-treeview-item";
-import { WorkflowConfigService } from "./workflow-config.service";
-import { Swagger, SwaggerModelSimple, SwaggerReferenceObject } from "../model/swagger";
-import { WorkflowService } from "./workflow.service";
-import { IntermediateCatchEvent } from "../model/workflow/intermediate-catch-event";
-import { ScriptTask } from "../model/workflow/script-task";
-
-/**
- * WorkflowService
- * provides all of the operations about workflow operations.
- */
-@Injectable()
-export class WorkflowProcessService {
-
- constructor(private workflowService: WorkflowService, private configService: WorkflowConfigService) {
-
- }
-
- public getProcess(): WorkflowNode[] {
- return this.workflowService.planModel.nodes;
- }
-
- public addNode(name: string, type: string, top: number, left: number): WorkflowNode {
- let node: WorkflowNode;
- switch (type) {
- case NodeType[NodeType.startEvent]:
- node = new StartEvent(this.createId(), name, type, new Position(top, left), []);
- break;
- case NodeType[NodeType.restTask]:
- node = new RestTask(this.createId(), name, type, new Position(top, left), []);
- break;
- case NodeType[NodeType.intermediateCatchEvent]:
- node = new IntermediateCatchEvent(this.createId(), name, type, new Position(top, left), []);
- break;
- case NodeType[NodeType.scriptTask]:
- node = new ScriptTask(this.createId(), name, type, new Position(top, left), []);
- break;
- default:
- node = new WorkflowNode(this.createId(), name, type, new Position(top, left), []);
- break;
- }
-
- this.getProcess().push(node);
- return node;
- }
-
- public deleteNode(nodeId: string): WorkflowNode {
- // delete related connections
- this.getProcess().forEach(node => this.deleteSequenceFlow(node.id, nodeId));
-
- // delete current node
- const index = this.getProcess().findIndex(node => node.id === nodeId);
- if (index !== -1) {
- const node = this.getProcess().splice(index, 1)[0];
- node.sequenceFlows = [];
- return node;
- }
-
- return undefined;
- }
-
- public addSequenceFlow(sourceId: string, targetId: string) {
- const node = this.getNodeById(sourceId);
- if (node) {
- const index = node.sequenceFlows.findIndex(sequenceFlow => sequenceFlow.targetRef === targetId);
- if (index === -1) {
- node.sequenceFlows.push(new SequenceFlow(sourceId, targetId));
- }
- }
- }
-
- public deleteSequenceFlow(sourceId: string, targetId: string) {
- const node = this.getNodeById(sourceId);
- if (node) {
- const index = node.sequenceFlows.findIndex(sequenceFlow => sequenceFlow.targetRef === targetId);
- if (index !== -1) {
- node.sequenceFlows.splice(index, 1);
- }
- }
- }
-
- public getSequenceFlow(sourceRef: string, targetRef: string): SequenceFlow {
- const node = this.getNodeById(sourceRef);
- if (node) {
- const sequenceFlow = node.sequenceFlows.find(tmp => tmp.targetRef === targetRef);
- return sequenceFlow;
- } else {
- return undefined;
- }
- }
-
- public getPlanParameters(nodeId: string): PlanTreeviewItem[] {
- const preNodeList = new Array<WorkflowNode>();
- this.getPreNodes(nodeId, preNodeList);
-
- return this.loadNodeOutputs(preNodeList);
- }
-
- private loadNodeOutputs(nodes: WorkflowNode[]): PlanTreeviewItem[] {
- const params = new Array<PlanTreeviewItem>();
- nodes.forEach(node => {
- switch (node.type) {
- case NodeType[NodeType.startEvent]:
- params.push(this.loadOutput4StartEvent(<StartEvent>node));
- break;
- case NodeType[NodeType.restTask]:
- params.push(this.loadOutput4RestTask(<RestTask>node));
- break;
- default:
- break;
- }
- });
-
- return params;
- }
-
- private loadOutput4StartEvent(node: StartEvent): PlanTreeviewItem {
- const startItem = new PlanTreeviewItem(node.name, `[${node.id}]`, []);
- node.parameters.map(param =>
- startItem.children.push(new PlanTreeviewItem(param.name, `[${param.name}]`, [])));
- return startItem;
- }
-
- private loadOutput4RestTask(node: RestTask): PlanTreeviewItem {
- const item = new PlanTreeviewItem(node.name, `[${node.id}]`, []);
- item.children.push(this.createStatusCodeTreeViewItem(node.id));
-
- if (node.responses.length !== 0) { // load rest responses
- const responseItem = this.createResponseTreeViewItem(node.id);
- item.children.push(responseItem);
- if (node.responses[0]) {
- const swagger = this.configService.getSwaggerInfo(node.serviceName, node.serviceVersion);
- const swaggerDefinition = this.configService.getDefinition(swagger, node.responses[0].schema.$ref);
- this.loadParamsBySwaggerDefinition(responseItem, swagger, <SwaggerModelSimple>swaggerDefinition);
- }
- }
-
- return item;
- }
-
- private createStatusCodeTreeViewItem(nodeId: string): PlanTreeviewItem {
- return new PlanTreeviewItem('statusCode', `[${nodeId}].[statusCode]`, []);
- }
-
- private createResponseTreeViewItem(nodeId: string): PlanTreeviewItem {
- return new PlanTreeviewItem('response', `[${nodeId}].[responseBody]`, []);
- }
-
- private loadParamsBySwaggerDefinition(parentItem: PlanTreeviewItem, swagger: Swagger, definition: SwaggerModelSimple) {
- Object.getOwnPropertyNames(definition.properties).map(key => {
- const property = definition.properties[key];
- const value = `${parentItem.value}.[${key}]`;
- const propertyItem = new PlanTreeviewItem(key, value, []);
- parentItem.children.push(propertyItem);
-
- if (property instanceof SwaggerReferenceObject) {
- const propertyDefinition = this.configService.getDefinition(swagger, property.$ref);
- this.loadParamsBySwaggerDefinition(propertyItem, swagger,
- <SwaggerModelSimple>propertyDefinition);
- }
-
- return propertyItem;
- });
- }
-
- public getPreNodes(nodeId: string, preNodes: WorkflowNode[]) {
- const preNode4CurrentNode = [];
- this.getProcess().forEach(node => {
- if (this.isPreNode(node, nodeId)) {
- const existNode = preNodes.find(tmpNode => tmpNode.id === node.id);
- if (existNode) {
- // current node already exists in preNodes. this could avoid loop circle.
- } else {
- preNode4CurrentNode.push(node);
- preNodes.push(node);
- }
- }
- });
-
- preNode4CurrentNode.forEach(node => this.getPreNodes(node.id, preNodes));
- }
-
- public isPreNode(preNode: WorkflowNode, id: string): boolean {
- const targetNode = preNode.sequenceFlows.find(connection => connection.targetRef === id);
- return targetNode !== undefined;
- }
-
- public getNodeById(sourceId: string): WorkflowNode {
- return this.getProcess().find(node => node.id === sourceId);
- }
-
- private createId() {
- const idSet = new Set();
- this.getProcess().forEach(node => idSet.add(node.id));
-
- for (let i = 0; i < idSet.size; i++) {
- if (!idSet.has('node' + i)) {
- return 'node' + i;
- }
- }
-
- return 'node' + idSet.size;
- }
-}