e1b37054a1ceb1f26f54856540d4d0f24af24b07
[usecase-ui.git] /
1 import {Component, OnInit} from '@angular/core';
2 import {BUSINESS_STATUS} from "../../../../../constants/constants";
3 import {SlicingTaskServices} from '.././../../../core/services/slicingTaskServices';
4 import { NzModalService, NzMessageService } from 'ng-zorro-antd';
5 @Component({
6     selector: 'app-csmf-slicing-business-management',
7     templateUrl: './csmf-slicing-business-management.component.html',
8     styleUrls: ['./csmf-slicing-business-management.component.less']
9 })
10 export class CsmfSlicingBusinessManagementComponent implements OnInit {
11
12     constructor(
13         private myhttp: SlicingTaskServices,
14         private modalService: NzModalService,
15         private message: NzMessageService
16     ) {
17     }
18
19     ngOnInit() {
20         this.getCSMFBusinessList()
21     }
22     ngOnDestroy() {
23         this.progressingTimer.forEach((item) => {
24             clearInterval(item.timer);
25         });
26         this.progressingTimer = [];
27     }
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     statusOptions: any[] = BUSINESS_STATUS;
36     progressingTimer: any[] = [];
37     terminateStart: boolean = false;
38
39     getCSMFBusinessList() {
40         this.loading = true;
41         this.listOfData = [];
42         let paramsObj = {
43             status: this.selectedValue,
44             pageNo: this.pageIndex,
45             pageSize: this.pageSize
46         };
47         this.myhttp.getCSMFSlicingBusinessList(paramsObj).subscribe(res => {
48             const {result_header: {result_code}, result_body: {slicing_service_list, record_number}} = res;
49             this.loading = false;
50             if (+result_code === 200) {
51                 this.total = record_number;
52                 if (slicing_service_list !== null && slicing_service_list.length > 0) {
53                     this.listOfData = slicing_service_list.map((item, index) => {
54                         if (item.last_operation_process && item.last_operation_type && Number(item.last_operation_process) < 100) {
55                             let updata = (prodata: { operation_progress: string }) => {
56                                 item.last_operation_process = prodata.operation_progress || item.last_operation_process;
57                             };
58                             let obj = {
59                                 serviceId: item.service_instance_id
60                             };
61                             if (item.last_operation_type === 'DELETE') this.terminateStart = true;
62                             this.queryProgress(obj, index, updata).then((res) => {
63                                 item.last_operation_process = '100';
64                                 this.getCSMFBusinessList();
65                             })
66                         }
67                         return item
68                     });
69                 }
70             }
71         })
72     }
73
74     getListOfProcessingStatus() {
75         this.pageIndex = 1;
76         this.pageSize = 10;
77         this.progressingTimer.forEach((item) => {
78             clearInterval(item.timer);
79         });
80         this.progressingTimer = [];
81         this.getCSMFBusinessList();
82     }
83
84     searchData(reset: boolean = false) {
85         this.progressingTimer.forEach((item) => {
86             clearInterval(item.timer);
87         });
88         this.progressingTimer = [];
89         this.getCSMFBusinessList();
90     }
91
92     switchChange(slicing, i) {
93         console.log(slicing, i, "slicing");
94         this.modalService.confirm({
95             nzTitle: '<i>Are you sure you want to perform this task?</i>',
96             nzContent: '<b>Name:' + slicing.service_name + '</b>',
97             nzOnOk: () => {
98                 let paramsObj = {
99                     serviceId: slicing.service_id
100                 };
101                 if (slicing.service_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.csmfChangeActivate(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.getCSMFBusinessList();
122             } else {
123                 let singleSlicing = Object.assign({}, this.listOfData[index]);
124                 this.listOfData[index] = singleSlicing;
125                 this.listOfData = [...this.listOfData];
126                 this.getCSMFBusinessList();
127             }
128             this.getCSMFBusinessList();
129         }, () => {
130             this.loading = false;
131             let singleSlicing = Object.assign({}, this.listOfData[index]);
132             this.listOfData[index] = singleSlicing;
133             this.listOfData = [...this.listOfData];
134             this.getCSMFBusinessList();
135         })
136     }
137
138     terminate(slicing) {
139         console.log(slicing, "slicing");
140         this.modalService.confirm({
141             nzTitle: 'Are you sure you want to terminate this task?',
142             nzContent: '<b>Name:&nbsp;</b>' + slicing.service_name,
143             nzOnOk: () => {
144                 let paramsObj = { serviceId: slicing.service_id };
145                 this.terminateStart = true;
146                 this.loading = true;
147                 this.myhttp.csmfTerminate(paramsObj).subscribe(res => {
148                     const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
149                     this.loading = false;
150                     if (+result_code === 200) {
151                         this.getCSMFBusinessList();
152                     } else {
153                         this.terminateStart = false;
154                     }
155                 }, () => {
156                     this.loading = false;
157                     this.terminateStart = false;
158                 })
159             },
160             nzCancelText: 'No',
161             nzOnCancel: () => {
162                 console.info('Cancel termination')
163             }
164         });
165     }
166     queryProgress(obj, index, callback) {
167         return new Promise(res => {
168             let requery = () => {
169                 this.myhttp.csmfSlicingProgress(obj)
170                     .subscribe((data) => {
171                         const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
172                         if (+result_code === 200) {
173                             if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
174                                 callback(data.result_body);
175                                 let progressSetTimeOut = setTimeout(() => {
176                                     requery();
177                                 }, 5000);
178                                 this.progressingTimer.push({
179                                     id: obj.serviceId,
180                                     timer: progressSetTimeOut
181                                 })
182                             } else {
183                                 this.progressingTimer.forEach((item) => {
184                                     if (item.serviceId === obj.serviceId) {
185                                         clearInterval(item.timer);
186                                     }
187                                 });
188                                 res(data.result_body);
189                             }
190                         } else {
191                             this.progressingTimer.forEach((item) => {
192                                 if (item.serviceId === obj.serviceId) {
193                                     clearInterval(item.timer);
194                                 }
195                             });
196                             this.getCSMFBusinessList();
197                             this.message.error(result_message);
198                         }
199                     }, (err) => {
200                         this.progressingTimer.forEach((item) => {
201                             if (item.serviceId === obj.serviceId) {
202                                 clearInterval(item.timer);
203                             }
204                         });
205                         this.getCSMFBusinessList();
206                         this.message.error(err);
207                     })
208             };
209             requery();
210         })
211     }
212 }