b5aba669a07a6bb38f31d9bd21a2a0051e923521
[portal/ric-dashboard.git] / webapp-frontend / src / app / ran-control / ran-control.component.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property
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 { HttpErrorResponse } from '@angular/common/http';
21 import { Component, OnInit } from '@angular/core';
22 import { MatDialog } from '@angular/material/dialog';
23 import { finalize } from 'rxjs/operators';
24 import { E2ManagerService } from '../services/e2-mgr/e2-mgr.service';
25 import { ConfirmDialogService } from '../services/ui/confirm-dialog.service';
26 import { ErrorDialogService } from '../services/ui/error-dialog.service';
27 import { LoadingDialogService } from '../services/ui/loading-dialog.service';
28 import { NotificationService } from '../services/ui/notification.service';
29 import { RanControlConnectDialogComponent } from './ran-connection-dialog.component';
30 import { RANControlDataSource } from './ran-control.datasource';
31 import { UiService } from '../services/ui/ui.service';
32
33 @Component({
34   selector: 'rd-ran-control',
35   templateUrl: './ran-control.component.html',
36   styleUrls: ['./ran-control.component.scss']
37 })
38 export class RanControlComponent implements OnInit {
39
40   darkMode: boolean;
41   panelClass: string = "";
42   displayedColumns: string[] = ['nbId', 'nodeType', 'ranName', 'ranIp', 'ranPort', 'connectionStatus'];
43   dataSource: RANControlDataSource;
44
45   constructor(private e2MgrSvc: E2ManagerService,
46     private errorDialogService: ErrorDialogService,
47     private confirmDialogService: ConfirmDialogService,
48     private notificationService: NotificationService,
49     private loadingDialogService: LoadingDialogService,
50     public dialog: MatDialog,
51     public ui: UiService) { }
52
53   ngOnInit() {
54     this.dataSource = new RANControlDataSource(this.e2MgrSvc, this.notificationService);
55     this.dataSource.loadTable();
56     this.ui.darkModeState.subscribe((isDark) => {
57       this.darkMode = isDark;
58     });
59   }
60
61   setupRANConnection() {
62     if (this.darkMode) {
63       this.panelClass = "dark-theme";
64     } else {
65       this.panelClass = "";
66     }
67     const dialogRef = this.dialog.open(RanControlConnectDialogComponent, {
68       panelClass: this.panelClass,
69       width: '450px'
70     });
71     dialogRef.afterClosed()
72       .subscribe((result: boolean) => {
73       if (result) {
74         this.dataSource.loadTable();
75       }
76     });
77   }
78
79   disconnectAllRANConnections() {
80     const aboutError = 'Disconnect all RAN Connections Failed: ';
81     this.confirmDialogService.openConfirmDialog('Are you sure you want to disconnect all RAN connections?')
82       .afterClosed().subscribe( (res: boolean) => {
83         if (res) {
84           this.loadingDialogService.startLoading("Disconnecting");
85           this.e2MgrSvc.nodebPut()
86             .pipe(
87               finalize(() => this.loadingDialogService.stopLoading())
88             )
89             .subscribe(
90             ( body: any ) => {
91               this.notificationService.success('Disconnect succeeded!');
92               this.dataSource.loadTable();
93             },
94             (her: HttpErrorResponse) => {
95               // the error field should have an ErrorTransport object
96               let msg = her.message;
97               if (her.error && her.error.message) {
98                 msg = her.error.message;
99               }
100               this.errorDialogService.displayError('Disconnect failed: ' + msg);
101             }
102           );
103         }
104       });
105   }
106
107 }