055925693e6f6b774c64111eae61cebadf4c9ccd
[usecase-ui.git] /
1 import {Component, OnInit} 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
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         ) {
17     }
18
19     ngOnInit() {
20         this.getBusinessList()
21     }
22     ngOnDestroy() {
23         clearInterval(this.progressingTimer);
24     }
25     selectedValue:string = BUSINESS_STATUS[0];
26     listOfData: any[] = [];
27     pageIndex: number = 1;
28     pageSize: number = 10;
29     total: number = 100;
30     loading = false;
31     isSelect: boolean = false;
32     statusOptions: any[] = BUSINESS_STATUS;
33     progressingTimer :any;
34
35
36     getBusinessList (): void{
37         this.loading = true;
38         this.isSelect = false;
39         let paramsObj = {
40             pageNo: this.pageIndex,
41             pageSize: this.pageSize
42         };
43         if(this.selectedValue !== BUSINESS_STATUS[0]){
44             paramsObj["businessStatus"] = this.selectedValue;
45             this.isSelect = true;
46         }
47         this.myhttp.getSlicingBusinessList(paramsObj,this.isSelect).subscribe (res => {
48             const { result_header: { result_code }, result_body: { slicing_business_list } } = res;
49             if (+result_code === 200) {
50                 this.total = slicing_business_list.length;
51                 this.loading = false;
52                 this.listOfData = slicing_business_list.map((item)=>{
53                     if(item.last_operation_progress < 100){
54                         let updata = (prodata) => {
55                             item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
56                         };
57                         let obj = {
58                             serviceId: item.service_instance_id
59                         };
60                         this.queryProgress(obj, updata).then((res) => {
61                             item.last_operation_progress = 100;
62                             item.orchestration_status = item.last_operation_type === 'activate'?'activated':item.last_operation_type === 'deactivated'?'deactivated':'terminated';
63                         })
64                     }
65                     return item
66                 });
67             }
68         })
69     }
70     getListOfProcessingStatus(){
71         this.pageIndex = 1;
72         this.pageSize = 10;
73         this.getBusinessList();
74     }
75     searchData(reset: boolean = false) {
76         this.getBusinessList();
77     }
78     switchChange(slicing,i){
79         this.modalService.confirm({
80             nzTitle: '<i>Do you Want to'+(slicing.orchestration_status === 'activated'?'deactivated':'activated')+ 'slicing business?</i>',
81             nzContent: '<b>service_instance_id:'+slicing.service_instance_id+'</b>',
82             nzOnOk: () => {
83                 let paramsObj = {
84                     serviceId:slicing.service_instance_id
85                 };
86                 if(slicing.orchestration_status === 'activated'){
87                     this.changeActivate(paramsObj,false,slicing,"deactivate","deactivated")
88                 }else {
89                     this.changeActivate(paramsObj,true,slicing,"activate","activated");
90                 }
91             },
92             nzCancelText: 'No',
93             nzOnCancel: () => {
94                 let singleSlicing = Object.assign({},this.listOfData[i]);
95                 this.listOfData[i] = singleSlicing;
96                 this.listOfData = [...this.listOfData];
97             }
98         });
99     }
100     changeActivate(paramsObj,isActivate,slicing,activateValue,finished){
101         this.myhttp.changeActivateSlicingService(paramsObj,isActivate).subscribe (res => {
102             const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
103             if (+result_code === 200) {
104                 slicing.last_operation_progress = 0;
105                 slicing.orchestration_status = activateValue;
106                 console.log(operation_id,"operation_id");
107                 let obj = {
108                     serviceId: slicing.service_instance_id
109                 }
110                 let updata = (prodata) => {
111                     slicing.last_operation_progress = prodata.progress;
112                     slicing.orchestration_status = prodata.operation_type;
113                     this.queryProgress(obj, updata).then(() => {
114                         slicing.last_operation_progress = 100;
115                         slicing.orchestration_status = finished;
116                     })
117                 }
118             }else {
119                 console.error(result_message)
120             }
121         })
122     }
123     terminate(slicing){
124         this.modalService.confirm({
125             nzTitle: 'Do you Want to Terminate slicing business?',
126             nzContent: '<b>service_instance_id:&nbsp;</b>'+slicing.service_instance_id,
127             nzOnOk: () => {
128                 let paramsObj = {
129                     serviceId:slicing.service_instance_id
130                 };
131                 this.myhttp.terminateSlicingService(paramsObj).subscribe (res => {
132                     const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
133                     if (+result_code === 200) {
134                         slicing.last_operation_progress = 0;
135                         slicing.orchestration_status = 'deactivate';
136                         console.log(operation_id,"operation_id");
137                         let obj = {
138                             serviceId: slicing.service_instance_id
139                         };
140                         let updata = (prodata) => {
141                             slicing.last_operation_progress = prodata.progress;
142                             slicing.orchestration_status = prodata.operation_type;
143                             this.queryProgress(obj, updata).then(() => {
144                                 slicing.last_operation_progress = 100;
145                                 slicing.orchestration_status = "terminated";
146                             })
147                         }
148                     }else {
149                         console.error(result_message)
150                     }
151                 })
152             },
153             nzCancelText: 'No',
154             nzOnCancel: () => {
155                 console.info('Cancel termination')
156             }
157         });
158     }
159     showdetail(data){
160
161     }
162     queryProgress(obj, callback) {
163         return new Promise( res => {
164             let requery = () => {
165                 this.myhttp.getSlicingBusinessProgress(obj)
166                     .subscribe((data) => {
167                         if (data.result_body.operation_progress < 100) {
168                             callback(data.result_body);
169                             this.progressingTimer = setTimeout(()=>{
170                                 requery();
171                             },5000);
172                         } else {
173                             res(data.result_body);
174                         }
175                     })
176             };
177             requery();
178         })
179     }
180 }