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
10 * ZTE - initial API and implementation and/or initial documentation
13 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
14 import { TreeNode } from 'primeng/primeng';
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";
25 * property component presents information of a workflow node.
26 * the presented information can be edit in this component.
27 * it may load information dynamically. the content may be different for different node type.
30 selector: 'b4t-rest-task-parameters',
31 templateUrl: 'rest-task-parameters.component.html',
33 export class RestTaskParametersComponent implements OnInit {
34 @Input() public task: RestTask;
35 @Input() public planItems: PlanTreeviewItem[];
37 public inputSources: ValueSource[] = [ValueSource.String, ValueSource.Variable, ValueSource.Plan];
38 public requestParameters: RestParameter[] = []; // not include body parameter
39 public bodyParameter: TreeNode[] = [];
40 public responseParameter: TreeNode[] = [];
41 public valueSource = ValueSource;
45 constructor(private broadcastService: BroadcastService, private swaggerTreeConverterService: SwaggerTreeConverterService) {
49 this.broadcastService.nodeTaskChange$.subscribe(() => {
50 this.resetRequestParams();
51 this.resetResponseParams();
55 public resetRequestParams() {
56 this.requestParameters = [];
57 this.bodyParameter = [];
59 this.task.parameters.forEach(param => {
60 if (param.position === 'body') {
61 const requestTreeNode = this.swaggerTreeConverterService
62 .schema2TreeNode('Request Param', this.task.serviceName, this.task.serviceVersion, param.schema);
63 param.value = param.schema.value;
64 this.bodyParameter.push(requestTreeNode);
66 this.requestParameters.push(param);
71 public resetResponseParams() {
72 // TODO add response body handler