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 this.myhttp.getCSMFSlicingBusinessList(paramsObj).subscribe(res => {
53 const { result_header: { result_code }, result_body: { slicing_order_list, record_number } } = res;
55 if (+result_code === 200) {
56 this.total = record_number;
57 if (slicing_order_list !== null && slicing_order_list.length > 0) {
58 this.listOfData = slicing_order_list.map((item, index) => {
59 item.order_creation_time = moment(Number(item.order_creation_time)).format('YYYY-MM-DD HH:mm:ss');
60 if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
61 let updata = (prodata: { operation_progress: string }) => {
62 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
65 serviceId: item.order_id
67 if (item.last_operation_type.toUpperCase() === 'DELETE') this.terminateStart[index] = true
68 else this.terminateStart[index] = false;
69 this.queryProgress(obj, index, updata).then(() => {
70 item.last_operation_progress = '100';
71 this.getCSMFBusinessList();
81 getListOfProcessingStatus(): void {
84 this.progressingTimer.forEach((item) => {
85 clearInterval(item.timer);
87 this.progressingTimer = [];
88 this.getCSMFBusinessList();
92 this.progressingTimer.forEach((item) => {
93 clearInterval(item.timer);
95 this.progressingTimer = [];
96 this.getCSMFBusinessList();
99 switchChange(slicing:any, i:number): void {
100 this.modalService.confirm({
101 nzTitle: '<i>Are you sure you want to perform this task?</i>',
102 nzContent: '<b>Name:' + slicing.order_name + '</b>',
105 serviceId: slicing.order_id
107 if (slicing.order_status === 'activated') {
108 this.changeActivate(paramsObj, false, i)
110 this.changeActivate(paramsObj, true, i);
115 let singleSlicing = Object.assign({}, this.listOfData[i]);
116 this.listOfData[i] = singleSlicing;
117 this.listOfData = [...this.listOfData];
121 changeActivate(paramsObj: any, isActivate: boolean, index: number): void {
123 this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
124 const { result_header: { result_code } } = res;
125 this.loading = false;
126 if (+result_code === 200) {
127 this.getCSMFBusinessList();
129 let singleSlicing = Object.assign({}, this.listOfData[index]);
130 this.listOfData[index] = singleSlicing;
131 this.listOfData = [...this.listOfData];
132 this.getCSMFBusinessList();
134 this.getCSMFBusinessList();
136 this.loading = false;
137 let singleSlicing = Object.assign({}, this.listOfData[index]);
138 this.listOfData[index] = singleSlicing;
139 this.listOfData = [...this.listOfData];
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 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
153 const { result_header: { result_code } } = res;
154 this.loading = false;
155 if (+result_code === 200) {
156 this.getCSMFBusinessList();
158 this.terminateStart[index] = false;
161 this.loading = false;
162 this.terminateStart[index] = false;
167 console.info('Cancel termination')
171 queryProgress(obj:any, index:number, callback:any) {
172 return new Promise(res => {
173 let requery = () => {
174 this.myhttp.getSlicingBusinessProgress(obj)
175 .subscribe((data) => {
176 const { result_header: { result_code, result_message }} = data;
177 if (+result_code === 200) {
178 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
179 callback(data.result_body);
180 let progressSetTimeOut = setTimeout(() => {
183 this.progressingTimer.push({
185 timer: progressSetTimeOut
188 this.progressingTimer.forEach((item) => {
189 if (item.serviceId === obj.serviceId) {
190 clearInterval(item.timer);
193 res(data.result_body);
196 this.progressingTimer.forEach((item) => {
197 if (item.serviceId === obj.serviceId) {
198 clearInterval(item.timer);
201 this.getCSMFBusinessList();
202 this.message.error(result_message);
205 this.progressingTimer.forEach((item) => {
206 if (item.serviceId === obj.serviceId) {
207 clearInterval(item.timer);
210 this.getCSMFBusinessList();
211 this.message.error(err);
218 OrderModelShow(): void {
219 this.businessOrderShow = true;
221 orderModelClose($event: any): void {
222 this.businessOrderShow = $event;
223 this.getCSMFBusinessList();