2 * Copyright (c) 2017 ZTE Corporation.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * and the Apache License 2.0 which both accompany this distribution,
\r
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
\r
7 * and http://www.apache.org/licenses/LICENSE-2.0
\r
10 * ZTE - initial API and implementation and/or initial documentation
\r
13 import { Injectable } from '@angular/core';
\r
14 import { WorkflowNode } from "../model/workflow-node";
\r
15 import { DataAccessService } from "./data-access/data-access.service";
\r
16 import { Observable } from "rxjs/Observable";
\r
17 import { Workflow } from "../model/workflow";
\r
21 * provides all of the operations about workflow operations.
\r
24 export class WorkflowService {
\r
26 public workflow: Workflow;
\r
28 constructor(private dataAccessService: DataAccessService) {
\r
32 public save(): Observable<boolean> {
\r
33 return this.dataAccessService.catalogService.saveWorkflow(this.workflow);
\r
36 public addNode(name: string, type: string, top: number, left: number): WorkflowNode {
\r
37 const node = new WorkflowNode(this.createId(), name, type, top, left);
\r
38 this.workflow.nodes.push(node);
\r
42 public deleteNode(nodeId: string): WorkflowNode {
\r
43 // delete current node
\r
44 const index = this.workflow.nodes.findIndex(node => node.id === nodeId);
\r
46 const node = this.workflow.nodes.splice(index, 1)[0];
\r
53 public getNodeById(sourceId: string): WorkflowNode {
\r
54 return this.workflow.nodes.find(node => node.id === sourceId);
\r
57 private createId() {
\r
58 const idSet = new Set();
\r
59 this.workflow.nodes.forEach(node => idSet.add(node.id));
\r
61 for (let i = 0; i < idSet.size; i++) {
\r
62 if (!idSet.has('node' + i)) {
\r
67 return 'node' + idSet.size;
\r