7f8bbf43e183e4fafc979613d697bef6f6ee85c2
[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
13 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
14 import { TreeNode } from 'primeng/primeng';
15
16 import { Swagger } from '../../../../model/swagger';
17 import { RestTask } from '../../../../model/workflow/rest-task';
18 import { BroadcastService } from '../../../../services/broadcast.service';
19 import { RestParameter } from "../../../../model/workflow/rest-parameter";
20 import { ValueSource } from "../../../../model/value-source.enum";
21 import { SwaggerTreeConverterService } from "../../../../services/swagger-tree-converter.service";
22 import { PlanTreeviewItem } from "../../../../model/plan-treeview-item";
23 import { WorkflowConfigService } from "../../../../services/workflow-config.service";
24
25 /**
26  * property component presents information of a workflow node.
27  * the presented information can be edit in this component.
28  * it may load information dynamically. the content may be different for different node type.
29  */
30 @Component({
31     selector: 'b4t-rest-task-parameters',
32     templateUrl: 'rest-task-parameters.component.html',
33 })
34 export class RestTaskParametersComponent implements OnInit {
35     @Input() public task: RestTask;
36     @Input() public planItems: PlanTreeviewItem[];
37
38     public inputSources: ValueSource[] = [ValueSource.String, ValueSource.Variable, ValueSource.Plan];
39     public requestParameters: RestParameter[] = []; // not include body parameter
40     public bodyParameter: TreeNode[] = [];
41     public responseParameter: TreeNode[] = [];
42     public valueSource = ValueSource;
43
44     private index = 1;
45
46     constructor(private broadcastService: BroadcastService,
47         private workflowConfigService: WorkflowConfigService,
48         private swaggerTreeConverterService: SwaggerTreeConverterService) {
49     }
50
51     public ngOnInit() {
52         this.broadcastService.nodeTaskChange$.subscribe(() => {
53             this.resetRequestParams();
54             this.resetResponseParams();
55         });
56     }
57
58     public resetRequestParams() {
59         this.requestParameters = [];
60         this.bodyParameter = [];
61
62         this.task.parameters.forEach(param => {
63             if (param.position === 'body') {
64                 const requestTreeNode = this.swaggerTreeConverterService
65                     .schema2TreeNode(this.workflowConfigService.getSwaggerInfo(this.task.serviceName, this.task.serviceVersion), 'Request Param', param.schema, param.value);
66                 param.value = requestTreeNode.value;
67                 param.value = param.schema.value;
68                 this.bodyParameter.push(requestTreeNode);
69             } else {
70                 this.requestParameters.push(param);
71             }
72         });
73     }
74
75     public resetResponseParams() {
76         // TODO add response body handler
77     }
78 }