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 = [];
34 selectedValue: string = BUSINESS_STATUS[0];
35 listOfData: any[] = [];
36 pageIndex: number = 1;
37 pageSize: number = 10;
40 statusOptions: any[] = BUSINESS_STATUS;
41 progressingTimer: any[] = [];
42 terminateStart: any[] = [];
43 businessOrderShow: boolean = false;
44 getCSMFBusinessList(): void {
48 status: this.selectedValue.toLocaleLowerCase(),
49 pageNo: this.pageIndex,
50 pageSize: this.pageSize
52 let getCSMFSlicingBusinessListFailedCallback = () => {
55 this.myhttp.getCSMFSlicingBusinessList(paramsObj, getCSMFSlicingBusinessListFailedCallback).then(res => {
56 const { result_body: { slicing_order_list, record_number } } = res;
58 this.total = record_number;
59 if (slicing_order_list !== null && slicing_order_list.length > 0) {
60 this.listOfData = slicing_order_list.map((item, index) => {
61 item.order_creation_time = moment(Number(item.order_creation_time)).format('YYYY-MM-DD HH:mm:ss');
62 if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
63 let updata = (prodata: { operation_progress: string }) => {
64 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
67 serviceId: item.order_id
69 if (item.last_operation_type.toUpperCase() === 'DELETE') this.terminateStart[index] = true
70 else this.terminateStart[index] = false;
71 this.queryProgress(obj, index, updata).then(() => {
72 item.last_operation_progress = '100';
73 this.getCSMFBusinessList();
82 getListOfProcessingStatus(): void {
85 this.progressingTimer.forEach((item) => {
86 clearInterval(item.timer);
88 this.progressingTimer = [];
89 this.getCSMFBusinessList();
93 this.progressingTimer.forEach((item) => {
94 clearInterval(item.timer);
96 this.progressingTimer = [];
97 this.getCSMFBusinessList();
100 switchChange(slicing:any, i:number): void {
101 this.modalService.confirm({
102 nzTitle: '<i>Are you sure you want to perform this task?</i>',
103 nzContent: '<b>Name:' + slicing.order_name + '</b>',
106 serviceId: slicing.order_id
108 if (slicing.order_status === 'activated') {
109 this.changeActivate(paramsObj, false, i)
111 this.changeActivate(paramsObj, true, i);
116 let singleSlicing = Object.assign({}, this.listOfData[i]);
117 this.listOfData[i] = singleSlicing;
118 this.listOfData = [...this.listOfData];
122 changeActivate(paramsObj: any, isActivate: boolean, index: number): void {
124 let changeActivateFailedCallback = () => {
125 this.loading = false;
126 let singleSlicing = Object.assign({}, this.listOfData[index]);
127 this.listOfData[index] = singleSlicing;
128 this.listOfData = [...this.listOfData];
129 this.getCSMFBusinessList();
131 this.myhttp.changeActivateSlicingService(paramsObj, isActivate, changeActivateFailedCallback).then((res) => {
132 this.loading = false;
133 this.getCSMFBusinessList();
137 terminate(slicing: any, index: number): void {
138 this.modalService.confirm({
139 nzTitle: 'Are you sure you want to terminate this task?',
140 nzContent: '<b>Name: </b>' + slicing.order_name,
142 let paramsObj = { serviceId: slicing.order_id };
143 this.terminateStart[index] = true;
145 let terminateFailedCallback = () => {
146 this.loading = false;
147 this.terminateStart[index] = false;
149 this.myhttp.terminateSlicingService(paramsObj, terminateFailedCallback).then(res => {
150 this.loading = false;
151 this.getCSMFBusinessList();
156 console.info('Cancel termination')
160 queryProgress(obj:any, index:number, callback:any) {
161 return new Promise(res => {
162 let requery = () => {
163 let queryProgressFailedCallback = () => {
164 this.progressingTimer.forEach((item) => {
165 if (item.serviceId === obj.serviceId) {
166 clearInterval(item.timer);
169 this.getCSMFBusinessList();
171 this.myhttp.getSlicingBusinessProgress(obj, queryProgressFailedCallback)
173 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
174 callback(data.result_body);
175 let progressSetTimeOut = setTimeout(() => {
178 this.progressingTimer.push({
180 timer: progressSetTimeOut
183 this.progressingTimer.forEach((item) => {
184 if (item.serviceId === obj.serviceId) {
185 clearInterval(item.timer);
188 res(data.result_body);
196 OrderModelShow(): void {
197 this.businessOrderShow = true;
199 orderModelClose($event: any): void {
200 this.businessOrderShow = $event;
201 this.getCSMFBusinessList();