23b8360be3532c078652f78352f20007c7f11571
[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: boolean = false;
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;
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 = true;
68                             this.queryProgress(obj, item.orchestration_status, index, updata).then((res) => {
69                                 item.last_operation_progress = '100';
70                                 this.getBusinessList();
71                             })
72                         }
73                         return item
74                     });
75                 }
76             }
77         })
78     }
79     getListOfProcessingStatus() {
80         this.pageIndex = 1;
81         this.pageSize = 10;
82         this.progressingTimer.forEach((item) => {
83             clearInterval(item.timer);
84         });
85         this.progressingTimer = [];
86         this.getBusinessList();
87     }
88     searchData(reset: boolean = false) {
89         this.progressingTimer.forEach((item) => {
90             clearInterval(item.timer);
91         });
92         this.progressingTimer = [];
93         this.getBusinessList();
94     }
95     switchChange(slicing, i) {
96         this.modalService.confirm({
97             nzTitle: '<i>Do you Want to ' + (slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate') + ' slicing business?</i>',
98             nzContent: '<b>Name:' + slicing.service_instance_name + '</b>',
99             nzOnOk: () => {
100                 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate', slicing.service_instance_id);
101                 let paramsObj = {
102                     serviceId: slicing.service_instance_id
103                 };
104                 if (slicing.orchestration_status === 'activated') {
105                     this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
106                 } else {
107                     this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
108                 }
109             },
110             nzCancelText: 'No',
111             nzOnCancel: () => {
112                 let singleSlicing = Object.assign({}, this.listOfData[i]);
113                 this.listOfData[i] = singleSlicing;
114                 this.listOfData = [...this.listOfData];
115             }
116         });
117     }
118     changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
119         this.loading = true;
120         this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
121             const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
122             this.loading = false;
123             if (+result_code === 200) {
124                 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
125                 this.getBusinessList();
126             } else {
127                 let singleSlicing = Object.assign({}, this.listOfData[index]);
128                 this.listOfData[index] = singleSlicing;
129                 this.listOfData = [...this.listOfData];
130                 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
131                 this.getBusinessList();
132             }
133             this.getBusinessList();
134         }, () => {
135             this.loading = false;
136             let singleSlicing = Object.assign({}, this.listOfData[index]);
137             this.listOfData[index] = singleSlicing;
138             this.listOfData = [...this.listOfData];
139             this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
140             this.getBusinessList();
141         })
142     }
143     terminate(slicing) {
144         this.modalService.confirm({
145             nzTitle: 'Do you Want to terminate slicing business?',
146             nzContent: '<b>Name:&nbsp;</b>' + slicing.service_instance_name,
147             nzOnOk: () => {
148                 this.notification1.notificationStart('slicing business', 'terminate', slicing.service_instance_id);
149                 let paramsObj = { serviceId: slicing.service_instance_id };
150                 this.terminateStart = true;
151                 this.loading = true;
152                 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
153                     const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
154                     this.loading = false;
155                     if (+result_code === 200) {
156                         this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id);
157                         this.getBusinessList();
158                     } else {
159                         this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
160                         this.terminateStart = false;
161                     }
162                 }, () => {
163                     this.loading = false;
164                     this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
165                     this.terminateStart = false;
166                 })
167             },
168             nzCancelText: 'No',
169             nzOnCancel: () => {
170                 console.info('Cancel termination')
171             }
172         });
173     }
174     showdetail(data) {
175         const BusinessModal = this.modalService.create({
176             nzTitle: "Detail",
177             nzContent: SlicingBusinessModelComponent,
178             nzWidth: "70%",
179             nzOkText: null,
180             nzCancelText: null,
181             nzComponentParams: {
182                 businessId: data.service_instance_id
183             }
184         })
185     }
186     queryProgress(obj, action, index, callback) {
187         return new Promise(res => {
188             let requery = () => {
189                 this.myhttp.getSlicingBusinessProgress(obj)
190                     .subscribe((data) => {
191                         const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
192                         if (+result_code === 200) {
193                             if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
194                                 callback(data.result_body);
195                                 let progressSetTimeOut = setTimeout(() => {
196                                     requery();
197                                 }, 5000);
198                                 this.progressingTimer.push({
199                                     id: obj.serviceId,
200                                     timer: progressSetTimeOut
201                                 })
202                             } else {
203                                 this.progressingTimer.forEach((item) => {
204                                     if (item.serviceId === obj.serviceId) {
205                                         clearInterval(item.timer);
206                                     }
207                                 });
208                                 res(data.result_body);
209                             }
210                         } else {
211                             this.progressingTimer.forEach((item) => {
212                                 if (item.serviceId === obj.serviceId) {
213                                     clearInterval(item.timer);
214                                 }
215                             });
216                             this.getBusinessList();
217                             this.message.error(result_message);
218                         }
219                     }, (err) => {
220                         this.progressingTimer.forEach((item) => {
221                             if (item.serviceId === obj.serviceId) {
222                                 clearInterval(item.timer);
223                             }
224                         });
225                         this.getBusinessList();
226                         this.message.error(err);
227                     })
228             };
229             requery();
230         })
231     }
232 }