387c98d70879adc2a04054b2867b7e231e99a6b9
[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 === '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             }
78         })
79     }
80
81     getListOfProcessingStatus(): void {
82         this.pageIndex = 1;
83         this.pageSize = 10;
84         this.progressingTimer.forEach((item) => {
85             clearInterval(item.timer);
86         });
87         this.progressingTimer = [];
88         this.getCSMFBusinessList();
89     }
90
91     searchData(): void {
92         this.progressingTimer.forEach((item) => {
93             clearInterval(item.timer);
94         });
95         this.progressingTimer = [];
96         this.getCSMFBusinessList();
97     }
98
99     switchChange(slicing:any, i:number): void {
100         this.modalService.confirm({
101             nzTitle: '<i>Are you sure you want to perform this task?</i>',
102             nzContent: '<b>Name:' + slicing.order_name + '</b>',
103             nzOnOk: () => {
104                 let paramsObj = {
105                     serviceId: slicing.order_id
106                 };
107                 if (slicing.order_status === 'activated') {
108                     this.changeActivate(paramsObj, false, i)
109                 } else {
110                     this.changeActivate(paramsObj, true, i);
111                 }
112             },
113             nzCancelText: 'No',
114             nzOnCancel: () => {
115                 let singleSlicing = Object.assign({}, this.listOfData[i]);
116                 this.listOfData[i] = singleSlicing;
117                 this.listOfData = [...this.listOfData];
118             }
119         });
120     }
121     changeActivate(paramsObj: any, isActivate: boolean, index: number): void {
122         this.loading = true;
123         this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
124             const { result_header: { result_code } } = res;
125             this.loading = false;
126             if (+result_code === 200) {
127                 this.getCSMFBusinessList();
128             } else {
129                 let singleSlicing = Object.assign({}, this.listOfData[index]);
130                 this.listOfData[index] = singleSlicing;
131                 this.listOfData = [...this.listOfData];
132                 this.getCSMFBusinessList();
133             }
134             this.getCSMFBusinessList();
135         }, () => {
136             this.loading = false;
137             let singleSlicing = Object.assign({}, this.listOfData[index]);
138             this.listOfData[index] = singleSlicing;
139             this.listOfData = [...this.listOfData];
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                 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
153                     const { result_header: { result_code } } = res;
154                     this.loading = false;
155                     if (+result_code === 200) {
156                         this.getCSMFBusinessList();
157                     } else {
158                         this.terminateStart[index] = false;
159                     }
160                 }, () => {
161                     this.loading = false;
162                     this.terminateStart[index] = false;
163                 })
164             },
165             nzCancelText: 'No',
166             nzOnCancel: () => {
167                 console.info('Cancel termination')
168             }
169         });
170     }
171     queryProgress(obj:any, index:number, callback:any) {
172         return new Promise(res => {
173             let requery = () => {
174                 this.myhttp.getSlicingBusinessProgress(obj)
175                     .subscribe((data) => {
176                         const { result_header: { result_code, result_message }} = data;
177                         if (+result_code === 200) {
178                             if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
179                                 callback(data.result_body);
180                                 let progressSetTimeOut = setTimeout(() => {
181                                     requery();
182                                 }, 5000);
183                                 this.progressingTimer.push({
184                                     id: obj.serviceId,
185                                     timer: progressSetTimeOut
186                                 })
187                             } else {
188                                 this.progressingTimer.forEach((item) => {
189                                     if (item.serviceId === obj.serviceId) {
190                                         clearInterval(item.timer);
191                                     }
192                                 });
193                                 res(data.result_body);
194                             }
195                         } else {
196                             this.progressingTimer.forEach((item) => {
197                                 if (item.serviceId === obj.serviceId) {
198                                     clearInterval(item.timer);
199                                 }
200                             });
201                             this.getCSMFBusinessList();
202                             this.message.error(result_message);
203                         }
204                     }, (err) => {
205                         this.progressingTimer.forEach((item) => {
206                             if (item.serviceId === obj.serviceId) {
207                                 clearInterval(item.timer);
208                             }
209                         });
210                         this.getCSMFBusinessList();
211                         this.message.error(err);
212                     })
213             };
214             requery();
215         })
216     }
217
218     OrderModelShow(): void {
219         this.businessOrderShow = true;
220     }
221     orderModelClose($event: any): void {
222         this.businessOrderShow = $event;
223         this.getCSMFBusinessList();
224     }
225 }