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