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";
8 selector: "app-csmf-slicing-business-management",
9 templateUrl: "./csmf-slicing-business-management.component.html",
10 styleUrls: ["./csmf-slicing-business-management.component.less"],
12 export class CsmfSlicingBusinessManagementComponent implements OnInit {
14 private myhttp: SlicingTaskServices,
15 private modalService: NzModalService,
16 private message: NzMessageService
18 @Input() currentTabTitle;
20 intervalTime: number = INTERVAL_TIME;
22 ngOnChanges(changes: SimpleChanges) {
23 if (changes.currentTabTitle.currentValue === "Communication Service") {
24 this.getCSMFBusinessList();
26 this.progressingTimer.forEach((item) => {
27 clearInterval(item.timer);
29 this.progressingTimer = [];
36 this.progressingTimer.forEach((item) => {
37 clearInterval(item.timer);
41 selectedValue: string = BUSINESS_STATUS[0];
42 listOfData: any[] = [];
43 pageIndex: number = 1;
44 pageSize: number = 10;
47 statusOptions: any[] = BUSINESS_STATUS;
48 progressingTimer: any[] = [];
49 terminateStart: any[] = [];
50 businessOrderShow: boolean = false;
51 getCSMFBusinessList(): void {
53 // this.listOfData = []; //solve the problem of blank screen after each operation
55 status: this.selectedValue.toLocaleLowerCase(),
56 pageNo: this.pageIndex,
57 pageSize: this.pageSize,
59 const getCSMFSlicingBusinessListFailedCallback = () => {
63 .getCSMFSlicingBusinessList(
65 getCSMFSlicingBusinessListFailedCallback
69 result_body: { slicing_order_list, record_number },
72 this.total = record_number;
74 slicing_order_list !== null &&
75 slicing_order_list.length > 0
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");
82 item.last_operation_progress &&
83 item.last_operation_type &&
84 Number(item.last_operation_progress) < 100
86 const updata = (prodata: {
87 operation_progress: string;
89 item.last_operation_progress =
90 prodata.operation_progress ||
91 item.last_operation_progress;
93 const obj = { serviceId: item.order_id };
95 item.last_operation_type.toUpperCase() ===
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();
111 getListOfProcessingStatus(): void {
114 this.progressingTimer.forEach((item) => {
115 clearInterval(item.timer);
117 this.progressingTimer = [];
118 this.getCSMFBusinessList();
122 this.progressingTimer.forEach((item) => {
123 clearInterval(item.timer);
125 this.progressingTimer = [];
126 this.getCSMFBusinessList();
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>",
135 serviceId: slicing.order_id,
137 if (slicing.order_status === "activated") {
138 this.changeActivate(paramsObj, false, i);
140 this.changeActivate(paramsObj, true, i);
145 const singleSlicing = Object.assign({}, this.listOfData[i]);
146 this.listOfData[i] = singleSlicing;
147 this.listOfData = [...this.listOfData];
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();
159 .changeActivateSlicingService(
162 changeActivateFailedCallback
165 this.getCSMFBusinessList();
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: </b>" + slicing.order_name,
174 const paramsObj = { serviceId: slicing.order_id };
175 this.terminateStart[index] = true;
176 const terminateFailedCallback = () => {
177 this.terminateStart[index] = false;
180 .terminateSlicingService(paramsObj, terminateFailedCallback)
182 this.getCSMFBusinessList();
187 console.info("Cancel termination");
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);
200 this.getCSMFBusinessList();
203 .getSlicingBusinessProgress(
205 queryProgressFailedCallback
209 data.result_body.operation_progress &&
210 Number(data.result_body.operation_progress) < 100
212 callback(data.result_body);
213 let progressSetTimeOut = setTimeout(() => {
215 }, this.intervalTime);
216 this.progressingTimer.push({
218 timer: progressSetTimeOut,
221 this.progressingTimer.forEach((item) => {
222 if (item.serviceId === obj.serviceId) {
223 clearInterval(item.timer);
226 res(data.result_body);
234 OrderModelShow(): void {
235 this.businessOrderShow = true;
237 orderModelClose($event: any): void {
238 this.businessOrderShow = $event;
239 this.getCSMFBusinessList();