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