a448bcf2534bf00c35886b278680dd9ad79a8e99
[usecase-ui.git] /
1 import {Component, Input, OnInit, SimpleChanges} 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 import * as moment from 'moment';
6 @Component({
7     selector: 'app-csmf-slicing-business-management',
8     templateUrl: './csmf-slicing-business-management.component.html',
9     styleUrls: ['./csmf-slicing-business-management.component.less']
10 })
11 export class CsmfSlicingBusinessManagementComponent implements OnInit {
12
13     constructor(
14         private myhttp: SlicingTaskServices,
15         private modalService: NzModalService,
16         private message: NzMessageService
17     ) {
18     }
19     @Input() currentTabTitle;
20
21     ngOnChanges(changes: SimpleChanges) {
22         if(changes.currentTabTitle.currentValue === 'Communication Service'){
23             this.getCSMFBusinessList()
24         }else {
25             this.progressingTimer.forEach((item) => {
26                 clearInterval(item.timer);
27             });
28             this.progressingTimer = [];
29         }
30     }
31
32     ngOnInit() {}
33
34     ngOnDestroy() {
35         console.log(this.progressingTimer)
36         this.progressingTimer.forEach((item) => {
37             clearInterval(item.timer)
38         })
39     }
40
41     selectedValue: string = BUSINESS_STATUS[0];
42     listOfData: any[] = [];
43     pageIndex: number = 1;
44     pageSize: number = 10;
45     total: number = 0;
46     loading = false;
47     statusOptions: any[] = BUSINESS_STATUS;
48     progressingTimer: any[] = [];
49     terminateStart: any[] = [];
50     businessOrderShow: boolean = false;
51     getCSMFBusinessList(): void {
52         this.loading = true;
53         this.listOfData = [];
54         let paramsObj = {
55             status: this.selectedValue.toLocaleLowerCase(),
56             pageNo: this.pageIndex,
57             pageSize: this.pageSize
58         };
59         let getCSMFSlicingBusinessListFailedCallback  = () => {
60             this.loading = false;
61         }
62         this.myhttp.getCSMFSlicingBusinessList(paramsObj, getCSMFSlicingBusinessListFailedCallback).then(res => {
63             const { result_body: { slicing_order_list, record_number } } = res;
64             this.loading = false;
65             this.total = record_number;
66             if (slicing_order_list !== null && slicing_order_list.length > 0) {
67                 this.listOfData = slicing_order_list.map((item, index) => {
68                     item.order_creation_time = moment(Number(item.order_creation_time)).format('YYYY-MM-DD HH:mm:ss');
69                     if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
70                         let updata = (prodata: { operation_progress: string }) => {
71                             item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
72                         };
73                         let obj = {
74                             serviceId: item.order_id
75                         };
76                         if (item.last_operation_type.toUpperCase() === 'DELETE') this.terminateStart[index] = true
77                         else this.terminateStart[index] = false;
78                         this.queryProgress(obj, index, updata).then(() => {
79                             item.last_operation_progress = '100';
80                             this.getCSMFBusinessList();
81                         })
82                     }
83                     return item
84                 });
85             }
86         })
87     }
88
89     getListOfProcessingStatus(): void {
90         this.pageIndex = 1;
91         this.pageSize = 10;
92         this.progressingTimer.forEach((item) => {
93             clearInterval(item.timer);
94         });
95         this.progressingTimer = [];
96         this.getCSMFBusinessList();
97     }
98
99     searchData(): void {
100         this.progressingTimer.forEach((item) => {
101             clearInterval(item.timer);
102         });
103         this.progressingTimer = [];
104         this.getCSMFBusinessList();
105     }
106
107     switchChange(slicing:any, i:number): void {
108         this.modalService.confirm({
109             nzTitle: '<i>Are you sure you want to perform this task?</i>',
110             nzContent: '<b>Name:' + slicing.order_name + '</b>',
111             nzOnOk: () => {
112                 let paramsObj = {
113                     serviceId: slicing.order_id
114                 };
115                 if (slicing.order_status === 'activated') {
116                     this.changeActivate(paramsObj, false, i)
117                 } else {
118                     this.changeActivate(paramsObj, true, i);
119                 }
120             },
121             nzCancelText: 'No',
122             nzOnCancel: () => {
123                 let singleSlicing = Object.assign({}, this.listOfData[i]);
124                 this.listOfData[i] = singleSlicing;
125                 this.listOfData = [...this.listOfData];
126             }
127         });
128     }
129     changeActivate(paramsObj: any, isActivate: boolean, index: number): void {
130         this.loading = true;
131         let changeActivateFailedCallback = () => {
132             this.loading = false;
133             let singleSlicing = Object.assign({}, this.listOfData[index]);
134             this.listOfData[index] = singleSlicing;
135             this.listOfData = [...this.listOfData];
136             this.getCSMFBusinessList();
137         }
138         this.myhttp.changeActivateSlicingService(paramsObj, isActivate, changeActivateFailedCallback).then((res) => {
139             this.loading = false;
140             this.getCSMFBusinessList();
141         })
142     }
143
144     terminate(slicing: any, index: number): void {
145         this.modalService.confirm({
146             nzTitle: 'Are you sure you want to terminate this task?',
147             nzContent: '<b>Name:&nbsp;</b>' + slicing.order_name,
148             nzOnOk: () => {
149                 let paramsObj = { serviceId: slicing.order_id };
150                 this.terminateStart[index] = true;
151                 this.loading = true;
152                 let terminateFailedCallback  = () => {
153                     this.loading = false;
154                     this.terminateStart[index] = false;
155                 }
156                 this.myhttp.terminateSlicingService(paramsObj, terminateFailedCallback).then(res => {
157                     this.loading = false;
158                     this.getCSMFBusinessList();
159                 })
160             },
161             nzCancelText: 'No',
162             nzOnCancel: () => {
163                 console.info('Cancel termination')
164             }
165         });
166     }
167     queryProgress(obj:any, index:number, callback:any) {
168         return new Promise(res => {
169             let requery = () => {
170                 let queryProgressFailedCallback  = () => {
171                     this.progressingTimer.forEach((item) => {
172                         if (item.serviceId === obj.serviceId) {
173                             clearInterval(item.timer);
174                         }
175                     });
176                     this.getCSMFBusinessList();
177                 }
178                 this.myhttp.getSlicingBusinessProgress(obj, queryProgressFailedCallback)
179                     .then((data) => {
180                         if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
181                             callback(data.result_body);
182                             let progressSetTimeOut = setTimeout(() => {
183                                 requery();
184                             }, 5000);
185                             this.progressingTimer.push({
186                                 id: obj.serviceId,
187                                 timer: progressSetTimeOut
188                             })
189                         } else {
190                             this.progressingTimer.forEach((item) => {
191                                 if (item.serviceId === obj.serviceId) {
192                                     clearInterval(item.timer);
193                                 }
194                             });
195                             res(data.result_body);
196                         }
197                     })
198             };
199             requery();
200         })
201     }
202
203     OrderModelShow(): void {
204         this.businessOrderShow = true;
205     }
206     orderModelClose($event: any): void {
207         this.businessOrderShow = $event;
208         this.getCSMFBusinessList();
209     }
210 }