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