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';
7 selector: 'app-csmf-slicing-business-management',
8 templateUrl: './csmf-slicing-business-management.component.html',
9 styleUrls: ['./csmf-slicing-business-management.component.less']
11 export class CsmfSlicingBusinessManagementComponent implements OnInit {
14 private myhttp: SlicingTaskServices,
15 private modalService: NzModalService,
16 private message: NzMessageService
19 @Input() currentTabTitle;
21 ngOnChanges(changes: SimpleChanges) {
22 if(changes.currentTabTitle.currentValue === 'Communication Service'){
23 this.getCSMFBusinessList()
25 this.progressingTimer.forEach((item) => {
26 clearInterval(item.timer);
28 this.progressingTimer = [];
35 console.log(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 {
55 status: this.selectedValue.toLocaleLowerCase(),
56 pageNo: this.pageIndex,
57 pageSize: this.pageSize
59 let getCSMFSlicingBusinessListFailedCallback = () => {
62 this.myhttp.getCSMFSlicingBusinessList(paramsObj, getCSMFSlicingBusinessListFailedCallback).then(res => {
63 const { result_body: { slicing_order_list, record_number } } = res;
65 this.total = record_number;
66 if (slicing_order_list !== null && slicing_order_list.length > 0) {
67 this.listOfData = slicing_order_list.map((item, index) => {
68 item.order_creation_time = moment(Number(item.order_creation_time)).format('YYYY-MM-DD HH:mm:ss');
69 if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
70 let updata = (prodata: { operation_progress: string }) => {
71 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
74 serviceId: item.order_id
76 if (item.last_operation_type.toUpperCase() === 'DELETE') this.terminateStart[index] = true
77 else this.terminateStart[index] = false;
78 this.queryProgress(obj, index, updata).then(() => {
79 item.last_operation_progress = '100';
80 this.getCSMFBusinessList();
89 getListOfProcessingStatus(): void {
92 this.progressingTimer.forEach((item) => {
93 clearInterval(item.timer);
95 this.progressingTimer = [];
96 this.getCSMFBusinessList();
100 this.progressingTimer.forEach((item) => {
101 clearInterval(item.timer);
103 this.progressingTimer = [];
104 this.getCSMFBusinessList();
107 switchChange(slicing:any, i:number): void {
108 this.modalService.confirm({
109 nzTitle: '<i>Are you sure you want to perform this task?</i>',
110 nzContent: '<b>Name:' + slicing.order_name + '</b>',
113 serviceId: slicing.order_id
115 if (slicing.order_status === 'activated') {
116 this.changeActivate(paramsObj, false, i)
118 this.changeActivate(paramsObj, true, i);
123 let singleSlicing = Object.assign({}, this.listOfData[i]);
124 this.listOfData[i] = singleSlicing;
125 this.listOfData = [...this.listOfData];
129 changeActivate(paramsObj: any, isActivate: boolean, index: number): void {
131 let changeActivateFailedCallback = () => {
132 this.loading = false;
133 let singleSlicing = Object.assign({}, this.listOfData[index]);
134 this.listOfData[index] = singleSlicing;
135 this.listOfData = [...this.listOfData];
136 this.getCSMFBusinessList();
138 this.myhttp.changeActivateSlicingService(paramsObj, isActivate, changeActivateFailedCallback).then((res) => {
139 this.loading = false;
140 this.getCSMFBusinessList();
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: </b>' + slicing.order_name,
149 let paramsObj = { serviceId: slicing.order_id };
150 this.terminateStart[index] = true;
152 let terminateFailedCallback = () => {
153 this.loading = false;
154 this.terminateStart[index] = false;
156 this.myhttp.terminateSlicingService(paramsObj, terminateFailedCallback).then(res => {
157 this.loading = false;
158 this.getCSMFBusinessList();
163 console.info('Cancel termination')
167 queryProgress(obj:any, index:number, callback:any) {
168 return new Promise(res => {
169 let requery = () => {
170 let queryProgressFailedCallback = () => {
171 this.progressingTimer.forEach((item) => {
172 if (item.serviceId === obj.serviceId) {
173 clearInterval(item.timer);
176 this.getCSMFBusinessList();
178 this.myhttp.getSlicingBusinessProgress(obj, queryProgressFailedCallback)
180 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
181 callback(data.result_body);
182 let progressSetTimeOut = setTimeout(() => {
185 this.progressingTimer.push({
187 timer: progressSetTimeOut
190 this.progressingTimer.forEach((item) => {
191 if (item.serviceId === obj.serviceId) {
192 clearInterval(item.timer);
195 res(data.result_body);
203 OrderModelShow(): void {
204 this.businessOrderShow = true;
206 orderModelClose($event: any): void {
207 this.businessOrderShow = $event;
208 this.getCSMFBusinessList();