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