fc07efc96ab4dc9c720f438db8cc72bda3001795
[usecase-ui.git] /
1 import { Component, OnInit, ViewChild } from '@angular/core';
2 import { SlicingTaskServices } from '.././../../../../../core/services/slicingTaskServices';
3 import { BUSINESS_STATUS } from '../../../../../../../constants/constants';
4 import { NzModalService, NzMessageService } from 'ng-zorro-antd';
5 import { SlicingBusinessModelComponent } from '../slicing-business-model/slicing-business-model.component';
6 @Component({
7     selector: 'app-slicing-business-table',
8     templateUrl: './slicing-business-table.component.html',
9     styleUrls: ['./slicing-business-table.component.less']
10 })
11 export class SlicingBusinessTableComponent implements OnInit {
12
13     constructor(
14         private myhttp: SlicingTaskServices,
15         private modalService: NzModalService,
16         private message: NzMessageService
17     ) {
18     }
19
20     ngOnInit() {
21         this.getBusinessList()
22     }
23     ngOnDestroy() {
24         this.progressingTimer.forEach((item) => {
25             clearInterval(item.timer);
26         })
27         this.progressingTimer = [];
28     }
29     selectedValue: string = BUSINESS_STATUS[0];
30     listOfData: any[] = [];
31     pageIndex: number = 1;
32     pageSize: number = 10;
33     total: number = 0;
34     loading = false;
35     isSelect: boolean = false;
36     statusOptions: any[] = BUSINESS_STATUS;
37     progressingTimer: any[] = [];
38     terminateStart: any[] = [];
39     @ViewChild('notification') notification1: any;
40
41     getBusinessList(): void {
42         this.loading = true;
43         this.isSelect = false;
44         this.listOfData = [];
45         let paramsObj = {
46             pageNo: this.pageIndex,
47             pageSize: this.pageSize
48         };
49         if (this.selectedValue !== BUSINESS_STATUS[0]) {
50             paramsObj["businessStatus"] = this.selectedValue.toLocaleLowerCase();
51             this.isSelect = true;
52         }
53         this.myhttp.getSlicingBusinessList(paramsObj, this.isSelect).subscribe(res => {
54             const { result_header: { result_code }, result_body: { slicing_business_list, record_number } } = res;
55             this.loading = false;
56             if (+result_code === 200) {
57                 this.total = record_number;
58                 if(slicing_business_list !==null && slicing_business_list.length >0){
59                     this.listOfData = slicing_business_list.map((item, index) => {
60                         if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
61                             let updata = (prodata: { operation_progress: string }) => {
62                                 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
63                             };
64                             let obj = {
65                                 serviceId: item.service_instance_id
66                             };
67                             if (item.last_operation_type === 'DELETE') this.terminateStart[index] = true
68                             else this.terminateStart[index] = false;
69                             this.queryProgress(obj, item.orchestration_status, index, updata).then((res) => {
70                                 item.last_operation_progress = '100';
71                                 this.getBusinessList();
72                             })
73                         }
74                         return item
75                     });
76                 }
77             }
78         })
79     }
80     getListOfProcessingStatus() {
81         this.pageIndex = 1;
82         this.pageSize = 10;
83         this.progressingTimer.forEach((item) => {
84             clearInterval(item.timer);
85         });
86         this.progressingTimer = [];
87         this.getBusinessList();
88     }
89     searchData(reset: boolean = false) {
90         this.progressingTimer.forEach((item) => {
91             clearInterval(item.timer);
92         });
93         this.progressingTimer = [];
94         this.getBusinessList();
95     }
96     switchChange(slicing, i) {
97         this.modalService.confirm({
98             nzTitle: '<i>Do you Want to ' + (slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate') + ' slicing business?</i>',
99             nzContent: '<b>Name:' + slicing.service_instance_name + '</b>',
100             nzOnOk: () => {
101                 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate', slicing.service_instance_id);
102                 let paramsObj = {
103                     serviceId: slicing.service_instance_id
104                 };
105                 if (slicing.orchestration_status === 'activated') {
106                     this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
107                 } else {
108                     this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
109                 }
110             },
111             nzCancelText: 'No',
112             nzOnCancel: () => {
113                 let singleSlicing = Object.assign({}, this.listOfData[i]);
114                 this.listOfData[i] = singleSlicing;
115                 this.listOfData = [...this.listOfData];
116             }
117         });
118     }
119     changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
120         this.loading = true;
121         this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
122             const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
123             this.loading = false;
124             if (+result_code === 200) {
125                 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
126                 this.getBusinessList();
127             } else {
128                 let singleSlicing = Object.assign({}, this.listOfData[index]);
129                 this.listOfData[index] = singleSlicing;
130                 this.listOfData = [...this.listOfData];
131                 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
132                 this.getBusinessList();
133             }
134             this.getBusinessList();
135         }, () => {
136             this.loading = false;
137             let singleSlicing = Object.assign({}, this.listOfData[index]);
138             this.listOfData[index] = singleSlicing;
139             this.listOfData = [...this.listOfData];
140             this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
141             this.getBusinessList();
142         })
143     }
144     terminate(slicing,index) {
145         this.modalService.confirm({
146             nzTitle: 'Do you Want to terminate slicing business?',
147             nzContent: '<b>Name:&nbsp;</b>' + slicing.service_instance_name,
148             nzOnOk: () => {
149                 this.notification1.notificationStart('slicing business', 'terminate', slicing.service_instance_id);
150                 let paramsObj = { serviceId: slicing.service_instance_id };
151                 this.terminateStart[index] = true;
152                 this.loading = true;
153                 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
154                     const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
155                     this.loading = false;
156                     if (+result_code === 200) {
157                         this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id);
158                         this.getBusinessList();
159                     } else {
160                         this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
161                         this.terminateStart[index] = false;
162                     }
163                 }, () => {
164                     this.loading = false;
165                     this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
166                     this.terminateStart[index] = false;
167                 })
168             },
169             nzCancelText: 'No',
170             nzOnCancel: () => {
171                 console.info('Cancel termination')
172             }
173         });
174     }
175     showdetail(data) {
176         const BusinessModal = this.modalService.create({
177             nzTitle: "Detail",
178             nzContent: SlicingBusinessModelComponent,
179             nzWidth: "70%",
180             nzOkText: null,
181             nzCancelText: null,
182             nzComponentParams: {
183                 businessId: data.service_instance_id
184             }
185         })
186     }
187     queryProgress(obj, action, index, callback) {
188         return new Promise(res => {
189             let requery = () => {
190                 this.myhttp.getSlicingBusinessProgress(obj)
191                     .subscribe((data) => {
192                         const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
193                         if (+result_code === 200) {
194                             if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
195                                 callback(data.result_body);
196                                 let progressSetTimeOut = setTimeout(() => {
197                                     requery();
198                                 }, 5000);
199                                 this.progressingTimer.push({
200                                     id: obj.serviceId,
201                                     timer: progressSetTimeOut
202                                 })
203                             } else {
204                                 this.progressingTimer.forEach((item) => {
205                                     if (item.serviceId === obj.serviceId) {
206                                         clearInterval(item.timer);
207                                     }
208                                 });
209                                 res(data.result_body);
210                             }
211                         } else {
212                             this.progressingTimer.forEach((item) => {
213                                 if (item.serviceId === obj.serviceId) {
214                                     clearInterval(item.timer);
215                                 }
216                             });
217                             this.getBusinessList();
218                             this.message.error(result_message);
219                         }
220                     }, (err) => {
221                         this.progressingTimer.forEach((item) => {
222                             if (item.serviceId === obj.serviceId) {
223                                 clearInterval(item.timer);
224                             }
225                         });
226                         this.getBusinessList();
227                         this.message.error(err);
228                     })
229             };
230             requery();
231         })
232     }
233 }