1 import {Component, OnInit} 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';
6 selector: 'app-csmf-slicing-business-management',
7 templateUrl: './csmf-slicing-business-management.component.html',
8 styleUrls: ['./csmf-slicing-business-management.component.less']
10 export class CsmfSlicingBusinessManagementComponent implements OnInit {
13 private myhttp: SlicingTaskServices,
14 private modalService: NzModalService,
15 private message: NzMessageService
20 this.getCSMFBusinessList()
23 this.progressingTimer.forEach((item) => {
24 clearInterval(item.timer);
26 this.progressingTimer = [];
29 selectedValue: string = BUSINESS_STATUS[0];
30 listOfData: any[] = [];
31 pageIndex: number = 1;
32 pageSize: number = 10;
35 statusOptions: any[] = BUSINESS_STATUS;
36 isSelect: boolean = false;
37 progressingTimer: any[] = [];
38 terminateStart: boolean = false;
40 getCSMFBusinessList() {
42 this.isSelect = false;
45 status: this.selectedValue,
46 pageNo: this.pageIndex,
47 pageSize: this.pageSize
49 if (this.selectedValue !== BUSINESS_STATUS[0]) {
50 paramsObj["businessStatus"] = this.selectedValue;
53 this.myhttp.getSlicingBusinessList(paramsObj, this.isSelect).subscribe(res => {
54 const {result_header: {result_code}, result_body: {slicing_business_list, record_number}} = res;
56 if (+result_code === 200) {
57 this.total = record_number;
58 if (slicing_business_list !== null && slicing_business_list.length > 0) {
59 this.listOfData = slicing_business_list.map((item, index) => {
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.service_instance_id
67 if (item.last_operation_type === 'DELETE') this.terminateStart = true;
68 this.queryProgress(obj, index, updata).then((res) => {
69 item.last_operation_progress = '100';
70 this.getCSMFBusinessList();
80 getListOfProcessingStatus() {
83 this.progressingTimer.forEach((item) => {
84 clearInterval(item.timer);
86 this.progressingTimer = [];
87 this.getCSMFBusinessList();
90 searchData(reset: boolean = false) {
91 this.progressingTimer.forEach((item) => {
92 clearInterval(item.timer);
94 this.progressingTimer = [];
95 this.getCSMFBusinessList();
98 switchChange(slicing, i) {
99 console.log(slicing, i, "slicing");
100 this.modalService.confirm({
101 nzTitle: '<i>Are you sure you want to perform this task?</i>',
102 nzContent: '<b>Name:' + slicing.service_instance_name + '</b>',
105 serviceId: slicing.service_instance_id
107 if (slicing.orchestration_status === 'activated') {
108 this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
110 this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
115 let singleSlicing = Object.assign({}, this.listOfData[i]);
116 this.listOfData[i] = singleSlicing;
117 this.listOfData = [...this.listOfData];
121 changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
123 this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
124 const { result_header: { result_code, result_message }, result_body: { operation_id } } = 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();
145 console.log(slicing, "slicing");
146 this.modalService.confirm({
147 nzTitle: 'Are you sure you want to terminate this task?',
148 nzContent: '<b>Name: </b>' + slicing.service_instance_name,
150 let paramsObj = { serviceId: slicing.service_instance_id };
151 this.terminateStart = 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 = false;
162 this.loading = false;
163 this.terminateStart = 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);