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