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 this.progressingTimer.forEach((item) => {
36 clearInterval(item.timer)
40 selectedValue: string = BUSINESS_STATUS[0];
41 listOfData: any[] = [];
42 pageIndex: number = 1;
43 pageSize: number = 10;
46 statusOptions: any[] = BUSINESS_STATUS;
47 progressingTimer: any[] = [];
48 terminateStart: any[] = [];
49 businessOrderShow: boolean = false;
50 getCSMFBusinessList(): void {
52 // this.listOfData = []; //solve the problem of blank screen after each operation
54 status: this.selectedValue.toLocaleLowerCase(),
55 pageNo: this.pageIndex,
56 pageSize: this.pageSize
58 const getCSMFSlicingBusinessListFailedCallback = () => {
61 this.myhttp.getCSMFSlicingBusinessList(paramsObj, getCSMFSlicingBusinessListFailedCallback).then(res => {
62 const { result_body: { slicing_order_list, record_number } } = res;
64 this.total = record_number;
65 if (slicing_order_list !== null && slicing_order_list.length > 0) {
66 this.listOfData = slicing_order_list.map((item, index) => {
67 item.order_creation_time = moment(Number(item.order_creation_time)).format('YYYY-MM-DD HH:mm:ss');
68 if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
69 const updata = (prodata: { operation_progress: string }) => {
70 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
72 const obj = { serviceId: item.order_id };
73 if (item.last_operation_type.toUpperCase() === 'DELETE') this.terminateStart[index] = true
74 else this.terminateStart[index] = false;
75 this.queryProgress(obj, index, updata).then(() => {
76 item.last_operation_progress = '100';
77 this.getCSMFBusinessList();
86 getListOfProcessingStatus(): void {
89 this.progressingTimer.forEach((item) => {
90 clearInterval(item.timer);
92 this.progressingTimer = [];
93 this.getCSMFBusinessList();
97 this.progressingTimer.forEach((item) => {
98 clearInterval(item.timer);
100 this.progressingTimer = [];
101 this.getCSMFBusinessList();
104 switchChange(slicing:any, i:number): void {
105 this.modalService.confirm({
106 nzTitle: '<i>Are you sure you want to perform this task?</i>',
107 nzContent: '<b>Name:' + slicing.order_name + '</b>',
110 serviceId: slicing.order_id
112 if (slicing.order_status === 'activated') {
113 this.changeActivate(paramsObj, false, i)
115 this.changeActivate(paramsObj, true, i);
120 const singleSlicing = Object.assign({}, this.listOfData[i]);
121 this.listOfData[i] = singleSlicing;
122 this.listOfData = [...this.listOfData];
126 changeActivate(paramsObj: any, isActivate: boolean, index: number): void {
127 const changeActivateFailedCallback = () => {
128 const singleSlicing = Object.assign({}, this.listOfData[index]);
129 this.listOfData[index] = singleSlicing;
130 this.listOfData = [...this.listOfData];
131 this.getCSMFBusinessList();
133 this.myhttp.changeActivateSlicingService(paramsObj, isActivate, changeActivateFailedCallback).then((res) => {
134 this.getCSMFBusinessList();
138 terminate(slicing: any, index: number): void {
139 this.modalService.confirm({
140 nzTitle: 'Are you sure you want to terminate this task?',
141 nzContent: '<b>Name: </b>' + slicing.order_name,
143 const paramsObj = { serviceId: slicing.order_id };
144 this.terminateStart[index] = true;
145 const terminateFailedCallback = () => {
146 this.terminateStart[index] = false;
148 this.myhttp.terminateSlicingService(paramsObj, terminateFailedCallback).then(res => {
149 this.getCSMFBusinessList();
154 console.info('Cancel termination')
158 queryProgress(obj:any, index:number, callback:any) {
159 return new Promise(res => {
160 const requery = () => {
161 const queryProgressFailedCallback = () => {
162 this.progressingTimer.forEach((item) => {
163 if (item.serviceId === obj.serviceId) {
164 clearInterval(item.timer);
167 this.getCSMFBusinessList();
169 this.myhttp.getSlicingBusinessProgress(obj, queryProgressFailedCallback)
171 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
172 callback(data.result_body);
173 let progressSetTimeOut = setTimeout(() => {
176 this.progressingTimer.push({
178 timer: progressSetTimeOut
181 this.progressingTimer.forEach((item) => {
182 if (item.serviceId === obj.serviceId) {
183 clearInterval(item.timer);
186 res(data.result_body);
194 OrderModelShow(): void {
195 this.businessOrderShow = true;
197 orderModelClose($event: any): void {
198 this.businessOrderShow = $event;
199 this.getCSMFBusinessList();