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