1 import { Component, OnInit, ViewChild } from '@angular/core';
2 import { SlicingTaskServices } from '.././../../../../../core/services/slicingTaskServices';
3 import { BUSINESS_STATUS } from '../../../../../../../constants/constants';
4 import { NzModalService, NzMessageService } from 'ng-zorro-antd';
5 import { SlicingBusinessModelComponent } from '../slicing-business-model/slicing-business-model.component';
7 selector: 'app-slicing-business-table',
8 templateUrl: './slicing-business-table.component.html',
9 styleUrls: ['./slicing-business-table.component.less']
11 export class SlicingBusinessTableComponent implements OnInit {
14 private myhttp: SlicingTaskServices,
15 private modalService: NzModalService,
16 private message: NzMessageService
21 this.getBusinessList()
24 this.progressingTimer.forEach((item) => {
25 clearInterval(item.timer);
27 this.progressingTimer = [];
29 selectedValue: string = BUSINESS_STATUS[0];
30 listOfData: any[] = [];
31 pageIndex: number = 1;
32 pageSize: number = 10;
35 isSelect: boolean = false;
36 statusOptions: any[] = BUSINESS_STATUS;
37 progressingTimer: any[] = [];
38 terminateStart: boolean = false;
39 @ViewChild('notification') notification1: any;
41 getBusinessList(): void {
43 this.isSelect = false;
45 pageNo: this.pageIndex,
46 pageSize: this.pageSize
48 if (this.selectedValue !== BUSINESS_STATUS[0]) {
49 paramsObj["businessStatus"] = this.selectedValue;
52 this.myhttp.getSlicingBusinessList(paramsObj, this.isSelect).subscribe(res => {
53 const { result_header: { result_code }, result_body: { slicing_business_list, record_number } } = res;
54 if (+result_code === 200) {
55 this.total = record_number;
57 this.listOfData = slicing_business_list.map((item, index) => {
58 if (item.last_operation_progress && item.last_operation_type && item.last_operation_progress < 100) {
59 let updata = (prodata: { operation_progress: string }) => {
60 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
63 serviceId: item.service_instance_id
65 if (item.last_operation_type === 'DELETE') this.terminateStart = true;
66 this.queryProgress(obj, item.orchestration_status, index, updata).then((res) => {
67 item.last_operation_progress = 100;
75 getListOfProcessingStatus() {
78 this.progressingTimer.forEach((item) => {
79 clearInterval(item.timer);
81 this.progressingTimer = [];
82 this.getBusinessList();
84 searchData(reset: boolean = false) {
85 this.progressingTimer.forEach((item) => {
86 clearInterval(item.timer);
88 this.progressingTimer = [];
89 this.getBusinessList();
91 switchChange(slicing, i) {
92 this.modalService.confirm({
93 nzTitle: '<i>Do you Want to ' + (slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate') + ' slicing business?</i>',
94 nzContent: '<b>Name:' + slicing.service_instance_name + '</b>',
96 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate', slicing.service_instance_id);
98 serviceId: slicing.service_instance_id
100 if (slicing.orchestration_status === 'activated') {
101 this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
103 this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
108 let singleSlicing = Object.assign({}, this.listOfData[i]);
109 this.listOfData[i] = singleSlicing;
110 this.listOfData = [...this.listOfData];
114 changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
116 this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
117 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
118 if (+result_code === 200) {
119 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
120 this.getBusinessList();
122 let singleSlicing = Object.assign({}, this.listOfData[index]);
123 this.listOfData[index] = singleSlicing;
124 this.listOfData = [...this.listOfData];
125 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
126 this.getBusinessList();
128 this.getBusinessList();
130 let singleSlicing = Object.assign({}, this.listOfData[index]);
131 this.listOfData[index] = singleSlicing;
132 this.listOfData = [...this.listOfData];
133 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
134 this.getBusinessList();
138 this.modalService.confirm({
139 nzTitle: 'Do you Want to terminate slicing business?',
140 nzContent: '<b>Name: </b>' + slicing.service_instance_name,
142 this.notification1.notificationStart('slicing business', 'terminate', slicing.service_instance_id);
143 let paramsObj = { serviceId: slicing.service_instance_id };
144 this.terminateStart = true;
146 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
147 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
148 if (+result_code === 200) {
149 this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id);
150 this.getBusinessList();
152 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
153 this.terminateStart = false;
156 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
157 this.terminateStart = false;
162 console.info('Cancel termination')
167 const BusinessModal = this.modalService.create({
169 nzContent: SlicingBusinessModelComponent,
174 businessId: data.service_instance_id
178 queryProgress(obj, action, index, callback) {
179 return new Promise(res => {
180 let requery = () => {
181 this.myhttp.getSlicingBusinessProgress(obj)
182 .subscribe((data) => {
183 const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
184 if (+result_code === 200) {
185 if (data.result_body.operation_progress && data.result_body.operation_progress < 100) {
186 callback(data.result_body);
187 let progressSetTimeOut = setTimeout(() => {
190 this.progressingTimer.push({
192 timer: progressSetTimeOut
195 this.progressingTimer.forEach((item) => {
196 if (item.serviceId === obj.serviceId) {
197 clearInterval(item.timer);
200 res(data.result_body);
203 this.progressingTimer.forEach((item) => {
204 if (item.serviceId === obj.serviceId) {
205 clearInterval(item.timer);
208 this.getBusinessList();
209 this.message.error(result_message);
212 this.progressingTimer.forEach((item) => {
213 if (item.serviceId === obj.serviceId) {
214 clearInterval(item.timer);
217 this.getBusinessList();
218 this.message.error(err);