d47618a50b4d5c28063173d1f787e81d008fae8b
[usecase-ui.git] /
1 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import { SlicingTaskServices } from '../../../../../core/services/slicingTaskServices'
4
5 @Component({
6         selector: 'app-check-process-model',
7         templateUrl: './check-process-model.component.html',
8         styleUrls: ['./check-process-model.component.less']
9 })
10 export class CheckProcessModelComponent implements OnInit {
11
12         @Input() moduleTitle: string;
13         @Input() showProcess: boolean;
14         @Input() taskId: string;
15
16         @Output() cancel = new EventEmitter<boolean>();
17
18         constructor(private http: SlicingTaskServices, private message: NzMessageService) { }
19
20         checkDetail: any[];
21         businessRequirement: any[];
22         NSTinfo: any[];
23         data: any[];
24         currentProgress: number = 1;
25         timer: any = null;
26         isSpinning: boolean = false;
27         isGetData: boolean = false;
28
29         ngOnInit() { }
30
31         ngOnChanges() {
32                 if (this.showProcess) {
33                         this.isSpinning = true;
34                         this.getInfo();
35                         this.getProgress();
36                 }else {
37                         clearTimeout(this.timer);
38                         this.isGetData = false;
39                 }
40         }
41
42         getInfo(): void {
43                 this.http.getSlicingBasicInfo(this.taskId).subscribe(res => {
44                         if (this.isGetData) {
45                                 this.isSpinning = false;
46                         } else {
47                                 this.isGetData = true;
48                         }
49                         const { result_body, result_header: { result_code } } = res;
50                         if (+result_code === 200) {
51                                 const {
52                                         task_id,
53                                         task_name,
54                                         create_time,
55                                         processing_status,
56                                         business_demand_info,
57                                         nst_info,
58                                         business_demand_info: { service_snssai, coverage_area_ta_list }
59                                 } = result_body;
60                                 // 处理配置审核详情数据
61                                 this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }];
62                                 // 业务需求信息数据
63                                 business_demand_info.area = coverage_area_ta_list.map(item => {
64                                         item = item.split(';').join('-')
65                                         return item
66                                 })
67                                 this.businessRequirement = [business_demand_info];
68                                 // 匹配NST信息
69                                 this.NSTinfo = [nst_info];
70                         } else {
71                                 const errorMessage = this.moduleTitle === '切片创建中' ? 'Failed to get data' : 'Viewing results failed';
72                                 this.message.error(errorMessage)
73                         }
74                 })
75         }
76
77         getProgress(): void {
78                 this.http.getSlicingCreateProgress(this.taskId).subscribe(res => {
79                         if (this.isGetData) {
80                                 this.isSpinning = false;
81                         } else {
82                                 this.isGetData = true;
83                         }
84                         const { result_body, result_header: {result_code } } = res;
85                         if (+result_code === 200) {
86                                 this.data = [];
87                                 Object.keys(result_body).forEach( item => {
88                                         let currentProgress = 1
89                                         let status = 'process';
90                                         if(+result_body[item] === 100){
91                                                 currentProgress = 2;
92                                                 status = 'finish'
93                                         }
94                                         const title = item === 'an_progress'? 'An': (item === 'tn_progress'? 'Tn' : 'Cn')
95                                         let obj = { [item]: result_body[item], currentProgress, title, status };
96                                         this.data.push(obj)
97                                 })
98                                 this.data = [this.data];
99                                 let flag: boolean = false;
100                                 Object.values(result_body).forEach ( item => {
101                                         if(item !== 100) {
102                                                 flag = true;
103                                         }
104                                 })
105                                 if(flag) {
106                                         this.timer = setTimeout( () => {
107                                                 this.getProgress()
108                                         }, 5000)
109                                 }
110                         } else {
111                                 this.message.error('Failed to get progress')
112                         }
113                 })
114         }
115
116         handleCancel() {
117                 this.showProcess = false;
118                 this.cancel.emit(this.showProcess)
119         }
120 }
121