4656c32eb98d108c526ee28040ca36e78080729b
[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 }
59                                 } = result_body;
60                                 // 处理配置审核详情数据
61                                 this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }];
62                                 // 业务需求信息数据
63                                 this.businessRequirement = [business_demand_info];
64                                 // 匹配NST信息
65                                 this.NSTinfo = [nst_info];
66                         } else {
67                                 const errorMessage = this.moduleTitle === '切片创建中' ? 'Failed to get data' : 'Viewing results failed';
68                                 this.message.error(errorMessage)
69                         }
70                 })
71         }
72
73         getProgress(): void {
74                 this.http.getSlicingCreateProgress(this.taskId).subscribe(res => {
75                         if (this.isGetData) {
76                                 this.isSpinning = false;
77                         } else {
78                                 this.isGetData = true;
79                         }
80                         const { result_body, result_header: {result_code } } = res;
81                         if (+result_code === 200) {
82                                 this.data = [];
83                                 Object.keys(result_body).forEach( item => {
84                                         let currentProgress = 1
85                                         let status = 'process';
86                                         if(+result_body[item] === 100){
87                                                 currentProgress = 2;
88                                                 status = 'finish'
89                                         }
90                                         const title = item === 'an_progress'? '无线域': (item === 'tn_progress'? '传输域' : '核心域')
91                                         let obj = { [item]: result_body[item], currentProgress, title, status };
92                                         this.data.push(obj)
93                                 })
94                                 this.data = [this.data];
95                                 let flag: boolean = false;
96                                 Object.values(result_body).forEach ( item => {
97                                         if(item !== 100) {
98                                                 flag = true;
99                                         }
100                                 })
101                                 if(flag) {
102                                         this.timer = setTimeout( () => {
103                                                 this.getProgress()
104                                         }, 5000)
105                                 }
106                         } else {
107                                 this.message.error('Failed to get progress')
108                         }
109                 })
110         }
111
112         handleCancel() {
113                 this.showProcess = false;
114                 this.cancel.emit(this.showProcess)
115         }
116         handleOk() { 
117                 this.handleCancel();
118         }
119
120 }
121