Drop endc/x2 connection setup support
[portal/ric-dashboard.git] / dashboard / 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, OnDestroy, OnInit } from '@angular/core';
22 import { MatDialog } from '@angular/material/dialog';
23 import { Subscription } from 'rxjs';
24 import { finalize } from 'rxjs/operators';
25 import { RicInstance } from '../interfaces/dashboard.types';
26 import { E2ManagerService } from '../services/e2-mgr/e2-mgr.service';
27 import { InstanceSelectorService } from '../services/instance-selector/instance-selector.service';
28 import { ConfirmDialogService } from '../services/ui/confirm-dialog.service';
29 import { ErrorDialogService } from '../services/ui/error-dialog.service';
30 import { LoadingDialogService } from '../services/ui/loading-dialog.service';
31 import { NotificationService } from '../services/ui/notification.service';
32 import { UiService } from '../services/ui/ui.service';
33 import { RANControlDataSource } from './ran-control.datasource';
34
35 @Component({
36   selector: 'rd-ran-control',
37   templateUrl: './ran-control.component.html',
38   styleUrls: ['./ran-control.component.scss']
39 })
40 export class RanControlComponent implements OnInit, OnDestroy {
41
42   darkMode: boolean;
43   panelClass: string;
44   displayedColumns: string[] = ['nbId', 'nodeType', 'ranName', 'ranIp', 'ranPort', 'connectionStatus'];
45   dataSource: RANControlDataSource;
46   private instanceChange: Subscription;
47   private instanceKey: string;
48
49   constructor(private e2MgrSvc: E2ManagerService,
50     private errorDialogService: ErrorDialogService,
51     private confirmDialogService: ConfirmDialogService,
52     private notificationService: NotificationService,
53     private loadingDialogService: LoadingDialogService,
54     public instanceSelectorService: InstanceSelectorService,
55     public dialog: MatDialog,
56     public ui: UiService) { }
57
58   ngOnInit() {
59     this.dataSource = new RANControlDataSource(this.e2MgrSvc, this.notificationService);
60
61     this.ui.darkModeState.subscribe((isDark) => {
62       this.darkMode = isDark;
63     });
64
65     this.instanceChange = this.instanceSelectorService.getSelectedInstance().subscribe((instance: RicInstance) => {
66       if (instance.key) {
67         this.instanceKey = instance.key;
68         this.dataSource.loadTable(instance.key);
69       }
70     });
71   }
72
73   ngOnDestroy() {
74     this.instanceChange.unsubscribe();
75   }
76
77   disconnectAllRANConnections() {
78     const aboutError = 'Disconnect all RAN Connections Failed: ';
79     this.confirmDialogService.openConfirmDialog('Are you sure you want to disconnect all RAN connections?')
80       .afterClosed().subscribe((res: boolean) => {
81         if (res) {
82           this.loadingDialogService.startLoading('Disconnecting');
83           this.e2MgrSvc.nodebPut(this.instanceKey)
84             .pipe(
85               finalize(() => this.loadingDialogService.stopLoading())
86             )
87             .subscribe(
88               (body: any) => {
89                 this.notificationService.success('Disconnect succeeded!');
90                 this.dataSource.loadTable(this.instanceKey);
91               },
92               (her: HttpErrorResponse) => {
93                 // the error field should have an ErrorTransport object
94                 let msg = her.message;
95                 if (her.error && her.error.message) {
96                   msg = her.error.message;
97                 }
98                 this.errorDialogService.displayError('Disconnect failed: ' + msg);
99               }
100             );
101         }
102       });
103   }
104
105 }