e19f97c04b2bc17d4be2a5a9e1c7013a91337787
[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 { SignalService } from '../services/signal/signal.service';
23 import { Router } from '@angular/router';
24 import { MatDialog, MatDialogConfig, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
25 import { MatFormFieldModule } from '@angular/material';
26 import { FormGroup, FormControl, FormBuilder, ReactiveFormsModule, Validators} from '@angular/forms';
27 import { HttpClient } from '@angular/common/http';
28 import { Observable } from 'rxjs/Rx';
29
30 export interface DialogData {
31     ranName: string;
32     ranIp: number;
33     ranPort: number;
34 }
35
36 @Component({
37     selector: 'app-signal',
38     templateUrl: 'signal.component.html',
39     styleUrls: ['signal.component.css']
40 })
41
42 export class SignalComponent {
43     settings = {
44         hideSubHeader: true,
45         actions: {
46             columnTitle: 'Actions',
47             add: false,
48             edit: false,
49             delete: false,
50             position: 'right'
51         },
52         columns: {
53             requestType: {
54                 title: 'Request Type',
55                 type: 'string',
56             },
57             ranName: {
58                 title: 'eNodeB/gNodeB Name',
59                 type: 'string',
60             },
61             ranIp: {
62                 title: 'IP',
63                 type: 'number',
64             },
65             ranPort: {
66                 title: 'Port',
67                 type: 'number',
68             },
69             responseCode: {
70                 title: 'Response',
71                 type: 'number',
72             },
73             timeStamp: {
74                 title: 'Time Stamp',
75                 type: 'string',
76             }
77         }
78     };
79
80     source: LocalDataSource = new LocalDataSource();
81
82     ranName: string;
83
84     ranIp: number;
85
86     ranPort: number;
87
88     constructor(private service: SignalService, public dialog: MatDialog, private http: HttpClient) {
89         this.service.getAll().subscribe((val: any[]) => this.source.load(val));
90     }
91
92     openRanConnectDialog() {
93
94         const dialogRef = this.dialog.open(AppRANConnectDialog,  {
95             width: '450px',
96             data: {ranName: this.ranName, ranIp: this.ranIp, ranPort: this.ranPort}
97     })
98
99         dialogRef.afterClosed().subscribe(result => {
100             this.service.getAll().subscribe((val: any[]) => this.source.load(val));
101         });
102
103     }
104 }
105
106 @Component({
107     selector: 'app-signal-ranconnect-dialog',
108     templateUrl: 'signal.component.ranconnect-dialog.html',
109     styleUrls: ['signal.component.css']
110 })
111
112 export class AppRANConnectDialog implements OnInit {
113
114     constructor(public dialogRef: MatDialogRef<AppRANConnectDialog>,
115           private service: SignalService,
116           @Inject(MAT_DIALOG_DATA) public data: DialogData) {
117     }
118
119     public ranDialogForm: FormGroup;
120
121         public ranName: string;
122
123         public ranIp: number;
124
125         public ranPort: number;
126
127     ngOnInit() {
128         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*$))';
129         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])$';
130         this.ranDialogForm = new FormGroup({
131                 ranName: new FormControl('', [Validators.required, Validators.maxLength(50)]),
132                 ranIp: new FormControl('', [Validators.required, Validators.pattern(ipPattern)]),
133                 ranPort: new FormControl('', [Validators.required, Validators.pattern(portPattern)])
134             });
135     }
136
137     close() {
138         this.dialogRef.close();
139     }
140
141     connectRAN(): void {
142         this.service.x2Setup(this.data).subscribe((val: any[]) => {});
143         this.dialogRef.close();
144     }
145
146     public hasError(controlName: string, errorName: string) {
147         if (this.ranDialogForm.controls[controlName].hasError(errorName))
148             return true;
149         return false;
150     }
151
152   public validateControl(controlName: string) {
153         if (this.ranDialogForm.controls[controlName].invalid && this.ranDialogForm.controls[controlName].touched)
154             return true;
155         return false;
156     }
157 }