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 } 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
20 this.getBusinessList()
23 this.progressingTimer.forEach((item) => {
24 clearInterval(item.timer);
26 this.progressingTimer = [];
28 selectedValue:string = BUSINESS_STATUS[0];
29 listOfData: any[] = [];
30 pageIndex: number = 1;
31 pageSize: number = 10;
34 isSelect: boolean = false;
35 statusOptions: any[] = BUSINESS_STATUS;
36 progressingTimer :any[] = [];
37 terminateStart :boolean = false;
38 @ViewChild('notification') notification1: any;
40 getBusinessList (): void{
42 this.isSelect = false;
44 pageNo: this.pageIndex,
45 pageSize: this.pageSize
47 if(this.selectedValue !== BUSINESS_STATUS[0]){
48 paramsObj["businessStatus"] = this.selectedValue;
51 this.myhttp.getSlicingBusinessList(paramsObj,this.isSelect).subscribe (res => {
52 const { result_header: { result_code }, result_body: { slicing_business_list,record_number } } = res;
53 if (+result_code === 200) {
54 this.total = record_number;
56 this.listOfData = slicing_business_list.map((item)=>{
57 if(item.last_operation_progress < 100){
58 let updata = (prodata) => {
59 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
62 serviceId: item.service_instance_id
64 this.queryProgress(obj, updata).then((res) => {
65 item.last_operation_progress = 100;
73 getListOfProcessingStatus(){
76 this.progressingTimer.forEach((item) => {
77 clearInterval(item.timer);
79 this.progressingTimer = [];
80 this.getBusinessList();
82 searchData(reset: boolean = false) {
83 this.progressingTimer.forEach((item) => {
84 clearInterval(item.timer);
86 this.progressingTimer = [];
87 this.getBusinessList();
89 switchChange(slicing,i){
90 this.modalService.confirm({
91 nzTitle: '<i>Do you Want to'+(slicing.orchestration_status === 'activated'?'deactivated':'activated')+ 'slicing business?</i>',
92 nzContent: '<b>Name:'+slicing.service_instance_name+'</b>',
94 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated'?'deactivate':'activated', slicing.service_instance_id);
96 serviceId:slicing.service_instance_id
98 if(slicing.orchestration_status === 'activated'){
99 this.changeActivate(paramsObj,false,slicing,"deactivate","deactivated",i)
101 this.changeActivate(paramsObj,true,slicing,"activate","activated",i);
106 let singleSlicing = Object.assign({},this.listOfData[i]);
107 this.listOfData[i] = singleSlicing;
108 this.listOfData = [...this.listOfData];
112 changeActivate(paramsObj,isActivate,slicing,activateValue,finished,index){
113 this.myhttp.changeActivateSlicingService(paramsObj,isActivate).subscribe (res => {
114 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
115 if (+result_code === 200) {
116 slicing.last_operation_progress = 0;
117 slicing.orchestration_status = activateValue;
118 console.log(operation_id,"operation_id");
120 serviceId: slicing.service_instance_id
122 let updata = (prodata) => {
123 slicing.last_operation_progress = prodata.progress || 0;
124 slicing.orchestration_status = prodata.operation_type || activateValue;
126 this.queryProgress(obj, updata).then(() => {
127 slicing.last_operation_progress = 100;
128 slicing.orchestration_status = finished;
129 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
130 this.getBusinessList();
133 let singleSlicing = Object.assign({},this.listOfData[index]);
134 this.listOfData[index] = singleSlicing;
135 this.listOfData = [...this.listOfData];
136 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
137 console.error(result_message);
140 let singleSlicing = Object.assign({},this.listOfData[index]);
141 this.listOfData[index] = singleSlicing;
142 this.listOfData = [...this.listOfData];
143 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
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);
154 serviceId:slicing.service_instance_id
156 this.terminateStart = true;
157 this.myhttp.terminateSlicingService(paramsObj).subscribe (res => {
158 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
159 if (+result_code === 200) {
160 slicing.last_operation_progress = 0;
161 slicing.orchestration_status = 'delete';
162 console.log(operation_id,"operation_id");
164 serviceId: slicing.service_instance_id
166 let updata = (prodata) => {
167 slicing.last_operation_progress = prodata.progress || 0;
168 slicing.orchestration_status = prodata.operation_type || "delete";
170 this.queryProgress(obj, updata).then(() => {
171 slicing.last_operation_progress = 100;
172 slicing.orchestration_status = "delete";
173 this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id);
174 this.terminateStart = false;
175 this.getBusinessList();
178 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
179 this.terminateStart = false;
180 console.error(result_message)
183 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
184 this.terminateStart = false;
190 console.info('Cancel termination')
195 const BusinessModal = this.modalService.create({
197 nzContent: SlicingBusinessModelComponent,
202 businessId:data.service_instance_id
206 queryProgress(obj, callback) {
207 return new Promise( res => {
208 let requery = () => {
209 this.myhttp.getSlicingBusinessProgress(obj)
210 .subscribe((data) => {
211 if (data.result_body.operation_progress < 100) {
212 callback(data.result_body);
213 let progressSetTimeOut = setTimeout(() => {
216 this.progressingTimer.push({
218 timer:progressSetTimeOut
221 this.progressingTimer.forEach((item) => {
222 if(item.serviceId === obj.serviceId){
223 clearInterval(item.timer);
226 res(data.result_body);