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