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