6eb5e9365447fd415b7a9dc30119712bf3639546
[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 import { INTERVAL_TIME } from "../constant";
7 @Component({
8         selector: "app-csmf-slicing-business-management",
9         templateUrl: "./csmf-slicing-business-management.component.html",
10         styleUrls: ["./csmf-slicing-business-management.component.less"],
11 })
12 export class CsmfSlicingBusinessManagementComponent implements OnInit {
13         constructor(
14                 private myhttp: SlicingTaskServices,
15                 private modalService: NzModalService,
16                 private message: NzMessageService
17         ) {}
18         @Input() currentTabTitle;
19
20         intervalTime: number = INTERVAL_TIME;
21
22         ngOnChanges(changes: SimpleChanges) {
23                 if (changes.currentTabTitle.currentValue === "Communication Service") {
24                         this.getCSMFBusinessList();
25                 } else {
26                         this.progressingTimer.forEach((item) => {
27                                 clearInterval(item.timer);
28                         });
29                         this.progressingTimer = [];
30                 }
31         }
32
33         ngOnInit() {}
34
35         ngOnDestroy() {
36                 this.progressingTimer.forEach((item) => {
37                         clearInterval(item.timer);
38                 });
39         }
40
41         selectedValue: string = BUSINESS_STATUS[0];
42         listOfData: any[] = [];
43         pageIndex: number = 1;
44         pageSize: number = 10;
45         total: number = 0;
46         loading = false;
47         statusOptions: any[] = BUSINESS_STATUS;
48         progressingTimer: any[] = [];
49         terminateStart: any[] = [];
50         businessOrderShow: boolean = false;
51         inputBusinessOrderShow: boolean = false;
52         orderForm: any;
53         getCSMFBusinessList(): void {
54                 this.loading = true;
55                 // this.listOfData = []; //solve the problem of blank screen after each operation
56                 const paramsObj = {
57                         status: this.selectedValue.toLocaleLowerCase(),
58                         pageNo: this.pageIndex,
59                         pageSize: this.pageSize,
60                 };
61                 const getCSMFSlicingBusinessListFailedCallback = () => {
62                         this.loading = false;
63                 };
64                 this.myhttp
65                         .getCSMFSlicingBusinessList(
66                                 paramsObj,
67                                 getCSMFSlicingBusinessListFailedCallback
68                         )
69                         .then((res) => {
70                                 const {
71                                         result_body: { slicing_order_list, record_number },
72                                 } = res;
73                                 this.loading = false;
74                                 this.total = record_number;
75                                 if (
76                                         slicing_order_list !== null &&
77                                         slicing_order_list.length > 0
78                                 ) {
79                                         this.listOfData = slicing_order_list.map((item, index) => {
80                                                 item.order_creation_time = moment(
81                                                         Number(item.order_creation_time)
82                                                 ).format("YYYY-MM-DD HH:mm:ss");
83                                                 if (
84                                                         item.last_operation_progress &&
85                                                         item.last_operation_type &&
86                                                         Number(item.last_operation_progress) < 100
87                                                 ) {
88                                                         const updata = (prodata: {
89                                                                 operation_progress: string;
90                                                         }) => {
91                                                                 item.last_operation_progress =
92                                                                         prodata.operation_progress ||
93                                                                         item.last_operation_progress;
94                                                         };
95                                                         const obj = { serviceId: item.order_id };
96                                                         if (
97                                                                 item.last_operation_type.toUpperCase() ===
98                                                                 "DELETE"
99                                                         )
100                                                                 this.terminateStart[index] = true;
101                                                         else this.terminateStart[index] = false;
102                                                         this.queryProgress(obj, index, updata).then(() => {
103                                                                 item.last_operation_progress = "100";
104                                                                 this.getCSMFBusinessList();
105                                                         });
106                                                 }
107                                                 return item;
108                                         });
109                                 }
110                         });
111         }
112
113         getListOfProcessingStatus(): void {
114                 this.pageIndex = 1;
115                 this.pageSize = 10;
116                 this.progressingTimer.forEach((item) => {
117                         clearInterval(item.timer);
118                 });
119                 this.progressingTimer = [];
120                 this.getCSMFBusinessList();
121         }
122
123         searchData(): void {
124                 this.progressingTimer.forEach((item) => {
125                         clearInterval(item.timer);
126                 });
127                 this.progressingTimer = [];
128                 this.getCSMFBusinessList();
129         }
130
131         switchChange(slicing: any, i: number): void {
132                 this.modalService.confirm({
133                         nzTitle: "<i>Are you sure you want to perform this task?</i>",
134                         nzContent: "<b>Name:" + slicing.order_name + "</b>",
135                         nzOnOk: () => {
136                                 let paramsObj = {
137                                         serviceId: slicing.order_id,
138                                 };
139                                 if (slicing.order_status === "activated") {
140                                         this.changeActivate(paramsObj, false, i);
141                                 } else {
142                                         this.changeActivate(paramsObj, true, i);
143                                 }
144                         },
145                         nzCancelText: "No",
146                         nzOnCancel: () => {
147                                 const singleSlicing = Object.assign({}, this.listOfData[i]);
148                                 this.listOfData[i] = singleSlicing;
149                                 this.listOfData = [...this.listOfData];
150                         },
151                 });
152         }
153         changeActivate(paramsObj: any, isActivate: boolean, index: number): void {
154                 const changeActivateFailedCallback = () => {
155                         const singleSlicing = Object.assign({}, this.listOfData[index]);
156                         this.listOfData[index] = singleSlicing;
157                         this.listOfData = [...this.listOfData];
158                         this.getCSMFBusinessList();
159                 };
160                 this.myhttp
161                         .changeActivateSlicingService(
162                                 paramsObj,
163                                 isActivate,
164                                 changeActivateFailedCallback
165                         )
166                         .then((res) => {
167                                 this.getCSMFBusinessList();
168                         });
169         }
170
171         terminate(slicing: any, index: number): void {
172                 this.modalService.confirm({
173                         nzTitle: "Are you sure you want to terminate this task?",
174                         nzContent: "<b>Name:&nbsp;</b>" + slicing.order_name,
175                         nzOnOk: () => {
176                                 const paramsObj = { serviceId: slicing.order_id };
177                                 this.terminateStart[index] = true;
178                                 const terminateFailedCallback = () => {
179                                         this.terminateStart[index] = false;
180                                 };
181                                 this.myhttp
182                                         .terminateSlicingService(paramsObj, terminateFailedCallback)
183                                         .then((res) => {
184                                                 this.getCSMFBusinessList();
185                                         });
186                         },
187                         nzCancelText: "No",
188                         nzOnCancel: () => {
189                                 console.info("Cancel termination");
190                         },
191                 });
192         }
193         queryProgress(obj: any, index: number, callback: any) {
194                 return new Promise((res) => {
195                         const requery = () => {
196                                 const queryProgressFailedCallback = () => {
197                                         this.progressingTimer.forEach((item) => {
198                                                 if (item.serviceId === obj.serviceId) {
199                                                         clearInterval(item.timer);
200                                                 }
201                                         });
202                                         this.getCSMFBusinessList();
203                                 };
204                                 this.myhttp
205                                         .getSlicingBusinessProgress(
206                                                 obj,
207                                                 queryProgressFailedCallback
208                                         )
209                                         .then((data) => {
210                                                 if (
211                                                         data.result_body.operation_progress &&
212                                                         Number(data.result_body.operation_progress) < 100
213                                                 ) {
214                                                         callback(data.result_body);
215                                                         let progressSetTimeOut = setTimeout(() => {
216                                                                 requery();
217                                                         }, this.intervalTime);
218                                                         this.progressingTimer.push({
219                                                                 id: obj.serviceId,
220                                                                 timer: progressSetTimeOut,
221                                                         });
222                                                 } else {
223                                                         this.progressingTimer.forEach((item) => {
224                                                                 if (item.serviceId === obj.serviceId) {
225                                                                         clearInterval(item.timer);
226                                                                 }
227                                                         });
228                                                         res(data.result_body);
229                                                 }
230                                         });
231                         };
232                         requery();
233                 });
234         }
235
236         OrderModelShow(): void {
237             this.orderForm = null;
238             this.businessOrderShow = true;
239         }
240         orderModelClose($event: any): void {
241             this.businessOrderShow = $event;
242             this.getCSMFBusinessList();
243         }
244         inputOrderModelShow(): void {
245             this.inputBusinessOrderShow = true;
246         }
247         inputOrderModelClose($event: any): void {
248             this.inputBusinessOrderShow = false;
249             if ($event.cancel) {
250                 return;
251             }
252             this.orderForm = $event.param;
253             this.businessOrderShow = true;
254         }
255 }