e4d43d8cb740b1c7f541dea1a5f3747ef6a15dd7
[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, Input, OnChanges } from '@angular/core';
14 import { ModalDirective } from 'ngx-bootstrap/modal';
15
16 import { Swagger } from '../../../../model/swagger';
17 import { RestConfig } from '../../../../model/rest-config';
18 import { RestService } from '../../../../services/rest.service';
19
20 /**
21  * toolbar component contains some basic operations(save) and all of the supported workflow nodes.
22  * The supported nodes can be dragged to container component. which will add a new node to the workflow.
23  */
24 @Component({
25     selector: 'wfm-rest-config-detail',
26     templateUrl: 'rest-config-detail.component.html',
27 })
28 export class RestConfigDetailComponent implements OnChanges {
29     @Input() restConfig: RestConfig;
30
31     public detail: string;
32
33     constructor(private restService: RestService) {
34     }
35
36     public ngOnChanges() {
37         if (this.restConfig == null) {
38             this.restConfig = new RestConfig('', '', '', '');
39         }
40         this.parseSwagger2String();
41     }
42
43     private parseSwagger2String() {
44         if (this.restConfig.swagger) {
45             this.detail = JSON.stringify(this.restConfig.swagger);
46         } else {
47             this.detail = '';
48         }
49     }
50
51     public onDetailChanged(detail: string) {
52         this.detail = detail;
53
54         let swagger: Swagger = null;
55         try {
56             swagger = new Swagger(JSON.parse(detail));
57             console.log(swagger);
58         } catch (e) {
59             console.log('detail transfer error');
60             console.error(e);
61         }
62         this.restConfig.swagger = swagger;
63     }
64
65     public toggleDynamic(dynamic: boolean) {
66         // this.restConfig.dynamic = dynamic;
67
68         // if (this.restConfig.dynamic && this.restConfig.definition) {
69         //     this.restService.getDynamicSwaggerInfo(this.restConfig.definition)
70         //         .subscribe(response => {
71         //             try {
72         //                 this.restConfig.swagger = new Swagger(response);
73         //                 this.parseSwagger2String();
74         //             } catch (e) {
75         //                 console.log('detail transfer error');
76         //                 console.error(e);
77         //             }
78
79         //         });
80         // }
81     }
82
83 }