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;
46 pageNo: this.pageIndex,
47 pageSize: this.pageSize
49 if (this.selectedValue !== BUSINESS_STATUS[0]) {
50 paramsObj["businessStatus"] = this.selectedValue;
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 = true;
68 this.queryProgress(obj, item.orchestration_status, index, updata).then((res) => {
69 item.last_operation_progress = '100';
70 this.getBusinessList();
79 getListOfProcessingStatus() {
82 this.progressingTimer.forEach((item) => {
83 clearInterval(item.timer);
85 this.progressingTimer = [];
86 this.getBusinessList();
88 searchData(reset: boolean = false) {
89 this.progressingTimer.forEach((item) => {
90 clearInterval(item.timer);
92 this.progressingTimer = [];
93 this.getBusinessList();
95 switchChange(slicing, i) {
96 this.modalService.confirm({
97 nzTitle: '<i>Do you Want to ' + (slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate') + ' slicing business?</i>',
98 nzContent: '<b>Name:' + slicing.service_instance_name + '</b>',
100 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated' ? 'deactivate' : 'activate', slicing.service_instance_id);
102 serviceId: slicing.service_instance_id
104 if (slicing.orchestration_status === 'activated') {
105 this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
107 this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
112 let singleSlicing = Object.assign({}, this.listOfData[i]);
113 this.listOfData[i] = singleSlicing;
114 this.listOfData = [...this.listOfData];
118 changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
120 this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
121 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
122 this.loading = false;
123 if (+result_code === 200) {
124 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
125 this.getBusinessList();
127 let singleSlicing = Object.assign({}, this.listOfData[index]);
128 this.listOfData[index] = singleSlicing;
129 this.listOfData = [...this.listOfData];
130 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
131 this.getBusinessList();
133 this.getBusinessList();
135 this.loading = false;
136 let singleSlicing = Object.assign({}, this.listOfData[index]);
137 this.listOfData[index] = singleSlicing;
138 this.listOfData = [...this.listOfData];
139 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
140 this.getBusinessList();
144 this.modalService.confirm({
145 nzTitle: 'Do you Want to terminate slicing business?',
146 nzContent: '<b>Name: </b>' + slicing.service_instance_name,
148 this.notification1.notificationStart('slicing business', 'terminate', slicing.service_instance_id);
149 let paramsObj = { serviceId: slicing.service_instance_id };
150 this.terminateStart = true;
152 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
153 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
154 this.loading = false;
155 if (+result_code === 200) {
156 this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id);
157 this.getBusinessList();
159 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
160 this.terminateStart = false;
163 this.loading = false;
164 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
165 this.terminateStart = false;
170 console.info('Cancel termination')
175 const BusinessModal = this.modalService.create({
177 nzContent: SlicingBusinessModelComponent,
182 businessId: data.service_instance_id
186 queryProgress(obj, action, index, callback) {
187 return new Promise(res => {
188 let requery = () => {
189 this.myhttp.getSlicingBusinessProgress(obj)
190 .subscribe((data) => {
191 const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
192 if (+result_code === 200) {
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);
211 this.progressingTimer.forEach((item) => {
212 if (item.serviceId === obj.serviceId) {
213 clearInterval(item.timer);
216 this.getBusinessList();
217 this.message.error(result_message);
220 this.progressingTimer.forEach((item) => {
221 if (item.serviceId === obj.serviceId) {
222 clearInterval(item.timer);
225 this.getBusinessList();
226 this.message.error(err);