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 {
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;
67 this.total = record_number;
68 if (slicing_order_list !== null && slicing_order_list.length > 0) {
69 this.listOfData = slicing_order_list.map((item, index) => {
70 item.order_creation_time = moment(Number(item.order_creation_time)).format('YYYY-MM-DD HH:mm:ss');
71 if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
72 const updata = (prodata: { operation_progress: string }) => {
73 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
76 serviceId: item.order_id
78 if (item.last_operation_type.toUpperCase() === 'DELETE') this.terminateStart[index] = true
79 else this.terminateStart[index] = false;
80 this.queryProgress(obj, index, updata).then(() => {
81 item.last_operation_progress = '100';
82 this.getCSMFBusinessList();
91 getListOfProcessingStatus(): void {
94 this.progressingTimer.forEach((item) => {
95 clearInterval(item.timer);
97 this.progressingTimer = [];
98 this.getCSMFBusinessList();
102 this.progressingTimer.forEach((item) => {
103 clearInterval(item.timer);
105 this.progressingTimer = [];
106 this.getCSMFBusinessList();
109 switchChange(slicing:any, i:number): void {
110 this.modalService.confirm({
111 nzTitle: '<i>Are you sure you want to perform this task?</i>',
112 nzContent: '<b>Name:' + slicing.order_name + '</b>',
115 serviceId: slicing.order_id
117 if (slicing.order_status === 'activated') {
118 this.changeActivate(paramsObj, false, i)
120 this.changeActivate(paramsObj, true, i);
125 const singleSlicing = Object.assign({}, this.listOfData[i]);
126 this.listOfData[i] = singleSlicing;
127 this.listOfData = [...this.listOfData];
131 changeActivate(paramsObj: any, isActivate: boolean, index: number): void {
132 const changeActivateFailedCallback = () => {
133 const 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.getCSMFBusinessList();
143 terminate(slicing: any, index: number): void {
144 this.modalService.confirm({
145 nzTitle: 'Are you sure you want to terminate this task?',
146 nzContent: '<b>Name: </b>' + slicing.order_name,
148 const paramsObj = { serviceId: slicing.order_id };
149 this.terminateStart[index] = true;
150 const terminateFailedCallback = () => {
151 this.terminateStart[index] = false;
153 this.myhttp.terminateSlicingService(paramsObj, terminateFailedCallback).then(res => {
154 this.getCSMFBusinessList();
159 console.info('Cancel termination')
163 queryProgress(obj:any, index:number, callback:any) {
164 return new Promise(res => {
165 const requery = () => {
166 const queryProgressFailedCallback = () => {
167 this.progressingTimer.forEach((item) => {
168 if (item.serviceId === obj.serviceId) {
169 clearInterval(item.timer);
172 this.getCSMFBusinessList();
174 this.myhttp.getSlicingBusinessProgress(obj, queryProgressFailedCallback)
176 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
177 callback(data.result_body);
178 let progressSetTimeOut = setTimeout(() => {
181 this.progressingTimer.push({
183 timer: progressSetTimeOut
186 this.progressingTimer.forEach((item) => {
187 if (item.serviceId === obj.serviceId) {
188 clearInterval(item.timer);
191 res(data.result_body);
199 OrderModelShow(): void {
200 this.businessOrderShow = true;
202 orderModelClose($event: any): void {
203 this.businessOrderShow = $event;
204 this.getCSMFBusinessList();