48a4074f71469fe668f3ce74fcbe95202e804908
[sdc/sdc-workflow-designer.git] /
1 /**
2  * Copyright (c) 2017 ZTE Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     ZTE - initial API and implementation and/or initial documentation
11  */
12 import { Component, Input, OnInit } from '@angular/core';
13 import { ServiceTask } from '../../../model/workflow/service-task';
14 import { NodeTypeService } from '../../../services/node-type.service';
15 import { Parameter } from '../../../model/workflow/parameter';
16 import { ValueSource } from '../../../model/value-source.enum';
17
18 @Component({
19   selector: 'wfm-service-task',
20   templateUrl: './service-task.component.html',
21   styleUrls: ['./service-task.component.css']
22 })
23 export class ServiceTaskComponent implements OnInit {
24   @Input() public node: ServiceTask;
25   public canEdit = true;
26   public inputValueSource = [ValueSource.Variable];
27   public outputValueSource = [];
28   constructor(private nodeTypeService: NodeTypeService) { }
29
30   public ngOnInit() {
31     const nodeDataType = this.nodeTypeService.getNodeDataTypeById(this.node.typeId);
32     if (nodeDataType.content && nodeDataType.content.class && '' != nodeDataType.content.class) {
33       this.canEdit = false;
34     }
35     if (!this.node.className) {
36       this.node.className = '';
37       if (nodeDataType.content.class) {
38         this.node.className = nodeDataType.content.class;
39       }
40     }
41
42     let inputs = nodeDataType.content.inputs;
43     if (!this.node.inputs) {
44       // Set default value
45       this.node.inputs = [];
46       if (inputs) {
47         for (const key in inputs) {
48           if (inputs.hasOwnProperty(key)) {
49             const element = inputs[key];
50             this.node.inputs.push(new Parameter(key, element.default, ValueSource[ValueSource.string],
51               element.type, element.required, element.show));
52           }
53         }
54       }
55     } else {
56       // Load parameter value
57       // todo: 
58     }
59
60     let outputs = nodeDataType.content.outputs;
61     if (!this.node.outputs) {
62       // Set default value
63       this.node.outputs = [];
64       if (outputs) {
65         for (const key in outputs) {
66           if (outputs.hasOwnProperty(key)) {
67             const element = outputs[key];
68             this.node.outputs.push(new Parameter(key, element.default, ValueSource[ValueSource.string],
69               element.type, element.required));
70           }
71         }
72       }
73     } else {
74       // Load parameter value
75       // todo: 
76     }
77   }
78
79   public createInput(): void {
80     this.node.inputs.push(new Parameter('', '', ValueSource[ValueSource.string]));
81   }
82
83   public deleteInput(index: number): void {
84     this.node.inputs.splice(index, 1);
85   }
86   public createOutput(): void {
87     this.node.outputs.push(new Parameter('', '', ValueSource[ValueSource.string]));
88   }
89
90   public deleteOutput(index: number): void {
91     this.node.outputs.splice(index, 1);
92   }
93
94   private getParameters() {
95
96   }
97 }