dd7949b42e80d1331a6f72afec22040b21471d8c
[usecase-ui.git] /
1 import { Component, OnInit } from "@angular/core";
2 import { Router } from "@angular/router";
3 import { NzMessageService } from "ng-zorro-antd";
4 import { intentBaseService } from "../../../../core/services/intentBase.service";
5
6 @Component({
7   selector: 'app-cloud-leased-line',
8   templateUrl: './cloud-leased-line.component.html',
9   styleUrls: ['./cloud-leased-line.component.less']
10 })
11 export class CloudLeasedLineComponent implements OnInit {
12
13   constructor(
14     private router:Router,
15     private myHttp: intentBaseService,
16     private nzMessage: NzMessageService 
17   ) {}
18
19         ngOnChanges() {}
20
21         ngOnInit() {
22     this.pageIndex = 1;
23     this.pageSize = 10;
24     this.getCloudLeasedLineList();
25   }
26
27         ngOnDestroy() {}
28
29   statusObj: any = {
30     0: 'Incomplete',
31     1: 'Completed',
32     2: 'Deleted',
33     3: 'Inactive'
34   }
35   // table lists
36         listOfData: any[] = [];
37   // pageSize or pageNum
38         pageIndex: number = 1;
39         pageSize: number = 10;
40         total: number = 0;
41         loading = false;
42   // cantrol dialog show or hidden
43   cloudLeasedLineShowFlag: boolean = false;
44   smartCloudLeasedLineShowFlag: boolean = false;
45   // resolve to dialog
46   resolveResult: any = null;
47   intervalTime: number = 5000;
48   progressingTimer: any[] = [];
49   
50   // init source data
51         getCloudLeasedLineList(): void {
52     this.myHttp.getInstanceList({
53       currentPage: this.pageIndex,
54       pageSize: this.pageSize
55     }).subscribe((response) => {
56       const { code, message, data } = response;
57       if (code !== 200) {
58         this.nzMessage.error(message);
59                                 return;
60       }
61       this.total = data.totalRecords;
62       if (data.list === 0) {
63         return;
64       }
65       
66       this.listOfData = data.list.map((item, index) => {
67         if (this.statusObj[item.status] === 'Incomplete') {
68           const updateStatus = (prodata) => {
69             item.status = prodata.status || item.status;
70           };
71           
72           const obj = { instanceId: item.instanceId };
73           this.queryStatus(obj, index, updateStatus).then(() => {
74             item.status = '1';
75           });
76         }
77         return item;
78       });
79     }, (err) => {
80       console.log(err);
81     });
82   }
83
84   queryStatus(obj: any, index: number, callback: any) {
85     return new Promise((res) => {
86                         const requery = () => {
87         const param = {
88           ids: [obj.instanceId]
89         };
90                                 this.myHttp.getInstanceStatus(param).subscribe((response) => {
91           const { code, data:{ IntentInstances } } = response;
92           if (code !== 200 || !IntentInstances || IntentInstances.length === 0) {
93             return;
94           }
95           const intentInstance = IntentInstances[0];
96           if (this.statusObj[intentInstance.status] === 'Incomplete') {
97             callback(intentInstance);
98             let progressSetTimeOut = setTimeout(() => {
99               requery();
100             }, this.intervalTime);
101             this.progressingTimer.push({
102               instanceId: obj.instanceId,
103               timer: progressSetTimeOut,
104             });
105           } else {
106             this.progressingTimer.forEach((item) => {
107               if (item.instanceId === obj.instanceId) {
108                 clearInterval(item.timer);
109               }
110             });
111             res(intentInstance);
112           }
113                                 });
114                         };
115                         requery();
116                 });
117   }
118
119   // change page message
120   searchData(): void {
121     this.getCloudLeasedLineList();
122   }
123   
124   // dialog show
125         cloudLeasedLineShow(): void {
126           this.cloudLeasedLineShowFlag = true;
127         }
128   // dialog close
129         cloudLeasedLineClose(): void {
130     this.cloudLeasedLineShowFlag = false;
131     this.pageIndex = 1;
132     this.pageSize = 10;
133     this.getCloudLeasedLineList();
134   }
135   // smart dialog show
136         smartCloudLeasedLineShow(): void {
137           this.smartCloudLeasedLineShowFlag = true;
138         }
139   // smart dialog close
140         smartCloudLeasedLineClose(data): void {
141     this.smartCloudLeasedLineShowFlag = false;
142     if (data.cancel) {
143       return;
144     }
145
146     this.resolveResult = {
147       name: 'test',
148       instanceId: '123456',
149       accessPointOne: {
150         name: 'aaa',
151         bandwidth: '20'
152       },
153       cloudPointName: 'aaa',
154     };
155
156     this.cloudLeasedLineShowFlag = true;
157   }
158   // to monitor page
159   goMonitorService(): void {
160     this.router.navigateByUrl('/fcaps/monitor_service');
161   }
162
163   activeCloudLeasedLine(row): void {
164     this.myHttp.activeIntentInstance({
165       instanceId: row.instanceId
166     }).subscribe((data) => {
167       const { code, message } = data;
168       if (code !== 200) {
169         this.nzMessage.error(message);
170         return;
171       }
172       this.getCloudLeasedLineList();
173     }, (err) => {
174       console.log(err);
175     });
176   }
177
178   inactiveCloudLeasedLine(row): void {
179     this.myHttp.invalidIntentInstance({
180       instanceId: row.instanceId
181     }).subscribe((data) => {
182       const { code, message } = data;
183       if (code !== 200) {
184         this.nzMessage.error(message);
185         return;
186       }
187       this.getCloudLeasedLineList();
188     }, (err) => {
189       console.log(err);
190     });
191   }
192
193   deleteCloudLeasedLine(row): void {
194     this.myHttp.deleteIntentInstance(row.instanceId).subscribe((data) => {
195       const { code, message } = data;
196       if (code !== 200) {
197         this.nzMessage.error(message);
198         return;
199       }
200       this.getCloudLeasedLineList();
201     }, (err) => {
202       console.log(err);
203     });
204   }
205 }