1 import {Component, Input, OnInit, ViewChild,SimpleChanges} 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
20 @Input() currentTabName;
22 ngOnChanges(changes: SimpleChanges) {
23 if(changes.currentTabName.currentValue === 'Slicing Business Management'){
24 this.getBusinessList()
26 this.progressingTimer.forEach((item) => {
27 clearInterval(item.timer);
29 this.progressingTimer = [];
35 selectedValue: string = BUSINESS_STATUS[0];
36 listOfData: any[] = [];
37 pageIndex: number = 1;
38 pageSize: number = 10;
41 isSelect: boolean = false;
42 statusOptions: any[] = BUSINESS_STATUS;
43 progressingTimer: any[] = [];
44 terminateStart: any[] = [];
45 @ViewChild('notification') notification1: any;
47 getBusinessList(): void {
49 this.isSelect = false;
52 pageNo: this.pageIndex,
53 pageSize: this.pageSize
55 if (this.selectedValue !== BUSINESS_STATUS[0]) {
56 paramsObj["businessStatus"] = this.selectedValue.toLocaleLowerCase();
59 this.myhttp.getSlicingBusinessList(paramsObj, this.isSelect).subscribe(res => {
60 const { result_header: { result_code }, result_body: { slicing_business_list, record_number } } = res;
62 if (+result_code === 200) {
63 this.total = record_number;
64 if(slicing_business_list !==null && slicing_business_list.length >0){
65 this.listOfData = slicing_business_list.map((item, index) => {
66 if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
67 let updata = (prodata: { operation_progress: string }) => {
68 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
71 serviceId: item.service_instance_id
73 if (item.last_operation_type.toUpperCase() === 'DELETE') this.terminateStart[index] = true
74 else this.terminateStart[index] = false;
75 this.queryProgress(obj, item.orchestration_status, index, updata).then((res) => {
76 item.last_operation_progress = '100';
77 this.getBusinessList();
86 getListOfProcessingStatus() {
89 this.progressingTimer.forEach((item) => {
90 clearInterval(item.timer);
92 this.progressingTimer = [];
93 this.getBusinessList();
95 searchData(reset: boolean = false) {
96 this.progressingTimer.forEach((item) => {
97 clearInterval(item.timer);
99 this.progressingTimer = [];
100 this.getBusinessList();
102 switchChange(slicing, i) {
103 this.modalService.confirm({
104 nzTitle: '<i>Do you Want to ' + (slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate') + ' slicing business?</i>',
105 nzContent: '<b>Name:' + slicing.service_instance_name + '</b>',
107 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate', slicing.service_instance_id);
109 serviceId: slicing.service_instance_id
111 if (slicing.orchestration_status === 'activated') {
112 this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
114 this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
119 let singleSlicing = Object.assign({}, this.listOfData[i]);
120 this.listOfData[i] = singleSlicing;
121 this.listOfData = [...this.listOfData];
125 changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
127 this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
128 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
129 this.loading = false;
130 if (+result_code === 200) {
131 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
132 this.getBusinessList();
134 let singleSlicing = Object.assign({}, this.listOfData[index]);
135 this.listOfData[index] = singleSlicing;
136 this.listOfData = [...this.listOfData];
137 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
138 this.getBusinessList();
140 this.getBusinessList();
142 this.loading = false;
143 let singleSlicing = Object.assign({}, this.listOfData[index]);
144 this.listOfData[index] = singleSlicing;
145 this.listOfData = [...this.listOfData];
146 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
147 this.getBusinessList();
150 terminate(slicing,index) {
151 this.modalService.confirm({
152 nzTitle: 'Do you Want to terminate slicing business?',
153 nzContent: '<b>Name: </b>' + slicing.service_instance_name,
155 this.notification1.notificationStart('slicing business', 'terminate', slicing.service_instance_id);
156 let paramsObj = { serviceId: slicing.service_instance_id };
157 this.terminateStart[index] = true;
159 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
160 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
161 this.loading = false;
162 if (+result_code === 200) {
163 this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id);
164 this.getBusinessList();
166 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
167 this.terminateStart[index] = false;
170 this.loading = false;
171 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
172 this.terminateStart[index] = false;
177 console.info('Cancel termination')
182 const BusinessModal = this.modalService.create({
184 nzContent: SlicingBusinessModelComponent,
189 businessId: data.service_instance_id
193 queryProgress(obj, action, index, callback) {
194 return new Promise(res => {
195 let requery = () => {
196 this.myhttp.getSlicingBusinessProgress(obj)
197 .subscribe((data) => {
198 const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
199 if (+result_code === 200) {
200 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
201 callback(data.result_body);
202 let progressSetTimeOut = setTimeout(() => {
205 this.progressingTimer.push({
207 timer: progressSetTimeOut
210 this.progressingTimer.forEach((item) => {
211 if (item.serviceId === obj.serviceId) {
212 clearInterval(item.timer);
215 res(data.result_body);
218 this.progressingTimer.forEach((item) => {
219 if (item.serviceId === obj.serviceId) {
220 clearInterval(item.timer);
223 this.getBusinessList();
224 this.message.error(result_message);
227 this.progressingTimer.forEach((item) => {
228 if (item.serviceId === obj.serviceId) {
229 clearInterval(item.timer);
232 this.getBusinessList();
233 this.message.error(err);