2dd1f0c8da89a93bd8d81b861649d7df9370268e
[usecase-ui.git] /
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';
6 @Component({
7     selector: 'app-slicing-business-table',
8     templateUrl: './slicing-business-table.component.html',
9     styleUrls: ['./slicing-business-table.component.less']
10 })
11 export class SlicingBusinessTableComponent implements OnInit {
12
13     constructor(
14         private myhttp: SlicingTaskServices,
15         private modalService: NzModalService,
16         private message: NzMessageService
17         ) {
18     }
19
20     ngOnInit() {
21         this.getBusinessList()
22     }
23     ngOnDestroy() {
24         this.progressingTimer.forEach((item) => {
25             clearInterval(item.timer);
26         })
27         this.progressingTimer = [];
28     }
29     selectedValue:string = BUSINESS_STATUS[0];
30     listOfData: any[] = [];
31     pageIndex: number = 1;
32     pageSize: number = 10;
33     total: number = 0;
34     loading = false;
35     isSelect: boolean = false;
36     statusOptions: any[] = BUSINESS_STATUS;
37     progressingTimer :any[] = [];
38     terminateStart :boolean = false;
39     @ViewChild('notification') notification1: any;
40
41     getBusinessList (): void{
42         this.loading = true;
43         this.isSelect = false;
44         let paramsObj = {
45             pageNo: this.pageIndex,
46             pageSize: this.pageSize
47         };
48         if(this.selectedValue !== BUSINESS_STATUS[0]){
49             paramsObj["businessStatus"] = this.selectedValue;
50             this.isSelect = true;
51         }
52         this.myhttp.getSlicingBusinessList(paramsObj,this.isSelect).subscribe (res => {
53             const { result_header: { result_code }, result_body: { slicing_business_list,record_number } } = res;
54             if (+result_code === 200) {
55                 this.total = record_number;
56                 this.loading = false;
57                 this.listOfData = slicing_business_list.map((item,index)=>{
58                     if(item.last_operation_progress!==null && item.last_operation_progress < 100 && item.last_operation_type!==null){
59                         let updata = (prodata) => {
60                             item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
61                         };
62                         let obj = {
63                             serviceId: item.service_instance_id
64                         };
65                         if(item.last_operation_type === 'delete')this.terminateStart = true;
66                         this.queryProgress(obj,item.orchestration_status,index, updata).then((res) => {
67                             item.last_operation_progress = 100;
68                         })
69                     }
70                     return item
71                 });
72             }
73         })
74     }
75     getListOfProcessingStatus(){
76         this.pageIndex = 1;
77         this.pageSize = 10;
78         this.progressingTimer.forEach((item) => {
79             clearInterval(item.timer);
80         });
81         this.progressingTimer = [];
82         this.getBusinessList();
83     }
84     searchData(reset: boolean = false) {
85         this.progressingTimer.forEach((item) => {
86             clearInterval(item.timer);
87         });
88         this.progressingTimer = [];
89         this.getBusinessList();
90     }
91     switchChange(slicing,i){
92         this.modalService.confirm({
93             nzTitle: '<i>Do you Want to'+(slicing.orchestration_status === 'activated'?'deactivated':'activated')+ 'slicing business?</i>',
94             nzContent: '<b>Name:'+slicing.service_instance_name+'</b>',
95             nzOnOk: () => {
96                 this.notification1.notificationStart('slicing business', slicing.orchestration_status === 'activated'?'deactivate':'activated', slicing.service_instance_id);
97                 let paramsObj = {
98                     serviceId:slicing.service_instance_id
99                 };
100                 if(slicing.orchestration_status === 'activated'){
101                     this.changeActivate(paramsObj,false,slicing,"deactivate","deactivated",i)
102                 }else {
103                     this.changeActivate(paramsObj,true,slicing,"activate","activated",i);
104                 }
105             },
106             nzCancelText: 'No',
107             nzOnCancel: () => {
108                 let singleSlicing = Object.assign({},this.listOfData[i]);
109                 this.listOfData[i] = singleSlicing;
110                 this.listOfData = [...this.listOfData];
111             }
112         });
113     }
114     changeActivate(paramsObj,isActivate,slicing,activateValue,finished,index){
115         this.myhttp.changeActivateSlicingService(paramsObj,isActivate).subscribe (res => {
116             const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
117             if (+result_code === 200) {
118                 this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id);
119                 this.getBusinessList();
120             }else {
121                 let singleSlicing = Object.assign({},this.listOfData[index]);
122                 this.listOfData[index] = singleSlicing;
123                 this.listOfData = [...this.listOfData];
124                 this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
125                 this.getBusinessList();
126             }
127             this.getBusinessList();
128         },() => {
129             let singleSlicing = Object.assign({},this.listOfData[index]);
130             this.listOfData[index] = singleSlicing;
131             this.listOfData = [...this.listOfData];
132             this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id);
133             this.getBusinessList();
134         })
135     }
136     terminate(slicing){
137         this.modalService.confirm({
138             nzTitle: 'Do you Want to Terminate slicing business?',
139             nzContent: '<b>Name:&nbsp;</b>'+slicing.service_instance_name,
140             nzOnOk: () => {
141                 this.notification1.notificationStart('slicing business', 'terminate', slicing.service_instance_id);
142                 let paramsObj = {
143                     serviceId:slicing.service_instance_id
144                 };
145                 this.terminateStart = true;
146                 this.myhttp.terminateSlicingService(paramsObj).subscribe (res => {
147                     const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
148                     if (+result_code === 200) {
149                         this.getBusinessList();
150                     }else {
151                         this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
152                         this.terminateStart = false;
153                     }
154                 },() => {
155                     this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id);
156                     this.terminateStart = false;
157                 })
158             },
159             nzCancelText: 'No',
160             nzOnCancel: () => {
161                 console.info('Cancel termination')
162             }
163         });
164     }
165     showdetail(data) {
166         const BusinessModal = this.modalService.create({
167             nzTitle:"Detail",
168             nzContent: SlicingBusinessModelComponent,
169             nzWidth:"70%",
170             nzOkText: null,
171             nzCancelText: null,
172             nzComponentParams:{
173                 businessId:data.service_instance_id
174             }
175         })
176     }
177     queryProgress(obj,action,index,callback) {
178         return new Promise( res => {
179             let requery = () => {
180                 this.myhttp.getSlicingBusinessProgress(obj)
181                     .subscribe((data) => {
182                         const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
183                         if (+result_code === 200) {
184                             if (data.result_body.operation_progress < 100) {
185                                 callback(data.result_body);
186                                 let progressSetTimeOut = setTimeout(() => {
187                                     requery();
188                                 }, 5000);
189                                 this.progressingTimer.push({
190                                     id: obj.serviceId,
191                                     timer: progressSetTimeOut
192                                 })
193                             } else {
194                                 this.progressingTimer.forEach((item) => {
195                                     if (item.serviceId === obj.serviceId) {
196                                         clearInterval(item.timer);
197                                     }
198                                 });
199                                 res(data.result_body);
200                             }
201                         }else {
202                             this.progressingTimer.forEach((item) => {
203                                 if (item.serviceId === obj.serviceId) {
204                                     clearInterval(item.timer);
205                                 }
206                             });
207                             this.getBusinessList();
208                             this.message.error(result_message);
209                         }
210                     },(err) => {
211                         this.progressingTimer.forEach((item) => {
212                             if (item.serviceId === obj.serviceId) {
213                                 clearInterval(item.timer);
214                             }
215                         });
216                         this.getBusinessList();
217                         this.message.error(err);
218                     })
219             };
220             requery();
221         })
222     }
223 }