90bcf9b078ed0272700fa0d2cd3cad5520ef9d49
[usecase-ui.git] /
1 import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
2 import { NzMessageService } from "ng-zorro-antd";
3 import { intentBaseService } from "../../../../core/services/intentBase.service";
4 import { Util } from "../../../../shared/utils/utils";
5 import { COMMUNICATION_FORM_ITEMS } from "../constants";
6
7 @Component({
8   selector: 'app-cloud-leased-line-modal',
9   templateUrl: './cloud-leased-line-modal.component.html',
10   styleUrls: ['./cloud-leased-line-modal.component.less']
11 })
12 export class CloudLeasedLineModalComponent implements OnInit {
13
14   constructor(
15     private myHttp: intentBaseService,
16                 private nzMessage: NzMessageService,
17                 private Util: Util
18         ) {}
19
20   @Input() modelParams: any;
21   @Input() cloudLeasedLineShowFlag: boolean;
22   @Output() cancelEmitter = new EventEmitter<boolean>();
23   comunicationFormItems = COMMUNICATION_FORM_ITEMS;
24   validateRulesShow: any[] = [];
25   isLoadingOne = false;
26   nodeLists: any[] = [];
27   cloudPointOptions: any[] = [];
28   cloud_leased_line_info = {
29                 name: '',
30                 instanceId: '',
31                 accessPointOne: {
32       name: '',
33       bandwidth: ''
34     },
35                 cloudPointName: '',
36         };
37
38   ngOnInit(): void {}
39   
40   ngOnChanges() {
41     if (this.cloudLeasedLineShowFlag) {
42       if (this.modelParams) {
43         this.cloud_leased_line_info = { ...this.modelParams };
44       } else {
45         this.getInstanceId();
46       }
47       this.queryAccessNodeInfo();
48     }
49         }
50   
51   queryAccessNodeInfo() {
52     this.myHttp.queryAccessNodeInfo().subscribe(
53       (response) => {
54         const { code, data } = response;
55         if (code !== 200) {
56           return;
57         }
58         this.cloudPointOptions = [...data.cloudAccessNodeList];
59         this.nodeLists = [...data.accessNodeList];
60       },
61       (err) => {
62         console.log(err);
63       }
64     )
65   }
66
67   getInstanceId() {
68     this.myHttp.getInstanceId().subscribe(
69       (response) => {
70         const { code, message, data} = response;
71         if (code !== 200) {
72           this.nzMessage.error(message);
73           return;
74         }
75         this.cloud_leased_line_info.instanceId = data && data.instanceId;
76       },
77       (err) => {
78         console.log(err);
79       }
80     )
81   }
82
83   submit(): void {
84     this.myHttp.createIntentInstance({
85       ...this.cloud_leased_line_info
86     }).subscribe(
87       (data) => {
88         console.log(data);
89         this.cancel();
90       },
91       (err) => {
92         console.log(err);
93       }
94     )
95   }
96
97   cancel(): void {
98     this.cloudLeasedLineShowFlag = false
99     this.cloud_leased_line_info = {
100       name: '',
101       instanceId: '',
102       accessPointOne: {
103         name: '',
104         bandwidth: ''
105       },
106       cloudPointName: '',
107     };
108     this.cancelEmitter.emit();
109   }
110 }