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() {
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 === 'DELETE') this.terminateStart[index] = true
68 else this.terminateStart[index] = false;
69 this.queryProgress(obj, index, updata).then((res) => {
70 item.last_operation_progress = '100';
71 this.getCSMFBusinessList();
81 getListOfProcessingStatus() {
84 this.progressingTimer.forEach((item) => {
85 clearInterval(item.timer);
87 this.progressingTimer = [];
88 this.getCSMFBusinessList();
91 searchData(reset: boolean = false) {
92 this.progressingTimer.forEach((item) => {
93 clearInterval(item.timer);
95 this.progressingTimer = [];
96 this.getCSMFBusinessList();
99 switchChange(slicing, i) {
100 // console.log(slicing, i, "slicing");
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, slicing, "deactivate", "deactivated", i)
111 this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
116 let singleSlicing = Object.assign({}, this.listOfData[i]);
117 this.listOfData[i] = singleSlicing;
118 this.listOfData = [...this.listOfData];
122 changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
124 this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
125 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
126 this.loading = false;
127 if (+result_code === 200) {
128 this.getCSMFBusinessList();
130 let singleSlicing = Object.assign({}, this.listOfData[index]);
131 this.listOfData[index] = singleSlicing;
132 this.listOfData = [...this.listOfData];
133 this.getCSMFBusinessList();
135 this.getCSMFBusinessList();
137 this.loading = false;
138 let singleSlicing = Object.assign({}, this.listOfData[index]);
139 this.listOfData[index] = singleSlicing;
140 this.listOfData = [...this.listOfData];
141 this.getCSMFBusinessList();
145 terminate(slicing, index) {
146 this.modalService.confirm({
147 nzTitle: 'Are you sure you want to terminate this task?',
148 nzContent: '<b>Name: </b>' + slicing.order_name,
150 let paramsObj = { serviceId: slicing.order_id };
151 this.terminateStart[index] = true;
153 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
154 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
155 this.loading = false;
156 if (+result_code === 200) {
157 this.getCSMFBusinessList();
159 this.terminateStart[index] = false;
162 this.loading = false;
163 this.terminateStart[index] = false;
168 console.info('Cancel termination')
172 queryProgress(obj, index, callback) {
173 return new Promise(res => {
174 let requery = () => {
175 this.myhttp.getSlicingBusinessProgress(obj)
176 .subscribe((data) => {
177 const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
178 if (+result_code === 200) {
179 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
180 callback(data.result_body);
181 let progressSetTimeOut = setTimeout(() => {
184 this.progressingTimer.push({
186 timer: progressSetTimeOut
189 this.progressingTimer.forEach((item) => {
190 if (item.serviceId === obj.serviceId) {
191 clearInterval(item.timer);
194 res(data.result_body);
197 this.progressingTimer.forEach((item) => {
198 if (item.serviceId === obj.serviceId) {
199 clearInterval(item.timer);
202 this.getCSMFBusinessList();
203 this.message.error(result_message);
206 this.progressingTimer.forEach((item) => {
207 if (item.serviceId === obj.serviceId) {
208 clearInterval(item.timer);
211 this.getCSMFBusinessList();
212 this.message.error(err);
220 this.businessOrderShow = true;
222 orderModelClose($event) {
223 this.businessOrderShow = $event;
224 this.getCSMFBusinessList();