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);
27 selectedValue:string = BUSINESS_STATUS[0];
28 listOfData: any[] = [];
29 pageIndex: number = 1;
30 pageSize: number = 10;
33 isSelect: boolean = false;
34 statusOptions: any[] = BUSINESS_STATUS;
35 progressingTimer :any[] = [];
36 terminateStart :boolean = false;
37 @ViewChild('notification') notification1: any;
39 getBusinessList (): void{
41 this.isSelect = false;
43 pageNo: this.pageIndex,
44 pageSize: this.pageSize
46 if(this.selectedValue !== BUSINESS_STATUS[0]){
47 paramsObj["businessStatus"] = this.selectedValue;
50 this.myhttp.getSlicingBusinessList(paramsObj,this.isSelect).subscribe (res => {
51 const { result_header: { result_code }, result_body: { slicing_business_list,record_number } } = res;
52 if (+result_code === 200) {
53 this.total = record_number;
55 this.listOfData = slicing_business_list.map((item)=>{
56 if(item.last_operation_progress < 100){
57 let updata = (prodata) => {
58 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
61 serviceId: item.service_instance_id
63 this.queryProgress(obj, updata).then((res) => {
64 item.last_operation_progress = 100;
72 getListOfProcessingStatus(){
75 this.getBusinessList();
77 searchData(reset: boolean = false) {
78 this.getBusinessList();
80 switchChange(slicing,i){
81 this.modalService.confirm({
82 nzTitle: '<i>Do you Want to'+(slicing.orchestration_status === 'activated'?'deactivated':'activated')+ 'slicing business?</i>',
83 nzContent: '<b>Name:'+slicing.service_instance_name+'</b>',
85 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated'?'deactivate':'activated', slicing.service_instance_id);
87 serviceId:slicing.service_instance_id
89 if(slicing.orchestration_status === 'activated'){
90 this.changeActivate(paramsObj,false,slicing,"deactivate","deactivated")
92 this.changeActivate(paramsObj,true,slicing,"activate","activated");
97 let singleSlicing = Object.assign({},this.listOfData[i]);
98 this.listOfData[i] = singleSlicing;
99 this.listOfData = [...this.listOfData];
103 changeActivate(paramsObj,isActivate,slicing,activateValue,finished){
104 this.myhttp.changeActivateSlicingService(paramsObj,isActivate).subscribe (res => {
105 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
106 if (+result_code === 200) {
107 slicing.last_operation_progress = 0;
108 slicing.orchestration_status = activateValue;
109 console.log(operation_id,"operation_id");
111 serviceId: slicing.service_instance_id
113 let updata = (prodata) => {
114 slicing.last_operation_progress = prodata.progress || 0;
115 slicing.orchestration_status = prodata.operation_type || activateValue;
117 this.queryProgress(obj, updata).then(() => {
118 slicing.last_operation_progress = 100;
119 slicing.orchestration_status = finished;
120 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
121 this.getBusinessList();
124 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
125 console.error(result_message);
130 this.modalService.confirm({
131 nzTitle: 'Do you Want to Terminate slicing business?',
132 nzContent: '<b>Name: </b>'+slicing.service_instance_name,
134 this.notification1.notificationStart('slicing business', 'terminate', slicing.service_instance_id);
136 serviceId:slicing.service_instance_id
138 this.terminateStart = true;
139 this.myhttp.terminateSlicingService(paramsObj).subscribe (res => {
140 const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
141 if (+result_code === 200) {
142 slicing.last_operation_progress = 0;
143 slicing.orchestration_status = 'delete';
144 console.log(operation_id,"operation_id");
146 serviceId: slicing.service_instance_id
148 let updata = (prodata) => {
149 slicing.last_operation_progress = prodata.progress || 0;
150 slicing.orchestration_status = prodata.operation_type || "delete";
152 this.queryProgress(obj, updata).then(() => {
153 slicing.last_operation_progress = 100;
154 slicing.orchestration_status = "delete";
155 this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id);
156 this.terminateStart = false;
157 this.getBusinessList();
160 this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
161 this.terminateStart = false;
162 console.error(result_message)
168 console.info('Cancel termination')
173 const BusinessModal = this.modalService.create({
175 nzContent: SlicingBusinessModelComponent,
180 businessId:data.service_instance_id
184 queryProgress(obj, callback) {
185 return new Promise( res => {
186 let requery = () => {
187 this.myhttp.getSlicingBusinessProgress(obj)
188 .subscribe((data) => {
189 if (data.result_body.operation_progress < 100) {
190 callback(data.result_body);
191 let progressSetTimeOut = setTimeout(() => {
194 this.progressingTimer.push({
196 timer:progressSetTimeOut
199 this.progressingTimer.forEach((item) => {
200 if(item.serviceId === obj.serviceId){
201 clearInterval(item.timer);
204 res(data.result_body);