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 let getSlicingBusinessListFailedCallback = () => {
62 this.myhttp.getSlicingBusinessList(paramsObj, this.isSelect, getSlicingBusinessListFailedCallback).then(res => {
63 const { result_body: { slicing_business_list, record_number } } = res;
65 this.total = record_number;
66 if(slicing_business_list !==null && slicing_business_list.length >0){
67 this.listOfData = slicing_business_list.map((item, index) => {
68 if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
69 let updata = (prodata: { operation_progress: string }) => {
70 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
73 serviceId: item.service_instance_id
75 if (item.last_operation_type.toUpperCase() === 'DELETE') this.terminateStart[index] = true
76 else this.terminateStart[index] = false;
77 this.queryProgress(obj, item.orchestration_status, index, updata).then((res) => {
78 item.last_operation_progress = '100';
79 this.getBusinessList();
87 getListOfProcessingStatus() {
90 this.progressingTimer.forEach((item) => {
91 clearInterval(item.timer);
93 this.progressingTimer = [];
94 this.getBusinessList();
96 searchData(reset: boolean = false) {
97 this.progressingTimer.forEach((item) => {
98 clearInterval(item.timer);
100 this.progressingTimer = [];
101 this.getBusinessList();
103 switchChange(slicing, i) {
104 this.modalService.confirm({
105 nzTitle: '<i>Do you Want to ' + (slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate') + ' slicing business?</i>',
106 nzContent: '<b>Name:' + slicing.service_instance_name + '</b>',
108 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate', slicing.service_instance_id);
110 serviceId: slicing.service_instance_id
112 if (slicing.orchestration_status === 'activated') {
113 this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
115 this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
120 let singleSlicing = Object.assign({}, this.listOfData[i]);
121 this.listOfData[i] = singleSlicing;
122 this.listOfData = [...this.listOfData];
126 changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
128 let changeActivateFailedCallback = () => {
129 this.loading = false;
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();
136 this.myhttp.changeActivateSlicingService(paramsObj, isActivate, changeActivateFailedCallback).then(res => {
137 this.loading = false;
138 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
139 this.getBusinessList();
142 terminate(slicing,index) {
143 this.modalService.confirm({
144 nzTitle: 'Do you Want to terminate slicing business?',
145 nzContent: '<b>Name: </b>' + slicing.service_instance_name,
147 this.notification1.notificationStart('slicing business', 'terminate', slicing.service_instance_id);
148 let paramsObj = { serviceId: slicing.service_instance_id };
149 this.terminateStart[index] = true;
151 let terminateFailedCallback = () => {
152 this.loading = false;
153 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
154 this.terminateStart[index] = false;
156 this.myhttp.terminateSlicingService(paramsObj, terminateFailedCallback).then(res => {
157 this.loading = false;
158 this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id);
159 this.getBusinessList();
164 console.info('Cancel termination')
169 const BusinessModal = this.modalService.create({
171 nzContent: SlicingBusinessModelComponent,
176 businessId: data.service_instance_id
180 queryProgress(obj, action, index, callback) {
181 return new Promise(res => {
182 let requery = () => {
183 let queryProgressFailedCallback = () => {
184 this.progressingTimer.forEach((item) => {
185 if (item.serviceId === obj.serviceId) {
186 clearInterval(item.timer);
189 this.getBusinessList();
191 this.myhttp.getSlicingBusinessProgress(obj, queryProgressFailedCallback)
193 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
194 callback(data.result_body);
195 let progressSetTimeOut = setTimeout(() => {
198 this.progressingTimer.push({
200 timer: progressSetTimeOut
203 this.progressingTimer.forEach((item) => {
204 if (item.serviceId === obj.serviceId) {
205 clearInterval(item.timer);
208 res(data.result_body);