4c60cd9ad9e37ca1118778849cef271562e8f23f
[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   // used for picking some key-value pairs from a object. 
90   pick(obj, arr): Object {
91     return arr.reduce((iter, val) => {
92       if(val in obj) {
93         iter[val] = obj[val];
94       }
95       return iter;
96     }, {});
97   }
98
99   getautidInfo(): void {
100     this.http.getAuditInfo(this.taskId).subscribe( res => {
101       const { result_header: { result_code, result_message } } = res;
102       this.isSpinning = false;
103       if (+result_code === 200) {
104         const {
105           business_demand_info,
106           nst_info,
107           nsi_nssi_info,
108           ...checkInfo
109         } = res.result_body;
110         // 处理配置审核详情数据
111         this.checkDetail = [{...checkInfo, 'service_snssai': business_demand_info.service_snssai}];
112         // 业务需求信息数据
113         business_demand_info.area = business_demand_info.coverage_area_ta_list.map(item => {
114           item = item.split(';').join(' - ')
115           return item
116         })
117         // 前端模拟数据
118         let areaList = ["Haidian District;Beijing;Beijing", "Xicheng District;Beijing;Beijing", "Changping District;Beijing;Beijing"].map(item => {
119           item = item.split(';').join(' - ')
120           return item
121         })
122         this.businessRequirement = [{ ...business_demand_info, area: areaList }];
123         // 匹配NST信息
124         this.NSTinfo = [nst_info];
125         // 共享切片实例
126         this.selectedServiceId = nsi_nssi_info.suggest_nsi_id;
127         this.selectedServiceName = nsi_nssi_info.suggest_nsi_name;
128         if (!this.selectedServiceId || !this.selectedServiceName) {
129           this.isDisabled = false;
130         }
131         this.slicingInstances = {
132           currentPage: '1',
133           pageSize: '10',
134           isLoading: false,
135           total: 0,
136           flag: false,
137           list: [{
138             service_instance_id: this.selectedServiceId,
139             service_instance_name: this.selectedServiceName
140           }]
141         }
142         // 子网实例
143         let subnetData = this.pick(nsi_nssi_info, ['an_suggest_nssi_id', 'an_suggest_nssi_name', 'tn_suggest_nssi_id', 'tn_suggest_nssi_name', 'cn_suggest_nssi_id', 'cn_suggest_nssi_name']);
144         this.subnetDataFormatting(subnetData, 0);
145         // 前端模拟数据
146         let area = ["Beijing;Beijing;Haidian District", "Beijing;Beijing;Xicheng District", "Beijing;Beijing;Changping District"]
147         // this.slicingSubnet[0].params = { an_latency, an_5qi, an_coverage_area_ta_list } 
148         // this.slicingSubnet[0].params = { an_latency, an_5qi, an_script_name, an_coverage_area_ta_list: area }
149         this.slicingSubnet[1].params = this.pick(nsi_nssi_info, ['tn_latency', 'tn_bandwidth', 'tn_script_name', 'tn_jitter', 'tn_service_snssai']);
150         this.slicingSubnet[0].params = this.slicingSubnet[2].params = {...this.pick(nsi_nssi_info, [
151           'cn_service_snssai',
152           'cn_resource_sharing_level',
153           'cn_ue_mobility_level',
154           'cn_latency',
155           'cn_max_number_of_ues',
156           'cn_activity_factor',
157           'cn_exp_data_rate_dl',
158           'cn_exp_data_rate_ul',
159           'cn_area_traffic_cap_dl',
160           'cn_area_traffic_cap_ul',
161           'cn_script_name',
162           'cn_overalluser_density',
163           // cn_ip_address,
164           // cn_logical_link,
165           // cn_nexthop_info,
166         ]), an_coverage_area_ta_list: area};
167       } else {
168         this.message.error(result_message || 'Failed to get data')
169       }
170     }, ({ status, statusText }) => {
171       this.message.error(status + ' (' + statusText + ')');
172       this.isSpinning = false;
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_message }, 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(result_message || 'Failed to get slicing instance ID')
205         }
206         this.slicingInstances.isLoading = false;
207         this.slicingInstances.flag = false;
208       }, 2000)
209     }, ({ status, statusText }) => {
210       this.message.error(status + ' (' + statusText + ')');
211       this.slicingInstances.isLoading = false;
212       this.slicingInstances.flag = false;
213     })
214   }
215
216
217   slicingInstanceChange(): void { // choose the target nssi
218     this.isDisabled = true;
219     this.selectedServiceName = '';
220     // 获取切片子网实例数据
221     this.http.getSlicingSubnetInstance(this.selectedServiceId).subscribe(res => {
222       const { result_header: { result_code, result_message }, result_body, record_number} = res;
223       if (+result_code === 200) {
224         this.subnetDataFormatting(result_body, record_number)
225       } else {
226         this.subnetDataFormatting({}, 1);
227         this.message.error(result_message || 'Failed to get slicing subnet instance ID')
228       }
229     }, ({ status, statusText }) => {
230       this.message.error(status + ' (' + statusText + ')');
231     })
232     this.slicingInstances.list.forEach(item => {
233       if (item.service_instance_id === this.selectedServiceId) {
234         this.selectedServiceName = item.service_instance_name;
235       }
236     })
237   }
238
239   subnetDataFormatting ( subnetData?: any, total?: number): void{
240     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;
241     this.slicingSubnet[0].slicingId = an_suggest_nssi_id;
242     this.slicingSubnet[0].slicingName = an_suggest_nssi_name;
243     this.slicingSubnet[0].total = total;
244     this.slicingSubnet[0].currentPage = '1';
245     this.slicingSubnet[0].instances = [{
246       service_instance_id: an_suggest_nssi_id,
247       service_instance_name: an_suggest_nssi_name
248     }];
249
250     this.slicingSubnet[1].slicingId = tn_suggest_nssi_id;
251     this.slicingSubnet[1].slicingName = tn_suggest_nssi_name;
252     this.slicingSubnet[1].total = total;
253     this.slicingSubnet[1].currentPage = '1';
254     this.slicingSubnet[1].instances = [{
255       service_instance_id: tn_suggest_nssi_id,
256       service_instance_name: tn_suggest_nssi_name
257     }];
258
259     this.slicingSubnet[2].slicingId = cn_suggest_nssi_id;
260     this.slicingSubnet[2].slicingName = cn_suggest_nssi_name;
261     this.slicingSubnet[2].total = total;
262     this.slicingSubnet[2].currentPage = '1';
263     this.slicingSubnet[2].instances = [{
264       service_instance_id: cn_suggest_nssi_id,
265       service_instance_name: cn_suggest_nssi_name
266     }];
267   }
268
269   resetSlicingInstance(): void {
270     this.selectedServiceId = '';
271     this.selectedServiceName = '';
272     this.slicingSubnet.map(item => {
273       item.slicingId = '';
274       item.slicingName = '';
275     })
276     this.isDisabled = false;
277   }
278
279   openSubnetInstances(bool: boolean, instance: any): void {
280     if (bool && !instance.total) {
281       instance.instances = []
282       this.getSubnetInstances(instance)
283     }
284   }
285
286   getNextPageSubnet(instance: any): void {
287     const { total, currentPage, pageSize } = instance;
288     if (total - (+currentPage * +pageSize) > 0) {
289       if (instance.flag) return;
290       instance.flag = true;
291       this.getSubnetInstances(instance);
292       let count = +instance.currentPage;
293       instance.currentPage = (++count).toString();
294     }
295   }
296
297   getSubnetInstances(instance: any): void {
298     instance.isLoading = true;
299     const { context, currentPage, pageSize } = instance;
300     this.http.getSubnetInContext(context, currentPage, pageSize).subscribe(res => {
301       const { result_header: { result_code, result_message }, result_body } = res;
302       if (+result_code === 200) {
303         const { nssi_service_instances, record_number } = result_body;
304         this.slicingSubnet.map(item => {
305           if (item.context === context) {
306             item.total = record_number;
307             item.instances.push(...nssi_service_instances);
308           }
309         })
310       } else {
311         this.message.error(result_message || 'Failed to get slicing subnet instance ID');
312       }
313       instance.isLoading = false;
314       instance.flag = false;
315     }, ({ status, statusText }) => {
316       this.message.error(status + ' (' + statusText + ')');
317       instance.isLoading = false;
318       instance.flag = false;
319     })
320   }
321
322   slicingSubnetChange(instance: any): void {
323     instance.slicingName = ''
324     instance.instances.forEach(item => {
325       if (instance.slicingId === item.service_instance_id) {
326         instance.slicingName = item.service_instance_name;
327       }
328     })
329   }
330
331   restSubnetInstance(instance: any): void {
332     instance.slicingId = '';
333     instance.slicingName = '';
334   }
335
336   showParamsModel(item: any): void {
337     console.log(item,"------->")
338     this.isShowParams = true;
339     this.paramsTitle = item.title;
340     this.params = item.params
341   }
342
343   changeParams(params: any): void {
344     const index = this.paramsTitle === 'An' ? 0 : (this.paramsTitle === 'Tn' ? 1 : 2);
345     this.slicingSubnet[index].params = params
346   }
347
348   handleCancel(bool: boolean = false) {
349     this.showDetail = false;
350     this.cancel.emit({ showDetail: this.showDetail, bool });
351   }
352   handleOk() {
353     this.loading = true;
354     const { selectedServiceId, selectedServiceName, slicingSubnet, checkDetail, businessRequirement, NSTinfo } = this;
355     const nsi_nssi_info: object = {
356       suggest_nsi_id: selectedServiceId,
357       suggest_nsi_name: selectedServiceName,
358       an_suggest_nssi_id: slicingSubnet[0].slicingId,
359       an_suggest_nssi_name: slicingSubnet[0].slicingName,
360       ...slicingSubnet[0].params,
361       tn_suggest_nssi_id: slicingSubnet[1].slicingId,
362       tn_suggest_nssi_name: slicingSubnet[1].slicingName,
363       ...slicingSubnet[1].params,
364       cn_suggest_nssi_id: slicingSubnet[2].slicingId,
365       cn_suggest_nssi_name: slicingSubnet[2].slicingName,
366       ...slicingSubnet[2].params,
367     }
368     delete businessRequirement[0].area
369     let reqBody = { ...checkDetail[0], business_demand_info: businessRequirement[0], nst_info: NSTinfo[0], nsi_nssi_info };
370     delete reqBody.service_snssai;
371     this.http.submitSlicing(reqBody).subscribe(res => {
372       const { result_header: { result_code } } = res;
373       if (+result_code === 200) {
374         this.notification1.notificationSuccess('Task', 'Sumbit', this.taskId)
375       } else {
376         this.notification1.notificationFailed('Task', 'Sumbit', this.taskId)
377       }
378       this.loading = false;
379       this.handleCancel(true);
380     }, ({ status, statusText }) => {
381       this.message.error(status + ' (' + statusText + ')');
382       this.loading = false;
383     })
384   }
385 }