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