0f0afc79b8edee605d309e7ad613382992dad935
[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         console.log(response);
55       },
56       (err) => {
57         console.log(err);
58       }
59     )
60   }
61
62   getInstanceId() {
63     this.myHttp.getInstanceId().subscribe(
64       (response) => {
65         const { code, message, data} = response;
66         if (code !== 200) {
67           this.nzMessage.error(message);
68           return;
69         }
70         this.cloud_leased_line_info.instanceId = data && data.instanceId;
71       },
72       (err) => {
73         console.log(err);
74       }
75     )
76   }
77
78   submit(): void {
79     this.myHttp.createIntentInstance({
80       ...this.cloud_leased_line_info
81     }).subscribe(
82       (data) => {
83         console.log(data);
84         this.cancel();
85       },
86       (err) => {
87         console.log(err);
88       }
89     )
90   }
91
92   cancel(): void {
93     this.cloudLeasedLineShowFlag = false
94     this.cloud_leased_line_info = {
95       name: '',
96       instanceId: '',
97       accessPointOne: {
98         name: '',
99         bandwidth: ''
100       },
101       cloudPointName: '',
102     };
103     this.cancelEmitter.emit();
104   }
105 }