288ad2c2db2fdbe1547814f8cbb83bbe38a39265
[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         this.progressingTimer.forEach((item) => {
36             clearInterval(item.timer)
37         })
38     }
39
40     selectedValue: string = BUSINESS_STATUS[0];
41     listOfData: any[] = [];
42     pageIndex: number = 1;
43     pageSize: number = 10;
44     total: number = 0;
45     loading = false;
46     statusOptions: any[] = BUSINESS_STATUS;
47     progressingTimer: any[] = [];
48     terminateStart: any[] = [];
49     businessOrderShow: boolean = false;
50     getCSMFBusinessList(): void {
51         this.loading = true;
52         // this.listOfData = []; //solve the problem of blank screen after each operation
53         const paramsObj = {
54             status: this.selectedValue.toLocaleLowerCase(),
55             pageNo: this.pageIndex,
56             pageSize: this.pageSize
57         };
58         const getCSMFSlicingBusinessListFailedCallback  = () => {
59             this.loading = false;
60         }
61         this.myhttp.getCSMFSlicingBusinessList(paramsObj, getCSMFSlicingBusinessListFailedCallback).then(res => {
62             const { result_body: { slicing_order_list, record_number } } = res;
63             this.loading = false;
64             this.total = record_number;
65             if (slicing_order_list !== null && slicing_order_list.length > 0) {
66                 this.listOfData = slicing_order_list.map((item, index) => {
67                     item.order_creation_time = moment(Number(item.order_creation_time)).format('YYYY-MM-DD HH:mm:ss');
68                     if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
69                         const updata = (prodata: { operation_progress: string }) => {
70                             item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
71                         };
72                         const obj = { serviceId: item.order_id };
73                         if (item.last_operation_type.toUpperCase() === 'DELETE') this.terminateStart[index] = true
74                         else this.terminateStart[index] = false;
75                         this.queryProgress(obj, index, updata).then(() => {
76                             item.last_operation_progress = '100';
77                             this.getCSMFBusinessList();
78                         })
79                     }
80                     return item
81                 });
82             }   
83         })
84     }
85
86     getListOfProcessingStatus(): void {
87         this.pageIndex = 1;
88         this.pageSize = 10;
89         this.progressingTimer.forEach((item) => {
90             clearInterval(item.timer);
91         });
92         this.progressingTimer = [];
93         this.getCSMFBusinessList();
94     }
95
96     searchData(): void {
97         this.progressingTimer.forEach((item) => {
98             clearInterval(item.timer);
99         });
100         this.progressingTimer = [];
101         this.getCSMFBusinessList();
102     }
103
104     switchChange(slicing:any, i:number): void {
105         this.modalService.confirm({
106             nzTitle: '<i>Are you sure you want to perform this task?</i>',
107             nzContent: '<b>Name:' + slicing.order_name + '</b>',
108             nzOnOk: () => {
109                 let paramsObj = {
110                     serviceId: slicing.order_id
111                 };
112                 if (slicing.order_status === 'activated') {
113                     this.changeActivate(paramsObj, false, i)
114                 } else {
115                     this.changeActivate(paramsObj, true, i);
116                 }
117             },
118             nzCancelText: 'No',
119             nzOnCancel: () => {
120                 const singleSlicing = Object.assign({}, this.listOfData[i]);
121                 this.listOfData[i] = singleSlicing;
122                 this.listOfData = [...this.listOfData];
123             }
124         });
125     }
126     changeActivate(paramsObj: any, isActivate: boolean, index: number): void {
127         const changeActivateFailedCallback = () => {
128             const singleSlicing = Object.assign({}, this.listOfData[index]);
129             this.listOfData[index] = singleSlicing;
130             this.listOfData = [...this.listOfData];
131             this.getCSMFBusinessList();
132         }
133         this.myhttp.changeActivateSlicingService(paramsObj, isActivate, changeActivateFailedCallback).then((res) => {
134             this.getCSMFBusinessList();
135         })
136     }
137
138     terminate(slicing: any, index: number): void {
139         this.modalService.confirm({
140             nzTitle: 'Are you sure you want to terminate this task?',
141             nzContent: '<b>Name:&nbsp;</b>' + slicing.order_name,
142             nzOnOk: () => {
143                 const paramsObj = { serviceId: slicing.order_id };
144                 this.terminateStart[index] = true;
145                 const terminateFailedCallback  = () => {
146                     this.terminateStart[index] = false;
147                 }
148                 this.myhttp.terminateSlicingService(paramsObj, terminateFailedCallback).then(res => {
149                     this.getCSMFBusinessList();
150                 })
151             },
152             nzCancelText: 'No',
153             nzOnCancel: () => {
154                 console.info('Cancel termination')
155             }
156         });
157     }
158     queryProgress(obj:any, index:number, callback:any) {
159         return new Promise(res => {
160             const requery = () => {
161                 const queryProgressFailedCallback  = () => {
162                     this.progressingTimer.forEach((item) => {
163                         if (item.serviceId === obj.serviceId) {
164                             clearInterval(item.timer);
165                         }
166                     });
167                     this.getCSMFBusinessList();
168                 }
169                 this.myhttp.getSlicingBusinessProgress(obj, queryProgressFailedCallback)
170                     .then((data) => {
171                         if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
172                             callback(data.result_body);
173                             let progressSetTimeOut = setTimeout(() => {
174                                 requery();
175                             }, 5000);
176                             this.progressingTimer.push({
177                                 id: obj.serviceId,
178                                 timer: progressSetTimeOut
179                             })
180                         } else {
181                             this.progressingTimer.forEach((item) => {
182                                 if (item.serviceId === obj.serviceId) {
183                                     clearInterval(item.timer);
184                                 }
185                             });
186                             res(data.result_body);
187                         }
188                     })
189             };
190             requery();
191         })
192     }
193
194     OrderModelShow(): void {
195         this.businessOrderShow = true;
196     }
197     orderModelClose($event: any): void {
198         this.businessOrderShow = $event;
199         this.getCSMFBusinessList();
200     }
201 }