33dec9956e3191685662f71f998e1963e0152fe7
[usecase-ui.git] /
1 import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import { SlicingTaskServices } from '../../../../../core/services/slicingTaskServices';
4
5 @Component({
6   selector: 'app-slicing-task-model',
7   templateUrl: './slicing-task-model.component.html',
8   styleUrls: ['./slicing-task-model.component.less']
9 })
10 export class SlicingTaskModelComponent implements OnInit {
11   @Input() showDetail: boolean;
12   @Input() moduleTitle: string;
13   @Input() taskId: string;
14   @Output() cancel = new EventEmitter<object>();
15   @ViewChild('notification') notification1: any;
16
17   constructor(private http: SlicingTaskServices, private message: NzMessageService) { }
18
19   // 配置审核详情
20   checkDetail: any[] = [{}];
21   //业务需求信息
22   businessRequirement: any[] = [];
23   //匹配NST信息 
24   NSTinfo: object[] = [{}];
25   // 共享切片实例
26   selectedServiceId: string;
27   selectedServiceName: string;
28   slicingInstances: any;
29   // 子网实例
30   slicingSubnet: any[] =  [
31     {
32       title: 'An',
33       context: 'an',
34       slicingId: '',
35       slicingName: '',
36       total: 0,
37       currentPage: '1',
38       pageSize: '10',
39       isLoading: false,
40       flag: false,
41       instances: []
42     },
43     {
44       title: 'Tn',
45       context: 'tn',
46       slicingId: '',
47       slicingName: '',
48       total: 0,
49       currentPage: '1',
50       pageSize: '10',
51       isLoading: false,
52       flag: false,
53       instances: []
54     },
55     {
56       title: 'Cn',
57       context: 'cn',
58       slicingId: '',
59       slicingName: '',
60       total: 0,
61       currentPage: '1',
62       pageSize: '10',
63       isLoading: false,
64       flag: false,
65       instances: []
66     }
67   ]
68   isDisabled: boolean = true;
69   // 子网参数
70   isShowParams: boolean;
71   paramsTitle: string;
72   params: any;
73   // 获取数据loading
74   isSpinning: boolean = false;
75   loading: boolean = false;
76   
77
78   ngOnInit() { }
79   
80   ngOnChanges() {
81     if (this.showDetail) {
82       this.isSpinning = true;
83       this.getautidInfo();
84     } else {
85       this.isDisabled = true;
86     }
87   }
88
89   getautidInfo(): void {
90     this.http.getAuditInfo(this.taskId).subscribe( res => {
91       const { result_header: { result_code } } = res;
92       this.isSpinning = false;
93       if (+result_code === 200) {
94         const { 
95           task_id, 
96           task_name, 
97           create_time, 
98           processing_status, 
99           business_demand_info, 
100           nst_info, 
101           nsi_nssi_info, 
102           business_demand_info: { service_snssai, coverage_area_ta_list } 
103         } = res.result_body;
104         const { 
105           suggest_nsi_id, 
106           suggest_nsi_name, 
107           an_suggest_nssi_id, 
108           an_suggest_nssi_name, 
109           tn_suggest_nssi_id, 
110           tn_suggest_nssi_name, 
111           cn_suggest_nssi_id, 
112           cn_suggest_nssi_name,
113           an_latency,
114           an_5qi,
115           an_coverage_area_ta_list, 
116           tn_latency,
117           tn_bandwidth,
118           cn_service_snssai,
119           cn_resource_sharing_level,
120           cn_ue_mobility_level,
121           cn_latency,
122           cn_max_number_of_ues,
123           cn_activity_factor,
124           cn_exp_data_rate_dl,
125           cn_exp_data_rate_ul,
126           cn_area_traffic_cap_dl,
127           cn_area_traffic_cap_ul
128         } = nsi_nssi_info;
129         // 处理配置审核详情数据
130         this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }];
131         // 业务需求信息数据
132         business_demand_info.area = coverage_area_ta_list.map(item => {
133           item = item.split(';').join('-')
134           return item
135         })
136         this.businessRequirement = [business_demand_info];
137         // 匹配NST信息
138         this.NSTinfo = [nst_info];
139         // 共享切片实例
140         this.selectedServiceId = suggest_nsi_id;
141         this.selectedServiceName = suggest_nsi_name;
142         this.slicingInstances = {
143           currentPage: '1',
144           pageSize: '10',
145           isLoading: false,
146           total: 0,
147           flag: false,
148           list: [{
149             service_instance_id: this.selectedServiceId,
150             service_instance_name: this.selectedServiceName
151           }]
152         }
153         // 子网实例
154         let subnetData = { an_suggest_nssi_id, an_suggest_nssi_name, tn_suggest_nssi_id, tn_suggest_nssi_name, cn_suggest_nssi_id, cn_suggest_nssi_name};
155         this.subnetDataFormatting(subnetData, 0);
156         this.slicingSubnet[0].params = { an_latency, an_5qi, an_coverage_area_ta_list } 
157         this.slicingSubnet[1].params = { tn_latency, tn_bandwidth };
158         this.slicingSubnet[2].params = { 
159           cn_service_snssai,
160           cn_resource_sharing_level,
161           cn_ue_mobility_level,
162           cn_latency,
163           cn_max_number_of_ues,
164           cn_activity_factor,
165           cn_exp_data_rate_dl,
166           cn_exp_data_rate_ul,
167           cn_area_traffic_cap_dl,
168           cn_area_traffic_cap_ul 
169         };
170       } else {
171         this.message.error('Failed to get data')
172       }
173     })
174   }
175
176   openSlicingInstance ( bool: boolean): void {
177     const { total, currentPage, pageSize} = this.slicingInstances;
178     if (bool && !total) {
179       this.slicingInstances.list = [];
180       this.getSlicingInstances(currentPage, pageSize)
181     }
182   }
183
184   getNextPageData ():void {
185     const { total, currentPage, pageSize} = this.slicingInstances;
186     if (total - (+currentPage * +pageSize) > 0 ) {
187       if (this.slicingInstances.flag) return;
188       this.slicingInstances.flag = true
189       this.getSlicingInstances(currentPage, pageSize)
190       this.slicingInstances.currentPage = (+this.slicingInstances.currentPage +1).toString();
191     }
192   }
193
194   getSlicingInstances(pageNo: string, pageSize: string): void {
195     this.slicingInstances.isLoading = true;
196     this.http.getSlicingInstance(pageNo, pageSize).subscribe ( res => {
197       const { result_header: { result_code }, result_body } = res;
198       setTimeout( () => {
199         if (+result_code === 200) {
200           const { nsi_service_instances, record_number } = result_body;
201           this.slicingInstances.total = record_number;
202           this.slicingInstances.list.push(...nsi_service_instances);
203         } else {
204           this.message.error('Failed to get slicing instance ID')
205         }
206         this.slicingInstances.isLoading = false;
207         this.slicingInstances.flag = false;
208       },2000)
209
210     })
211   }
212
213
214   slicingInstanceChange ():void {
215     this.isDisabled = true;
216     // 获取切片子网实例数据
217     this.http.getSlicingSubnetInstance(this.selectedServiceId).subscribe( res => {
218       const { result_header: { result_code }, result_body, record_number} = res;
219       if (+result_code === 200) {
220         this.subnetDataFormatting(result_body, record_number)
221       } else {
222         this.message.error('Failed to get slicing subnet instance ID')
223       }
224     }) 
225     this.slicingInstances.list.forEach (item => {
226       if (item.service_instance_id === this.selectedServiceId) {
227         this.selectedServiceName = item.service_instance_name;
228       }
229     })
230   }
231
232   subnetDataFormatting ( subnetData: any, total: number): void{
233     const { an_suggest_nssi_id, an_suggest_nssi_name, tn_suggest_nssi_id, tn_suggest_nssi_name, cn_suggest_nssi_id, cn_suggest_nssi_name } = subnetData;
234     this.slicingSubnet[0].slicingId = an_suggest_nssi_id;
235     this.slicingSubnet[0].slicingName = an_suggest_nssi_name;
236     this.slicingSubnet[0].total = total;
237     this.slicingSubnet[0].currentPage = '1'; 
238     this.slicingSubnet[0].instances = [{
239       service_instance_id: an_suggest_nssi_id,
240       service_instance_name: an_suggest_nssi_name
241     }];
242
243     this.slicingSubnet[1].slicingId = tn_suggest_nssi_id;
244     this.slicingSubnet[1].slicingName = tn_suggest_nssi_name;
245     this.slicingSubnet[1].total = total;
246     this.slicingSubnet[1].currentPage = '1'; 
247     this.slicingSubnet[1].instances =  [{
248       service_instance_id: tn_suggest_nssi_id,
249       service_instance_name: tn_suggest_nssi_name
250     }];
251
252     this.slicingSubnet[2].slicingId = cn_suggest_nssi_id;
253     this.slicingSubnet[2].slicingName = cn_suggest_nssi_name;
254     this.slicingSubnet[2].total = total;
255     this.slicingSubnet[2].currentPage = '1'; 
256     this.slicingSubnet[2].instances = [{
257       service_instance_id: cn_suggest_nssi_id,
258       service_instance_name: cn_suggest_nssi_name
259     }];
260   }
261
262   resetSlicingInstance (): void {
263     this.selectedServiceId = '';
264     this.selectedServiceName = '';
265     this.slicingSubnet.map( item => {
266       item.slicingId = '';
267       item.slicingName = '';
268     })
269     this.isDisabled = false;
270   }
271   
272   openSubnetInstances (bool: boolean, instance: any): void {
273     if(bool && !instance.total) {
274       instance.instances = []
275       this.getSubnetInstances(instance)
276     }
277   }
278
279   getNextPageSubnet (instance: any): void{
280     const { total, currentPage, pageSize} = instance;
281     if(total - (+currentPage * +pageSize) > 0 ){
282       if (instance.flag) return;
283       instance.flag = true;
284       this.getSubnetInstances(instance);
285       let count = +instance.currentPage;
286       instance.currentPage = (++count).toString();
287     }
288   }
289
290   getSubnetInstances (instance: any): void {
291     instance.isLoading = true;
292     const { context, currentPage, pageSize } = instance;
293     this.http.getSubnetInContext(context, currentPage, pageSize).subscribe( res => {
294       const { result_header: { result_code }, result_body } = res;
295       if (+result_code === 200) {
296         const { nssi_service_instances, record_number } = result_body;
297         this.slicingSubnet.map (item => {
298           if (item.context === context) {
299             item.total = record_number;
300             setTimeout(() => {
301               item.instances.push(...nssi_service_instances);
302               item.isLoading = false;
303               item.flag = false;
304             },2000)
305           }
306         })
307       } else {
308         this.message.error('Failed to get slicing subnet instance ID');
309       }
310     })
311   }
312
313   slicingSubnetChange (instance: any): void {
314     instance.instances.forEach( item => {
315       if (instance.slicingId === item.service_instance_id) {
316         instance.slicingName = item.service_instance_name; 
317       }
318     })
319   }
320
321   restSubnetInstance (instance: any): void {
322     instance.slicingId = '';
323     instance.slicingName = '';
324   }
325
326   showParamsModel (item: any): void {
327     this.isShowParams = true;
328     this.paramsTitle = item.title;
329     this.params = item.params
330   }
331
332   changeParams (params: any): void {
333     const index = this.paramsTitle === 'An' ? 0 : (this.paramsTitle === 'Tn' ? 1 : 2);
334     this.slicingSubnet[index].params = params
335   }
336
337   handleCancel(bool: boolean = false) {
338     this.showDetail = false;
339     this.cancel.emit({showDetail: this.showDetail, bool});
340   }
341   handleOk() {
342     this.loading = true;
343     const { selectedServiceId, selectedServiceName, slicingSubnet, checkDetail, businessRequirement, NSTinfo } = this;
344     const nsi_nssi_info: object = {
345       suggest_nsi_id:  selectedServiceId,
346       suggest_nsi_name: selectedServiceName,
347       an_suggest_nssi_id: slicingSubnet[0].slicingId,
348       an_suggest_nssi_name: slicingSubnet[0].slicingName,
349       ...slicingSubnet[0].params,
350       tn_suggest_nssi_id: slicingSubnet[1].slicingId,
351       tn_suggest_nssi_name: slicingSubnet[1].slicingName,
352       ...slicingSubnet[1].params,
353       cn_suggest_nssi_id: slicingSubnet[2].slicingId,
354       cn_suggest_nssi_name: slicingSubnet[2].slicingName,
355       ...slicingSubnet[2].params,
356     }
357     delete businessRequirement[0].area
358     let reqBody = {...checkDetail[0], business_demand_info: businessRequirement[0], nst_info: NSTinfo[0], nsi_nssi_info};
359     delete reqBody.service_snssai;
360     // this.notification1.notificationStart('Task', 'Sumbit', this.taskId)
361     this.http.submitSlicing(reqBody).subscribe (res => {
362       const { result_header: { result_code } } = res;
363       if (+result_code === 200) {
364         this.notification1.notificationSuccess('Task', 'Sumbit', this.taskId)
365       } else {
366         this.notification1.notificationFailed('Task', 'Sumbit', this.taskId)
367       }
368       this.loading = false;
369       this.handleCancel(true);
370     })
371   }
372 }