36a089cd800d6d66d50f2840093b18e98d5e4417
[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() {
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((res) => {
70                                 item.last_operation_progress = '100';
71                                 this.getCSMFBusinessList();
72                             })
73                         }
74                         return item
75                     });
76                 }
77             }
78         })
79     }
80
81     getListOfProcessingStatus() {
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(reset: boolean = false) {
92         this.progressingTimer.forEach((item) => {
93             clearInterval(item.timer);
94         });
95         this.progressingTimer = [];
96         this.getCSMFBusinessList();
97     }
98
99     switchChange(slicing, i) {
100         // console.log(slicing, i, "slicing");
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, slicing, "deactivate", "deactivated", i)
110                 } else {
111                     this.changeActivate(paramsObj, true, slicing, "activate", "activated", 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, isActivate, slicing, activateValue, finished, index) {
123         this.loading = true;
124         this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
125             const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
126             this.loading = false;
127             if (+result_code === 200) {
128                 this.getCSMFBusinessList();
129             } else {
130                 let singleSlicing = Object.assign({}, this.listOfData[index]);
131                 this.listOfData[index] = singleSlicing;
132                 this.listOfData = [...this.listOfData];
133                 this.getCSMFBusinessList();
134             }
135             this.getCSMFBusinessList();
136         }, () => {
137             this.loading = false;
138             let singleSlicing = Object.assign({}, this.listOfData[index]);
139             this.listOfData[index] = singleSlicing;
140             this.listOfData = [...this.listOfData];
141             this.getCSMFBusinessList();
142         })
143     }
144
145     terminate(slicing, index) {
146         this.modalService.confirm({
147             nzTitle: 'Are you sure you want to terminate this task?',
148             nzContent: '<b>Name:&nbsp;</b>' + slicing.order_name,
149             nzOnOk: () => {
150                 let paramsObj = { serviceId: slicing.order_id };
151                 this.terminateStart[index] = true;
152                 this.loading = true;
153                 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
154                     const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
155                     this.loading = false;
156                     if (+result_code === 200) {
157                         this.getCSMFBusinessList();
158                     } else {
159                         this.terminateStart[index] = false;
160                     }
161                 }, () => {
162                     this.loading = false;
163                     this.terminateStart[index] = false;
164                 })
165             },
166             nzCancelText: 'No',
167             nzOnCancel: () => {
168                 console.info('Cancel termination')
169             }
170         });
171     }
172     queryProgress(obj, index, callback) {
173         return new Promise(res => {
174             let requery = () => {
175                 this.myhttp.getSlicingBusinessProgress(obj)
176                     .subscribe((data) => {
177                         const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
178                         if (+result_code === 200) {
179                             if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
180                                 callback(data.result_body);
181                                 let progressSetTimeOut = setTimeout(() => {
182                                     requery();
183                                 }, 5000);
184                                 this.progressingTimer.push({
185                                     id: obj.serviceId,
186                                     timer: progressSetTimeOut
187                                 })
188                             } else {
189                                 this.progressingTimer.forEach((item) => {
190                                     if (item.serviceId === obj.serviceId) {
191                                         clearInterval(item.timer);
192                                     }
193                                 });
194                                 res(data.result_body);
195                             }
196                         } else {
197                             this.progressingTimer.forEach((item) => {
198                                 if (item.serviceId === obj.serviceId) {
199                                     clearInterval(item.timer);
200                                 }
201                             });
202                             this.getCSMFBusinessList();
203                             this.message.error(result_message);
204                         }
205                     }, (err) => {
206                         this.progressingTimer.forEach((item) => {
207                             if (item.serviceId === obj.serviceId) {
208                                 clearInterval(item.timer);
209                             }
210                         });
211                         this.getCSMFBusinessList();
212                         this.message.error(err);
213                     })
214             };
215             requery();
216         })
217     }
218
219     OrderModelShow() {
220         this.businessOrderShow = true;
221     }
222     orderModelClose($event) {
223         this.businessOrderShow = $event;
224         this.getCSMFBusinessList();
225     }
226 }