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 = [];
36 this.progressingTimer.forEach((item) => {
37 clearInterval(item.timer)
40 selectedValue: string = BUSINESS_STATUS[0];
41 listOfData: any[] = [];
42 pageIndex: number = 1;
43 pageSize: number = 10;
46 isSelect: boolean = false;
47 statusOptions: any[] = BUSINESS_STATUS;
48 progressingTimer: any[] = [];
49 terminateStart: any[] = [];
50 @ViewChild('notification') notification1: any;
52 getBusinessList(): void {
54 this.isSelect = false;
57 pageNo: this.pageIndex,
58 pageSize: this.pageSize
60 if (this.selectedValue !== BUSINESS_STATUS[0]) {
61 paramsObj["businessStatus"] = this.selectedValue.toLocaleLowerCase();
64 let getSlicingBusinessListFailedCallback = () => {
67 this.myhttp.getSlicingBusinessList(paramsObj, this.isSelect, getSlicingBusinessListFailedCallback).then(res => {
68 const { result_body: { slicing_business_list, record_number } } = res;
70 this.total = record_number;
71 if(slicing_business_list !==null && slicing_business_list.length >0){
72 this.listOfData = slicing_business_list.map((item, index) => {
73 if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
74 let updata = (prodata: { operation_progress: string }) => {
75 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
78 serviceId: item.service_instance_id
80 if (item.last_operation_type.toUpperCase() === 'DELETE') this.terminateStart[index] = true
81 else this.terminateStart[index] = false;
82 this.queryProgress(obj, item.orchestration_status, index, updata).then((res) => {
83 item.last_operation_progress = '100';
84 this.getBusinessList();
92 getListOfProcessingStatus() {
95 this.progressingTimer.forEach((item) => {
96 clearInterval(item.timer);
98 this.progressingTimer = [];
99 this.getBusinessList();
101 searchData(reset: boolean = false) {
102 this.progressingTimer.forEach((item) => {
103 clearInterval(item.timer);
105 this.progressingTimer = [];
106 this.getBusinessList();
108 switchChange(slicing, i) {
109 this.modalService.confirm({
110 nzTitle: '<i>Do you Want to ' + (slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate') + ' slicing business?</i>',
111 nzContent: '<b>Name:' + slicing.service_instance_name + '</b>',
113 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate', slicing.service_instance_id);
115 serviceId: slicing.service_instance_id
117 if (slicing.orchestration_status === 'activated') {
118 this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
120 this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
125 let singleSlicing = Object.assign({}, this.listOfData[i]);
126 this.listOfData[i] = singleSlicing;
127 this.listOfData = [...this.listOfData];
131 changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
133 let changeActivateFailedCallback = () => {
134 this.loading = false;
135 let singleSlicing = Object.assign({}, this.listOfData[index]);
136 this.listOfData[index] = singleSlicing;
137 this.listOfData = [...this.listOfData];
138 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
139 this.getBusinessList();
141 this.myhttp.changeActivateSlicingService(paramsObj, isActivate, changeActivateFailedCallback).then(res => {
142 this.loading = false;
143 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
144 this.getBusinessList();
147 terminate(slicing,index) {
148 this.modalService.confirm({
149 nzTitle: 'Do you Want to terminate slicing business?',
150 nzContent: '<b>Name: </b>' + slicing.service_instance_name,
152 this.notification1.notificationStart('slicing business', 'terminate', slicing.service_instance_id);
153 let paramsObj = { serviceId: slicing.service_instance_id };
154 this.terminateStart[index] = true;
156 let terminateFailedCallback = () => {
157 this.loading = false;
158 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
159 this.terminateStart[index] = false;
161 this.myhttp.terminateSlicingService(paramsObj, terminateFailedCallback).then(res => {
162 this.loading = false;
163 this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id);
164 this.getBusinessList();
169 console.info('Cancel termination')
174 const BusinessModal = this.modalService.create({
176 nzContent: SlicingBusinessModelComponent,
181 businessId: data.service_instance_id,
186 queryProgress(obj, action, index, callback) {
187 return new Promise(res => {
188 let requery = () => {
189 let queryProgressFailedCallback = () => {
190 this.progressingTimer.forEach((item) => {
191 if (item.serviceId === obj.serviceId) {
192 clearInterval(item.timer);
195 this.getBusinessList();
197 this.myhttp.getSlicingBusinessProgress(obj, queryProgressFailedCallback)
199 if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
200 callback(data.result_body);
201 let progressSetTimeOut = setTimeout(() => {
204 this.progressingTimer.push({
206 timer: progressSetTimeOut
209 this.progressingTimer.forEach((item) => {
210 if (item.serviceId === obj.serviceId) {
211 clearInterval(item.timer);
214 res(data.result_body);