8baa556b59c42b04d28703245054f54495b951eb
[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
32 @Component({
33   selector: 'rd-ran-control',
34   templateUrl: './ran-control.component.html',
35   styleUrls: ['./ran-control.component.scss']
36 })
37 export class RanControlComponent implements OnInit {
38   displayedColumns: string[] = ['nbId', 'nodeType', 'ranName', 'ranIp', 'ranPort', 'connectionStatus'];
39   dataSource: RANControlDataSource;
40
41   constructor(private e2MgrSvc: E2ManagerService,
42     private errorDialogService: ErrorDialogService,
43     private confirmDialogService: ConfirmDialogService,
44     private notificationService: NotificationService,
45     private loadingDialogService: LoadingDialogService,
46     public dialog: MatDialog) { }
47
48   ngOnInit() {
49     this.dataSource = new RANControlDataSource(this.e2MgrSvc, this.notificationService);
50     this.dataSource.loadTable();
51   }
52
53   setupRANConnection() {
54     const dialogRef = this.dialog.open(RanControlConnectDialogComponent, {
55       width: '450px'
56     });
57     dialogRef.afterClosed().subscribe( (result: boolean) => {
58       if (result) {
59         this.dataSource.loadTable();
60       }
61     });
62   }
63
64   disconnectAllRANConnections() {
65     const aboutError = 'Disconnect all RAN Connections Failed: ';
66     this.confirmDialogService.openConfirmDialog('Are you sure you want to disconnect all RAN connections?')
67       .afterClosed().subscribe( (res: boolean) => {
68         if (res) {
69           this.loadingDialogService.startLoading("Disconnecting");
70           this.e2MgrSvc.nodebPut()
71             .pipe(
72               finalize(() => this.loadingDialogService.stopLoading())
73             )
74             .subscribe(
75             ( body: any ) => {
76               this.notificationService.success('Disconnect succeeded!');
77               this.dataSource.loadTable();
78             },
79             (her: HttpErrorResponse) => {
80               // the error field should have an ErrorTransport object
81               let msg = her.message;
82               if (her.error && her.error.message) {
83                 msg = her.error.message;
84               }
85               this.errorDialogService.displayError('Disconnect failed: ' + msg);
86             }
87           );
88         }
89       });
90   }
91
92 }