28e312afbaf6b4cd7ae37374409c15b2f3400777
[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 (item.status === 'Incomplete') {
68           const updateStatus = (prodata) => {
69             item.status = prodata.status || item.status;
70           };
71           
72           const obj = { serviceId: item.id };
73           this.queryStatus(obj, index, updateStatus).then(() => {
74             item.status = "Completed";
75             this.getCloudLeasedLineList();
76           });
77         } 
78         return item;
79       });
80     }, (err) => {
81       console.log(err);
82     });
83   }
84
85   queryStatus(obj: any, index: number, callback: any) {
86     return new Promise((res) => {
87                         const requery = () => {
88         const param = [obj.id];
89                                 this.myHttp.getInstanceStatus(param).subscribe((response) => {
90                                                 if (
91                                                         response.data.status && response.data.status === 'Incomplete') {
92                                                         callback(response.data);
93                                                         let progressSetTimeOut = setTimeout(() => {
94                                                                 requery();
95                                                         }, this.intervalTime);
96                                                         this.progressingTimer.push({
97                                                                 id: obj.id,
98                                                                 timer: progressSetTimeOut,
99                                                         });
100                                                 } else {
101                                                         this.progressingTimer.forEach((item) => {
102                                                                 if (item.serviceId === obj.serviceId) {
103                                                                         clearInterval(item.timer);
104                                                                 }
105                                                         });
106                                                         res(response.data);
107                                                 }
108                                         });
109                         };
110                         requery();
111                 });
112   }
113
114   // change page message
115   searchData(): void {
116     this.getCloudLeasedLineList();
117   }
118   
119   // dialog show
120         cloudLeasedLineShow(): void {
121           this.cloudLeasedLineShowFlag = true;
122         }
123   // dialog close
124         cloudLeasedLineClose(): void {
125     this.cloudLeasedLineShowFlag = false;
126     this.pageIndex = 1;
127     this.pageSize = 10;
128     this.getCloudLeasedLineList();
129   }
130   // smart dialog show
131         smartCloudLeasedLineShow(): void {
132           this.smartCloudLeasedLineShowFlag = true;
133         }
134   // smart dialog close
135         smartCloudLeasedLineClose(data): void {
136     this.smartCloudLeasedLineShowFlag = false;
137     if (data.cancel) {
138       return;
139     }
140
141     this.resolveResult = {
142       name: 'test',
143       instanceId: '123456',
144       accessPointOne: {
145         name: 'aaa',
146         bandwidth: '20'
147       },
148       cloudPointName: 'aaa',
149     };
150
151     this.cloudLeasedLineShowFlag = true;
152   }
153   // to monitor page
154   goMonitorService(): void {
155     this.router.navigateByUrl('/fcaps/monitor_service');
156   }
157
158   activeCloudLeasedLine(row): void {
159     this.myHttp.activeIntentInstance({
160       instanceId: row.instanceId
161     }).subscribe((data) => {
162       console.log(data);
163     }, (err) => {
164       console.log(err);
165     });
166   }
167
168   inactiveCloudLeasedLine(row): void {
169     this.myHttp.invalidIntentInstance({
170       instanceId: row.instanceId
171     }).subscribe((data) => {
172       console.log(data);
173     }, (err) => {
174       console.log(err);
175     });
176   }
177
178   deleteCloudLeasedLine(row): void {
179     this.myHttp.deleteIntentInstance(row.instanceId).subscribe((data) => {
180       console.log(data);
181     }, (err) => {
182       console.log(err);
183     });
184   }
185 }