Merge "Add AC and ANR services"
[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 { E2ManagerService } from '../services/e2-mgr/e2-mgr.service';
29 import { E2SetupRequest } from '../interfaces/e2-mgr.types';
30
31 @Component({
32   selector: 'app-signal-ranconnect-dialog',
33   templateUrl: 'signal.component.ranconnect-dialog.html',
34   styleUrls: ['signal.component.css']
35 })
36
37 export class RANConnectDialogComponent implements OnInit {
38
39   public ranDialogForm: FormGroup;
40
41   constructor(
42       public dialogRef: MatDialogRef<RANConnectDialogComponent>,
43       private service: E2ManagerService
44     ,
45       @Inject(MAT_DIALOG_DATA) public data: E2SetupRequest) {  }
46
47   ngOnInit() {
48     const namePattern = /^([A-Z]){4}([0-9]){6}$/;
49     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}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|:)))(%.+)?\s*$))/;
50     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])$/;
51     this.ranDialogForm = new FormGroup({
52       ranType: new FormControl('endc'),
53       ranName: new FormControl('', [Validators.required, Validators.pattern(namePattern)]),
54       ranIp: new FormControl('', [Validators.required, Validators.pattern(ipPattern)]),
55       ranPort: new FormControl('', [Validators.required, Validators.pattern(portPattern)])
56     });
57   }
58
59   onCancel() {
60     this.dialogRef.close();
61   }
62
63   public setupConnection = (ranFormValue) => {
64     if (this.ranDialogForm.valid) {
65       this.executeSetupConnection(ranFormValue);
66     }
67   }
68
69   private executeSetupConnection = (ranFormValue) => {
70     const setupRequest: E2SetupRequest = {
71       ranName: ranFormValue.ranName,
72       ranIp:   ranFormValue.ranIp,
73       ranPort: ranFormValue.ranPort
74     };
75     if (ranFormValue.ranType === 'endc') {
76       this.service.endcSetup(setupRequest).subscribe((val: any[]) => {});
77     } else {
78       this.service.x2Setup(setupRequest).subscribe((val: any[]) => {});
79     }
80     this.dialogRef.close();
81   }
82
83   public hasError(controlName: string, errorName: string) {
84     if (this.ranDialogForm.controls[controlName].hasError(errorName)) { return true; }
85     return false;
86   }
87
88   public validateControl(controlName: string) {
89     if (this.ranDialogForm.controls[controlName].invalid && this.ranDialogForm.controls[controlName].touched) { return true; }
90     return false;
91   }
92
93 } // class RANConnectDialogComponent
94
95 @Component({
96   selector: 'app-signal',
97   templateUrl: 'signal.component.html',
98   styleUrls: ['signal.component.css']
99 })
100
101 export class SignalComponent {
102   settings = {
103     hideSubHeader: true,
104     actions: {
105       columnTitle: 'Actions',
106       add: false,
107       edit: false,
108       delete: false,
109       position: 'right'
110     },
111     columns: {
112       requestType: {
113         title: 'RAN Type',
114         type: 'string',
115       },
116       ranName: {
117         title: 'eNodeB/gNodeB Name',
118         type: 'string',
119       },
120       ranIp: {
121         title: 'IP',
122         type: 'number',
123       },
124       ranPort: {
125         title: 'Port',
126         type: 'number',
127       },
128       responseCode: {
129         title: 'Response',
130         type: 'number',
131       },
132       timeStamp: {
133         title: 'Time Stamp',
134         type: 'string',
135       }
136     }
137   };
138
139   source: LocalDataSource = new LocalDataSource();
140
141   constructor(private service: E2ManagerService
142   , public dialog: MatDialog, private http: HttpClient) {
143     this.service.getAll().subscribe((val: any[]) => this.source.load(val));
144   }
145
146   openRanConnectDialog() {
147     const dialogRef = this.dialog.open(RANConnectDialogComponent, {
148       width: '450px',
149       data: { }
150     });
151     dialogRef.afterClosed().subscribe(result => {
152       this.service.getAll().subscribe((val: any[]) => this.source.load(val));
153     });
154   }
155
156 }// class SignalComponent
157