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: any[] = [];
39 @ViewChild('notification') notification1: any;
41 getBusinessList(): void {
43 this.isSelect = false;
46 pageNo: this.pageIndex,
47 pageSize: this.pageSize
49 if (this.selectedValue !== BUSINESS_STATUS[0]) {
50 paramsObj["businessStatus"] = this.selectedValue.toLocaleLowerCase();
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[index] = true
68 else this.terminateStart[index] = false;
69 this.queryProgress(obj, item.orchestration_status, index, updata).then((res) => {
70 item.last_operation_progress = '100';
71 this.getBusinessList();
80 getListOfProcessingStatus() {
83 this.progressingTimer.forEach((item) => {
84 clearInterval(item.timer);
86 this.progressingTimer = [];
87 this.getBusinessList();
89 searchData(reset: boolean = false) {
90 this.progressingTimer.forEach((item) => {
91 clearInterval(item.timer);
93 this.progressingTimer = [];
94 this.getBusinessList();
96 switchChange(slicing, i) {
97 this.modalService.confirm({
98 nzTitle: '<i>Do you Want to ' + (slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate') + ' slicing business?</i>',
99 nzContent: '<b>Name:' + slicing.service_instance_name + '</b>',
101 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate', slicing.service_instance_id);
103 serviceId: slicing.service_instance_id
105 if (slicing.orchestration_status === 'activated') {
106 this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
108 this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
113 let singleSlicing = Object.assign({}, this.listOfData[i]);
114 this.listOfData[i] = singleSlicing;
115 this.listOfData = [...this.listOfData];
119 changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
121 this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
122 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
123 this.loading = false;
124 if (+result_code === 200) {
125 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
126 this.getBusinessList();
128 let singleSlicing = Object.assign({}, this.listOfData[index]);
129 this.listOfData[index] = singleSlicing;
130 this.listOfData = [...this.listOfData];
131 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
132 this.getBusinessList();
134 this.getBusinessList();
136 this.loading = false;
137 let singleSlicing = Object.assign({}, this.listOfData[index]);
138 this.listOfData[index] = singleSlicing;
139 this.listOfData = [...this.listOfData];
140 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
141 this.getBusinessList();
144 terminate(slicing,index) {
145 this.modalService.confirm({
146 nzTitle: 'Do you Want to terminate slicing business?',
147 nzContent: '<b>Name: </b>' + slicing.service_instance_name,
149 this.notification1.notificationStart('slicing business', 'terminate', slicing.service_instance_id);
150 let paramsObj = { serviceId: slicing.service_instance_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.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id);
158 this.getBusinessList();
160 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
161 this.terminateStart[index] = false;
164 this.loading = false;
165 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
166 this.terminateStart[index] = false;
171 console.info('Cancel termination')
176 const BusinessModal = this.modalService.create({
178 nzContent: SlicingBusinessModelComponent,
183 businessId: data.service_instance_id
187 queryProgress(obj, action, index, callback) {
188 return new Promise(res => {
189 let requery = () => {
190 this.myhttp.getSlicingBusinessProgress(obj)
191 .subscribe((data) => {
192 const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
193 if (+result_code === 200) {
194 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
195 callback(data.result_body);
196 let progressSetTimeOut = setTimeout(() => {
199 this.progressingTimer.push({
201 timer: progressSetTimeOut
204 this.progressingTimer.forEach((item) => {
205 if (item.serviceId === obj.serviceId) {
206 clearInterval(item.timer);
209 res(data.result_body);
212 this.progressingTimer.forEach((item) => {
213 if (item.serviceId === obj.serviceId) {
214 clearInterval(item.timer);
217 this.getBusinessList();
218 this.message.error(result_message);
221 this.progressingTimer.forEach((item) => {
222 if (item.serviceId === obj.serviceId) {
223 clearInterval(item.timer);
226 this.getBusinessList();
227 this.message.error(err);