c6d75a304d8981709fd696dbacac924cd4fd62f5
[usecase-ui.git] /
1 import {
2         Component,
3         OnInit,
4         Input,
5         Output,
6         EventEmitter,
7         ViewChild,
8 } from "@angular/core";
9 import { SlicingTaskServices } from "@src/app/core/services/slicingTaskServices";
10 import { indexDebugNode } from "@angular/core/src/debug/debug_node";
11
12 @Component({
13         selector: "app-slicing-task-model",
14         templateUrl: "./slicing-task-model.component.html",
15         styleUrls: ["./slicing-task-model.component.less"],
16 })
17 export class SlicingTaskModelComponent implements OnInit {
18         @Input() showDetail: boolean;
19         @Input() moduleTitle: string;
20         @Input() taskId: string;
21         @Output() cancel = new EventEmitter<object>();
22         @ViewChild("notification") notification1: any;
23
24         constructor(private http: SlicingTaskServices) {}
25
26         // 配置审核详情
27         checkDetail: any[] = [{}];
28         //业务需求信息
29         businessRequirement: any[] = [];
30         //匹配NST信息
31         NSTinfo: object[] = [{}];
32         // 共享切片实例
33         selectedServiceId: string;
34         selectedServiceName: string;
35         slicingInstances: any;
36         //an/tn/cn instances NSSI ID下拉框的开关
37         enableNSSISelectionList: any[] = [];
38         // 子网实例
39         slicingSubnet: any[] = [
40                 {
41                         title: "An",
42                         context: "an",
43                         slicingId: "",
44                         slicingName: "",
45                         total: 0,
46                         currentPage: "1",
47                         pageSize: "10",
48                         isLoading: false,
49                         flag: false,
50                         instances: [],
51                 },
52                 {
53                         title: "Tn",
54                         context: "tn",
55                         slicingId: "",
56                         slicingName: "",
57                         total: 0,
58                         currentPage: "1",
59                         pageSize: "10",
60                         isLoading: false,
61                         flag: false,
62                         instances: [],
63                 },
64                 {
65                         title: "Cn",
66                         context: "cn",
67                         slicingId: "",
68                         slicingName: "",
69                         total: 0,
70                         currentPage: "1",
71                         pageSize: "10",
72                         isLoading: false,
73                         flag: false,
74                         instances: [],
75                 },
76         ];
77         isDisabled: any = [true, true, true];
78         // 子网参数
79         isShowParams: boolean;
80         paramsTitle: string;
81         params: any;
82         noPassPara: string[] = [];
83         // 获取数据loading
84         isSpinning: boolean = false;
85         loading: boolean = false;
86
87         ngOnInit() {}
88
89         ngOnChanges() {
90                 if (this.showDetail) {
91                         this.isSpinning = true;
92                         this.getautidInfo();
93                 } else {
94                         this.isDisabled.map((item) => {
95                                 item = true;
96                         });
97                 }
98         }
99
100         // used for picking some key-value pairs from a object.
101         pick(obj, arr): Object {
102                 return arr.reduce((iter, val) => {
103                         if (val in obj) {
104                                 iter[val] = obj[val];
105                         }
106                         return iter;
107                 }, {});
108         }
109
110         getautidInfo(): void {
111                 let getAuditInfoFailedCallback = () => {
112                         this.isSpinning = false;
113                 };
114                 this.http
115                         .getAuditInfo(this.taskId, getAuditInfoFailedCallback)
116                         .then((res) => {
117                                 this.isSpinning = false;
118                                 const {
119                                         business_demand_info,
120                                         nst_info,
121                                         nsi_nssi_info,
122                                         ...checkInfo
123                                 } = res.result_body;
124                                 // 处理配置审核详情数据
125                                 this.checkDetail = [
126                                         {
127                                                 ...checkInfo,
128                                                 service_snssai: business_demand_info.service_snssai,
129                                         },
130                                 ];
131                                 // 业务需求信息数据
132                                 if (business_demand_info.coverage_area_ta_list !== null) {
133                                         business_demand_info.area = business_demand_info.coverage_area_ta_list.map(
134                                                 (item) => {
135                                                         item = item.split(";").join(" - ");
136                                                         return item;
137                                                 }
138                                         );
139                                 } else {
140                                         business_demand_info.area = [];
141                                 }
142                                 // 前端模拟数据
143                                 let areaList = [
144                                         "Haidian District;Beijing;Beijing",
145                                         "Xicheng District;Beijing;Beijing",
146                                         "Changping District;Beijing;Beijing",
147                                 ].map((item) => {
148                                         item = item.split(";").join(" - ");
149                                         return item;
150                                 });
151                                 this.businessRequirement = [
152                                         { ...business_demand_info, area: areaList },
153                                 ];
154                                 // 匹配NST信息
155                                 this.NSTinfo = [nst_info];
156                                 // 共享切片实例
157                                 this.selectedServiceId = nsi_nssi_info.suggest_nsi_id;
158                                 this.selectedServiceName = nsi_nssi_info.suggest_nsi_name;
159                                 // an/tn/cn 3 select box switches parameters of Matching Shared NSSI
160                                 this.enableNSSISelectionList = [
161                                         nsi_nssi_info.an_enableNSSISelection,
162                                         nsi_nssi_info.tn_bh_enableNSSISelection,
163                                         nsi_nssi_info.cn_enableNSSISelection,
164                                 ];
165                                 if (!this.selectedServiceId || !this.selectedServiceName) {
166                                         this.isDisabled.map((item, index) => {
167                                                 this.isDisabled[index] = false;
168                                         });
169                                 }
170                                 this.isDisabled.map((item, index) => {
171                                         if (this.enableNSSISelectionList[index]) {
172                                                 this.isDisabled[index] = false;
173                                         }
174                                 });
175                                 this.slicingInstances = {
176                                         currentPage: "1",
177                                         pageSize: "10",
178                                         isLoading: false,
179                                         total: 0,
180                                         flag: false,
181                                         list: [
182                                                 {
183                                                         service_instance_id: this.selectedServiceId,
184                                                         service_instance_name: this.selectedServiceName,
185                                                 },
186                                         ],
187                                 };
188                                 // 子网实例
189                                 let subnetData = this.pick(nsi_nssi_info, [
190                                         "an_suggest_nssi_id",
191                                         "an_suggest_nssi_name",
192                                         "tn_bh_suggest_nssi_id",
193                                         "tn_bh_suggest_nssi_name",
194                                         "cn_suggest_nssi_id",
195                                         "cn_suggest_nssi_name",
196                                 ]);
197                                 this.subnetDataFormatting(subnetData, 0);
198                                 // 前端模拟数据
199                                 let area = [
200                                         "Beijing;Beijing;Haidian District",
201                                         "Beijing;Beijing;Xicheng District",
202                                         "Beijing;Beijing;Changping District",
203                                 ];
204                                 this.slicingSubnet[0].params = {
205                                         ...this.pick(nsi_nssi_info, [
206                                                 "sliceProfile_AN_sNSSAI",
207                                                 "sliceProfile_AN_resourceSharingLevel",
208                                                 "sliceProfile_AN_uEMobilityLevel",
209                                                 "an_latency",
210                                                 "sliceProfile_AN_maxNumberofUEs",
211                                                 "sliceProfile_AN_activityFactor",
212                                                 "sliceProfile_AN_expDataRateDL",
213                                                 "sliceProfile_AN_expDataRateUL",
214                                                 "sliceProfile_AN_areaTrafficCapDL",
215                                                 "sliceProfile_AN_areaTrafficCapUL",
216                                                 "an_script_name",
217                                                 "sliceProfile_AN_overallUserDensity",
218                                                 "an_enableNSSISelection",
219                                                 "sliceProfile_AN_maxNumberofPDUSession",
220                                         ]),
221                                         an_coverage_area_ta_list: area,
222                                 };
223                                 this.slicingSubnet[1].params = this.pick(nsi_nssi_info, [
224                                         "tn_bh_latency",
225                                         "tn_bh_bandwidth",
226                                         "tn_bh_script_name",
227                                         "sliceProfile_TN_BH_jitte",
228                                         "sliceProfile_TN_BH_sNSSAI",
229                                         "tn_bh_enableNSSISelection",
230                                         "sliceProfile_TN_resourceSharingLevel",
231                                         "sliceProfile_CN_logicInterfaceId",
232                                         "sliceProfile_CN_ipAddress",
233                                         "sliceProfile_CN_nextHopInfo",
234                                         "sliceProfile_AN_ipAddress",
235                                         "sliceProfile_AN_logicInterfaceId",
236                                         "sliceProfile_AN_nextHopInfo",
237                                         "sliceProfile_TN_connection_links",
238                                 ]);
239                                 this.slicingSubnet[2].params = {
240                                         ...this.pick(nsi_nssi_info, [
241                                                 "cn_service_snssai",
242                                                 "cn_resource_sharing_level",
243                                                 "cn_ue_mobility_level",
244                                                 "cn_latency",
245                                                 "cn_max_number_of_ues",
246                                                 "cn_activity_factor",
247                                                 "cn_exp_data_rate_dl",
248                                                 "cn_exp_data_rate_ul",
249                                                 "cn_area_traffic_cap_dl",
250                                                 "cn_area_traffic_cap_ul",
251                                                 "cn_script_name",
252                                                 "sliceProfile_CN_overallUserDensity",
253                                                 "cn_enableNSSISelection",
254                                                 "sliceProfile_CN_maxNumberofPDUSession",
255                                         ]),
256                                 };
257                         });
258         }
259
260         openSlicingInstance(bool: boolean): void {
261                 const { total, currentPage, pageSize } = this.slicingInstances;
262                 if (bool && !total) {
263                         this.slicingInstances.list = [];
264                         this.getSlicingInstances(currentPage, pageSize);
265                 }
266         }
267
268         getNextPageData(): void {
269                 const { total, currentPage, pageSize } = this.slicingInstances;
270                 if (total - +currentPage * +pageSize > 0) {
271                         if (this.slicingInstances.flag) return;
272                         this.slicingInstances.flag = true;
273                         this.getSlicingInstances(currentPage, pageSize);
274                         this.slicingInstances.currentPage = (
275                                 +this.slicingInstances.currentPage + 1
276                         ).toString();
277                 }
278         }
279
280         getSlicingInstances(pageNo: string, pageSize: string): void {
281                 this.slicingInstances.isLoading = true;
282                 let getSlicingInstanceFailedCallback = () => {
283                         this.slicingInstances.isLoading = false;
284                         this.slicingInstances.flag = false;
285                 };
286                 this.http
287                         .getSlicingInstance(
288                                 pageNo,
289                                 pageSize,
290                                 getSlicingInstanceFailedCallback
291                         )
292                         .then((res) => {
293                                 const { result_body } = res;
294                                 setTimeout(() => {
295                                         const {
296                                                 nsi_service_instances,
297                                                 record_number,
298                                         } = result_body;
299                                         this.slicingInstances.total = record_number;
300                                         this.slicingInstances.list.push(...nsi_service_instances);
301                                         this.slicingInstances.isLoading = false;
302                                         this.slicingInstances.flag = false;
303                                 }, 2000);
304                         });
305         }
306
307         slicingInstanceChange(): void {
308                 // choose the target nssi
309                 this.isDisabled.map((item, index) => {
310                         if (!this.enableNSSISelectionList[index]) {
311                                 this.isDisabled[index] = true;
312                         }
313                 });
314                 this.selectedServiceName = "";
315                 // 获取切片子网实例数据
316
317                 let getSlicingSubnetInstanceFailedCallback = () => {
318                         this.subnetDataFormatting({}, 1);
319                 };
320                 this.http
321                         .getSlicingSubnetInstance(
322                                 this.selectedServiceId,
323                                 getSlicingSubnetInstanceFailedCallback
324                         )
325                         .then((res) => {
326                                 const { result_body, record_number } = res;
327                                 this.subnetDataFormatting(result_body, record_number);
328                         });
329                 this.slicingInstances.list.forEach((item) => {
330                         if (item.service_instance_id === this.selectedServiceId) {
331                                 this.selectedServiceName = item.service_instance_name;
332                         }
333                 });
334         }
335
336         subnetDataFormatting(subnetData?: any, total?: number): void {
337                 const {
338                         an_suggest_nssi_id,
339                         an_suggest_nssi_name,
340                         tn_bh_suggest_nssi_id,
341                         tn_bh_suggest_nssi_name,
342                         cn_suggest_nssi_id,
343                         cn_suggest_nssi_name,
344                 } = subnetData;
345                 this.slicingSubnet[0].slicingId = an_suggest_nssi_id;
346                 this.slicingSubnet[0].slicingName = an_suggest_nssi_name;
347                 this.slicingSubnet[0].total = total;
348                 this.slicingSubnet[0].currentPage = "1";
349                 this.slicingSubnet[0].instances = [
350                         {
351                                 service_instance_id: an_suggest_nssi_id,
352                                 service_instance_name: an_suggest_nssi_name,
353                         },
354                 ];
355
356                 this.slicingSubnet[1].slicingId = tn_bh_suggest_nssi_id;
357                 this.slicingSubnet[1].slicingName = tn_bh_suggest_nssi_name;
358                 this.slicingSubnet[1].total = total;
359                 this.slicingSubnet[1].currentPage = "1";
360                 this.slicingSubnet[1].instances = [
361                         {
362                                 service_instance_id: tn_bh_suggest_nssi_id,
363                                 service_instance_name: tn_bh_suggest_nssi_name,
364                         },
365                 ];
366
367                 this.slicingSubnet[2].slicingId = cn_suggest_nssi_id;
368                 this.slicingSubnet[2].slicingName = cn_suggest_nssi_name;
369                 this.slicingSubnet[2].total = total;
370                 this.slicingSubnet[2].currentPage = "1";
371                 this.slicingSubnet[2].instances = [
372                         {
373                                 service_instance_id: cn_suggest_nssi_id,
374                                 service_instance_name: cn_suggest_nssi_name,
375                         },
376                 ];
377         }
378
379         resetSlicingInstance(): void {
380                 this.selectedServiceId = "";
381                 this.selectedServiceName = "";
382                 this.slicingSubnet.map((item) => {
383                         item.slicingId = "";
384                         item.slicingName = "";
385                 });
386                 this.isDisabled.map((item, index) => {
387                         this.isDisabled[index] = false;
388                 });
389         }
390
391         openSubnetInstances(bool: boolean, instance: any): void {
392                 if (bool && !instance.total) {
393                         instance.instances = [];
394                         this.getSubnetInstances(instance);
395                 }
396         }
397
398         getNextPageSubnet(instance: any): void {
399                 const { total, currentPage, pageSize } = instance;
400                 if (total - +currentPage * +pageSize > 0) {
401                         if (instance.flag) return;
402                         instance.flag = true;
403                         this.getSubnetInstances(instance);
404                         let count = +instance.currentPage;
405                         instance.currentPage = (++count).toString();
406                 }
407         }
408
409         getSubnetInstances(instance: any): void {
410                 instance.isLoading = true;
411                 const { context, currentPage, pageSize } = instance;
412                 let getSubnetInContextFailedCallback = () => {
413                         instance.isLoading = false;
414                         instance.flag = false;
415                 };
416                 this.http
417                         .getSubnetInContext(
418                                 context,
419                                 currentPage,
420                                 pageSize,
421                                 getSubnetInContextFailedCallback
422                         )
423                         .then((res) => {
424                                 const { result_body } = res;
425                                 const { nssi_service_instances, record_number } = result_body;
426                                 this.slicingSubnet.map((item) => {
427                                         if (item.context === context) {
428                                                 item.total = record_number;
429                                                 item.instances.push(...nssi_service_instances);
430                                         }
431                                 });
432                                 instance.isLoading = false;
433                                 instance.flag = false;
434                         });
435         }
436
437         slicingSubnetChange(instance: any): void {
438                 instance.slicingName = "";
439                 instance.instances.forEach((item) => {
440                         if (instance.slicingId === item.service_instance_id) {
441                                 instance.slicingName = item.service_instance_name;
442                         }
443                 });
444         }
445
446         restSubnetInstance(instance: any): void {
447                 instance.slicingId = "";
448                 instance.slicingName = "";
449         }
450
451         showParamsModel(item: any): void {
452                 this.isShowParams = true;
453                 this.paramsTitle = item.title;
454                 this.params = item.params;
455         }
456
457         changeParams(params: any): void {
458                 const index =
459                         this.paramsTitle === "An" ? 0 : this.paramsTitle === "Tn" ? 1 : 2;
460                 this.slicingSubnet[index].params = params;
461         }
462         noPassParaChange(noPassPara: string[]): void {
463                 this.noPassPara = noPassPara;
464         }
465         handleCancel(bool: boolean = false) {
466                 this.showDetail = false;
467                 this.cancel.emit({ showDetail: this.showDetail, bool });
468         }
469         handleOk() {
470                 this.loading = true;
471                 const {
472                         selectedServiceId,
473                         selectedServiceName,
474                         slicingSubnet,
475                         checkDetail,
476                         businessRequirement,
477                         NSTinfo,
478                 } = this;
479                 // slicingSubnet[1] is about Tn,
480                 // Delete parameters that do not need to be passed
481                 if (this.noPassPara.length !== 0) {
482                         this.noPassPara.forEach((item) => {
483                                 for (let val in slicingSubnet[1].params) {
484                                         if (val === item) {
485                                                 delete slicingSubnet[1].params[val];
486                                         }
487                                 }
488                         });
489                 }
490                 const nsi_nssi_info: object = {
491                         suggest_nsi_id: selectedServiceId,
492                         suggest_nsi_name: selectedServiceName,
493                         an_suggest_nssi_id: slicingSubnet[0].slicingId,
494                         an_suggest_nssi_name: slicingSubnet[0].slicingName,
495                         ...slicingSubnet[0].params,
496                         tn_bh_suggest_nssi_id: slicingSubnet[1].slicingId,
497                         tn_bh_suggest_nssi_name: slicingSubnet[1].slicingName,
498                         ...slicingSubnet[1].params,
499                         cn_suggest_nssi_id: slicingSubnet[2].slicingId,
500                         cn_suggest_nssi_name: slicingSubnet[2].slicingName,
501                         ...slicingSubnet[2].params,
502                 };
503                 delete businessRequirement[0].area;
504                 let reqBody = {
505                         ...checkDetail[0],
506                         business_demand_info: businessRequirement[0],
507                         nst_info: NSTinfo[0],
508                         nsi_nssi_info,
509                 };
510                 delete reqBody.service_snssai;
511                 let submitSlicingFailedCallback = () => {
512                         this.loading = false;
513                         this.notification1.notificationFailed(
514                                 "Task",
515                                 "Sumbit",
516                                 this.taskId
517                         );
518                 };
519                 this.http
520                         .submitSlicing(reqBody, submitSlicingFailedCallback)
521                         .then((res) => {
522                                 this.notification1.notificationSuccess(
523                                         "Task",
524                                         "Sumbit",
525                                         this.taskId
526                                 );
527                                 this.loading = false;
528                                 this.handleCancel(true);
529                         });
530         }
531 }