summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/services/slicing-management/csmf-slicing-business-management/csmf-slicing-business-management.component.ts
blob: 36a089cd800d6d66d50f2840093b18e98d5e4417 (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import {Component, Input, OnInit, SimpleChanges} from '@angular/core';
import { BUSINESS_STATUS } from "../../../../../constants/constants";
import { SlicingTaskServices } from '.././../../../core/services/slicingTaskServices';
import { NzModalService, NzMessageService } from 'ng-zorro-antd';
import * as moment from 'moment';
@Component({
    selector: 'app-csmf-slicing-business-management',
    templateUrl: './csmf-slicing-business-management.component.html',
    styleUrls: ['./csmf-slicing-business-management.component.less']
})
export class CsmfSlicingBusinessManagementComponent implements OnInit {

    constructor(
        private myhttp: SlicingTaskServices,
        private modalService: NzModalService,
        private message: NzMessageService
    ) {
    }
    @Input() currentTabTitle;

    ngOnChanges(changes: SimpleChanges) {
        if(changes.currentTabTitle.currentValue === 'Communication Service'){
            this.getCSMFBusinessList()
        }else {
            this.progressingTimer.forEach((item) => {
                clearInterval(item.timer);
            });
            this.progressingTimer = [];
        }
    }

    ngOnInit() {}

    selectedValue: string = BUSINESS_STATUS[0];
    listOfData: any[] = [];
    pageIndex: number = 1;
    pageSize: number = 10;
    total: number = 0;
    loading = false;
    statusOptions: any[] = BUSINESS_STATUS;
    progressingTimer: any[] = [];
    terminateStart: any[] = [];
    businessOrderShow: boolean = false;
    getCSMFBusinessList() {
        this.loading = true;
        this.listOfData = [];
        let paramsObj = {
            status: this.selectedValue.toLocaleLowerCase(),
            pageNo: this.pageIndex,
            pageSize: this.pageSize
        };
        this.myhttp.getCSMFSlicingBusinessList(paramsObj).subscribe(res => {
            const { result_header: { result_code }, result_body: { slicing_order_list, record_number } } = res;
            this.loading = false;
            if (+result_code === 200) {
                this.total = record_number;
                if (slicing_order_list !== null && slicing_order_list.length > 0) {
                    this.listOfData = slicing_order_list.map((item, index) => {
                        item.order_creation_time = moment(Number(item.order_creation_time)).format('YYYY-MM-DD HH:mm:ss');
                        if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
                            let updata = (prodata: { operation_progress: string }) => {
                                item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
                            };
                            let obj = {
                                serviceId: item.order_id
                            };
                            if (item.last_operation_type === 'DELETE') this.terminateStart[index] = true
                            else this.terminateStart[index] = false;
                            this.queryProgress(obj, index, updata).then((res) => {
                                item.last_operation_progress = '100';
                                this.getCSMFBusinessList();
                            })
                        }
                        return item
                    });
                }
            }
        })
    }

    getListOfProcessingStatus() {
        this.pageIndex = 1;
        this.pageSize = 10;
        this.progressingTimer.forEach((item) => {
            clearInterval(item.timer);
        });
        this.progressingTimer = [];
        this.getCSMFBusinessList();
    }

    searchData(reset: boolean = false) {
        this.progressingTimer.forEach((item) => {
            clearInterval(item.timer);
        });
        this.progressingTimer = [];
        this.getCSMFBusinessList();
    }

    switchChange(slicing, i) {
        // console.log(slicing, i, "slicing");
        this.modalService.confirm({
            nzTitle: '<i>Are you sure you want to perform this task?</i>',
            nzContent: '<b>Name:' + slicing.order_name + '</b>',
            nzOnOk: () => {
                let paramsObj = {
                    serviceId: slicing.order_id
                };
                if (slicing.order_status === 'activated') {
                    this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
                } else {
                    this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
                }
            },
            nzCancelText: 'No',
            nzOnCancel: () => {
                let singleSlicing = Object.assign({}, this.listOfData[i]);
                this.listOfData[i] = singleSlicing;
                this.listOfData = [...this.listOfData];
            }
        });
    }
    changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
        this.loading = true;
        this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
            const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
            this.loading = false;
            if (+result_code === 200) {
                this.getCSMFBusinessList();
            } else {
                let singleSlicing = Object.assign({}, this.listOfData[index]);
                this.listOfData[index] = singleSlicing;
                this.listOfData = [...this.listOfData];
                this.getCSMFBusinessList();
            }
            this.getCSMFBusinessList();
        }, () => {
            this.loading = false;
            let singleSlicing = Object.assign({}, this.listOfData[index]);
            this.listOfData[index] = singleSlicing;
            this.listOfData = [...this.listOfData];
            this.getCSMFBusinessList();
        })
    }

    terminate(slicing, index) {
        this.modalService.confirm({
            nzTitle: 'Are you sure you want to terminate this task?',
            nzContent: '<b>Name:&nbsp;</b>' + slicing.order_name,
            nzOnOk: () => {
                let paramsObj = { serviceId: slicing.order_id };
                this.terminateStart[index] = true;
                this.loading = true;
                this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
                    const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
                    this.loading = false;
                    if (+result_code === 200) {
                        this.getCSMFBusinessList();
                    } else {
                        this.terminateStart[index] = false;
                    }
                }, () => {
                    this.loading = false;
                    this.terminateStart[index] = false;
                })
            },
            nzCancelText: 'No',
            nzOnCancel: () => {
                console.info('Cancel termination')
            }
        });
    }
    queryProgress(obj, index, callback) {
        return new Promise(res => {
            let requery = () => {
                this.myhttp.getSlicingBusinessProgress(obj)
                    .subscribe((data) => {
                        const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
                        if (+result_code === 200) {
                            if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
                                callback(data.result_body);
                                let progressSetTimeOut = setTimeout(() => {
                                    requery();
                                }, 5000);
                                this.progressingTimer.push({
                                    id: obj.serviceId,
                                    timer: progressSetTimeOut
                                })
                            } else {
                                this.progressingTimer.forEach((item) => {
                                    if (item.serviceId === obj.serviceId) {
                                        clearInterval(item.timer);
                                    }
                                });
                                res(data.result_body);
                            }
                        } else {
                            this.progressingTimer.forEach((item) => {
                                if (item.serviceId === obj.serviceId) {
                                    clearInterval(item.timer);
                                }
                            });
                            this.getCSMFBusinessList();
                            this.message.error(result_message);
                        }
                    }, (err) => {
                        this.progressingTimer.forEach((item) => {
                            if (item.serviceId === obj.serviceId) {
                                clearInterval(item.timer);
                            }
                        });
                        this.getCSMFBusinessList();
                        this.message.error(err);
                    })
            };
            requery();
        })
    }

    OrderModelShow() {
        this.businessOrderShow = true;
    }
    orderModelClose($event) {
        this.businessOrderShow = $event;
        this.getCSMFBusinessList();
    }
}