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