summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/services/slicing-management/slicing-resource-management/slicing-business-management/slicing-business-table/slicing-business-table.component.ts
blob: 515a4d3d910f591d1f2d37e1f3c9ff6d970088d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import {Component, OnInit} from '@angular/core';
import {SlicingTaskServices} from '.././../../../../../core/services/slicingTaskServices';
import {BUSINESS_STATUS} from '../../../../../../../constants/constants';
import { NzModalService } from 'ng-zorro-antd';
import { SlicingBusinessModelComponent } from '../slicing-business-model/slicing-business-model.component';
@Component({
    selector: 'app-slicing-business-table',
    templateUrl: './slicing-business-table.component.html',
    styleUrls: ['./slicing-business-table.component.less']
})
export class SlicingBusinessTableComponent implements OnInit {

    constructor(
        private myhttp: SlicingTaskServices,
        private modalService: NzModalService
        ) {
    }

    ngOnInit() {
        this.getBusinessList()
    }
    ngOnDestroy() {
        clearInterval(this.progressingTimer);
    }
    selectedValue:string = BUSINESS_STATUS[0];
    listOfData: any[] = [];
    pageIndex: number = 1;
    pageSize: number = 10;
    total: number = 0;
    loading = false;
    isSelect: boolean = false;
    statusOptions: any[] = BUSINESS_STATUS;
    progressingTimer :any;


    getBusinessList (): void{
        this.loading = true;
        this.isSelect = false;
        let paramsObj = {
            pageNo: this.pageIndex,
            pageSize: this.pageSize
        };
        if(this.selectedValue !== BUSINESS_STATUS[0]){
            paramsObj["businessStatus"] = this.selectedValue;
            this.isSelect = true;
        }
        this.myhttp.getSlicingBusinessList(paramsObj,this.isSelect).subscribe (res => {
            const { result_header: { result_code }, result_body: { slicing_business_list,record_number } } = res;
            if (+result_code === 200) {
                this.total = record_number;
                this.loading = false;
                this.listOfData = slicing_business_list.map((item)=>{
                    if(item.last_operation_progress < 100){
                        let updata = (prodata) => {
                            item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
                        };
                        let obj = {
                            serviceId: item.service_instance_id
                        };
                        this.queryProgress(obj, updata).then((res) => {
                            item.last_operation_progress = 100;
                            item.orchestration_status = item.last_operation_type === 'activate'?'activated':item.last_operation_type === 'deactivated'?'deactivated':'terminated';
                        })
                    }
                    return item
                });
            }
        })
    }
    getListOfProcessingStatus(){
        this.pageIndex = 1;
        this.pageSize = 10;
        this.getBusinessList();
    }
    searchData(reset: boolean = false) {
        this.getBusinessList();
    }
    switchChange(slicing,i){
        this.modalService.confirm({
            nzTitle: '<i>Do you Want to'+(slicing.orchestration_status === 'activated'?'deactivated':'activated')+ 'slicing business?</i>',
            nzContent: '<b>service_instance_id:'+slicing.service_instance_id+'</b>',
            nzOnOk: () => {
                let paramsObj = {
                    serviceId:slicing.service_instance_id
                };
                if(slicing.orchestration_status === 'activated'){
                    this.changeActivate(paramsObj,false,slicing,"deactivate","deactivated")
                }else {
                    this.changeActivate(paramsObj,true,slicing,"activate","activated");
                }
            },
            nzCancelText: 'No',
            nzOnCancel: () => {
                let singleSlicing = Object.assign({},this.listOfData[i]);
                this.listOfData[i] = singleSlicing;
                this.listOfData = [...this.listOfData];
            }
        });
    }
    changeActivate(paramsObj,isActivate,slicing,activateValue,finished){
        this.myhttp.changeActivateSlicingService(paramsObj,isActivate).subscribe (res => {
            const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
            if (+result_code === 200) {
                slicing.last_operation_progress = 0;
                slicing.orchestration_status = activateValue;
                console.log(operation_id,"operation_id");
                let obj = {
                    serviceId: slicing.service_instance_id
                }
                let updata = (prodata) => {
                    slicing.last_operation_progress = prodata.progress;
                    slicing.orchestration_status = prodata.operation_type;
                    this.queryProgress(obj, updata).then(() => {
                        slicing.last_operation_progress = 100;
                        slicing.orchestration_status = finished;
                    })
                }
            }else {
                console.error(result_message)
            }
        })
    }
    terminate(slicing){
        this.modalService.confirm({
            nzTitle: 'Do you Want to Terminate slicing business?',
            nzContent: '<b>service_instance_id:&nbsp;</b>'+slicing.service_instance_id,
            nzOnOk: () => {
                let paramsObj = {
                    serviceId:slicing.service_instance_id
                };
                this.myhttp.terminateSlicingService(paramsObj).subscribe (res => {
                    const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
                    if (+result_code === 200) {
                        slicing.last_operation_progress = 0;
                        slicing.orchestration_status = 'deactivate';
                        console.log(operation_id,"operation_id");
                        let obj = {
                            serviceId: slicing.service_instance_id
                        };
                        let updata = (prodata) => {
                            slicing.last_operation_progress = prodata.progress;
                            slicing.orchestration_status = prodata.operation_type;
                            this.queryProgress(obj, updata).then(() => {
                                slicing.last_operation_progress = 100;
                                slicing.orchestration_status = "terminated";
                            })
                        }
                    }else {
                        console.error(result_message)
                    }
                })
            },
            nzCancelText: 'No',
            nzOnCancel: () => {
                console.info('Cancel termination')
            }
        });
    }
    showdetail(data) {
        const BusinessModal = this.modalService.create({
            nzTitle:"Detail",
            nzContent: SlicingBusinessModelComponent,
            nzWidth:"70%",
            nzOkText: null,
            nzCancelText: null,
            nzComponentParams:{
                businessId:data.service_instance_id
            }
        })
    }
    queryProgress(obj, callback) {
        return new Promise( res => {
            let requery = () => {
                this.myhttp.getSlicingBusinessProgress(obj)
                    .subscribe((data) => {
                        if (data.result_body.operation_progress < 100) {
                            callback(data.result_body);
                            this.progressingTimer = setTimeout(()=>{
                                requery();
                            },5000);
                        } else {
                            clearInterval(this.progressingTimer);
                            res(data.result_body);
                        }
                    })
            };
            requery();
        })
    }
}