Update ANR API to version 0.0.5
[portal/ric-dashboard.git] / webapp-frontend / src / app / signal / signal.component.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20 import { Component, OnInit, Inject } from '@angular/core';
21 import { LocalDataSource } from 'ng2-smart-table';
22 import { Router } from '@angular/router';
23 import { MatDialog, MatDialogConfig, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
24 import { MatFormFieldModule } from '@angular/material';
25 import { MatRadioModule } from '@angular/material/radio'; 
26 import { FormGroup, FormControl, FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
27 import { HttpClient } from '@angular/common/http';
28 import { Observable } from 'rxjs/Rx';
29 import { SignalService } from '../services/signal/signal.service';
30 import { E2SetupRequest } from '../interfaces/e2-mgr.types';
31
32 @Component({
33   selector: 'app-signal',
34   templateUrl: 'signal.component.html',
35   styleUrls: ['signal.component.css']
36 })
37
38 export class SignalComponent {
39   settings = {
40     hideSubHeader: true,
41     actions: {
42       columnTitle: 'Actions',
43       add: false,
44       edit: false,
45       delete: false,
46       position: 'right'
47     },
48     columns: {
49       requestType: {
50         title: 'RAN Type',
51         type: 'string',
52       },
53       ranName: {
54         title: 'eNodeB/gNodeB Name',
55         type: 'string',
56       },
57       ranIp: {
58         title: 'IP',
59         type: 'number',
60       },
61       ranPort: {
62         title: 'Port',
63         type: 'number',
64       },
65       responseCode: {
66         title: 'Response',
67         type: 'number',
68       },
69       timeStamp: {
70         title: 'Time Stamp',
71         type: 'string',
72       }
73     }
74   };
75
76   source: LocalDataSource = new LocalDataSource();
77
78   constructor(private service: SignalService, public dialog: MatDialog, private http: HttpClient) {
79     this.service.getAll().subscribe((val: any[]) => this.source.load(val));
80   }
81
82   openRanConnectDialog() {
83     const dialogRef = this.dialog.open(AppRANConnectDialog, {
84       width: '450px',
85       data: { }
86     })
87     dialogRef.afterClosed().subscribe(result => {
88       this.service.getAll().subscribe((val: any[]) => this.source.load(val));
89     });
90   }
91
92 }// class SignalComponent
93
94 @Component({
95   selector: 'app-signal-ranconnect-dialog',
96   templateUrl: 'signal.component.ranconnect-dialog.html',
97   styleUrls: ['signal.component.css']
98 })
99
100 export class AppRANConnectDialog implements OnInit {
101
102   public ranDialogForm: FormGroup;
103
104   constructor(
105       public dialogRef: MatDialogRef<AppRANConnectDialog>,
106       private service: SignalService, 
107       @Inject(MAT_DIALOG_DATA) public data: E2SetupRequest) { 
108     }
109
110   ngOnInit() {
111     const namePattern = /^([A-Z]){4}([0-9]){6}$/;
112     const ipPattern = /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/;
113     const portPattern = /^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/;
114     this.ranDialogForm = new FormGroup({
115       ranType: new FormControl('endc'),
116       ranName: new FormControl('', [Validators.required, Validators.pattern(namePattern)]),
117       ranIp: new FormControl('', [Validators.required, Validators.pattern(ipPattern)]),
118       ranPort: new FormControl('', [Validators.required, Validators.pattern(portPattern)])
119     });
120   }
121
122   onCancel() {
123     this.dialogRef.close();
124   }
125
126   public setupConnection = (ranFormValue) => {
127     if (this.ranDialogForm.valid) {
128       this.executeSetupConnection(ranFormValue);
129     }
130   }
131
132   private executeSetupConnection = (ranFormValue) => {
133     let setupRequest: E2SetupRequest = {
134       ranName: ranFormValue.ranName,
135       ranIp:   ranFormValue.ranIp,
136       ranPort: ranFormValue.ranPort
137     }
138     if (ranFormValue.ranType === 'endc') {
139       this.service.endcSetup(setupRequest).subscribe((val: any[]) => {});
140     }
141     else {
142       this.service.x2Setup(setupRequest).subscribe((val: any[]) => {});
143     }
144     this.dialogRef.close();
145   }
146
147   public hasError(controlName: string, errorName: string) {
148     if (this.ranDialogForm.controls[controlName].hasError(errorName))
149       return true;
150     return false;
151   }
152
153   public validateControl(controlName: string) {
154     if (this.ranDialogForm.controls[controlName].invalid && this.ranDialogForm.controls[controlName].touched)
155       return true;
156     return false;
157   }
158
159 } // class AppRANConnectDialog