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();
78 this.message.error(res.result_header.result_message)
83 getListOfProcessingStatus(): void {
86 this.progressingTimer.forEach((item) => {
87 clearInterval(item.timer);
89 this.progressingTimer = [];
90 this.getCSMFBusinessList();
94 this.progressingTimer.forEach((item) => {
95 clearInterval(item.timer);
97 this.progressingTimer = [];
98 this.getCSMFBusinessList();
101 switchChange(slicing:any, i:number): void {
102 this.modalService.confirm({
103 nzTitle: '<i>Are you sure you want to perform this task?</i>',
104 nzContent: '<b>Name:' + slicing.order_name + '</b>',
107 serviceId: slicing.order_id
109 if (slicing.order_status === 'activated') {
110 this.changeActivate(paramsObj, false, i)
112 this.changeActivate(paramsObj, true, i);
117 let singleSlicing = Object.assign({}, this.listOfData[i]);
118 this.listOfData[i] = singleSlicing;
119 this.listOfData = [...this.listOfData];
123 changeActivate(paramsObj: any, isActivate: boolean, index: number): void {
125 this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
126 const { result_header: { result_code } } = res;
127 this.loading = false;
128 if (+result_code === 200) {
129 this.getCSMFBusinessList();
131 let singleSlicing = Object.assign({}, this.listOfData[index]);
132 this.listOfData[index] = singleSlicing;
133 this.listOfData = [...this.listOfData];
134 this.message.error(res.result_header.result_message)
135 this.getCSMFBusinessList();
137 this.getCSMFBusinessList();
139 this.loading = false;
140 let singleSlicing = Object.assign({}, this.listOfData[index]);
141 this.listOfData[index] = singleSlicing;
142 this.listOfData = [...this.listOfData];
143 this.getCSMFBusinessList();
147 terminate(slicing: any, index: number): void {
148 this.modalService.confirm({
149 nzTitle: 'Are you sure you want to terminate this task?',
150 nzContent: '<b>Name: </b>' + slicing.order_name,
152 let paramsObj = { serviceId: slicing.order_id };
153 this.terminateStart[index] = true;
155 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
156 const { result_header: { result_code } } = res;
157 this.loading = false;
158 if (+result_code === 200) {
159 this.getCSMFBusinessList();
161 this.terminateStart[index] = false;
162 this.message.error(res.result_header.result_message)
165 this.loading = false;
166 this.terminateStart[index] = false;
171 console.info('Cancel termination')
175 queryProgress(obj:any, index:number, callback:any) {
176 return new Promise(res => {
177 let requery = () => {
178 this.myhttp.getSlicingBusinessProgress(obj)
179 .subscribe((data) => {
180 const { result_header: { result_code, result_message }} = data;
181 if (+result_code === 200) {
182 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
183 callback(data.result_body);
184 let progressSetTimeOut = setTimeout(() => {
187 this.progressingTimer.push({
189 timer: progressSetTimeOut
192 this.progressingTimer.forEach((item) => {
193 if (item.serviceId === obj.serviceId) {
194 clearInterval(item.timer);
197 res(data.result_body);
200 this.progressingTimer.forEach((item) => {
201 if (item.serviceId === obj.serviceId) {
202 clearInterval(item.timer);
205 this.getCSMFBusinessList();
206 this.message.error(result_message);
209 this.progressingTimer.forEach((item) => {
210 if (item.serviceId === obj.serviceId) {
211 clearInterval(item.timer);
214 this.getCSMFBusinessList();
215 this.message.error(err);
222 OrderModelShow(): void {
223 this.businessOrderShow = true;
225 orderModelClose($event: any): void {
226 this.businessOrderShow = $event;
227 this.getCSMFBusinessList();