Add table with automatic neighbor relation data
[portal/ric-dashboard.git] / webapp-frontend / src / app / anr-xapp / anr-xapp.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
21 import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
22 import { MatDialog } from '@angular/material/dialog';
23 import { fromEvent } from 'rxjs/observable/fromEvent';
24 import { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators';
25 import { ANRNeighborCellRelation } from '../interfaces/anr-xapp.types';
26 import { ANRXappDataSource } from './anr-xapp.datasource';
27 import { ANRXappService } from '../services/anr-xapp/anr-xapp.service';
28 import { ANREditNCRDialogComponent } from './anr-edit-ncr-dialog.component';
29 import { ConfirmDialogService } from './../services/ui/confirm-dialog.service';
30 import { ErrorDialogService } from '../services/ui/error-dialog.service';
31 import { NotificationService } from './../services/ui/notification.service';
32
33 @Component({
34   selector: 'app-anr',
35   templateUrl: './anr-xapp.component.html',
36   styleUrls: ['./anr-xapp.component.scss']
37 })
38 export class AnrXappComponent implements AfterViewInit, OnInit {
39
40   dataSource: ANRXappDataSource;
41   anrClientVersion: string;
42   gNodeBIds: string[];
43   @ViewChild('ggNodeB') ggNodeB: ElementRef;
44   @ViewChild('servingCellNrcgi') servingCellNrcgi: ElementRef;
45   @ViewChild('neighborCellNrpci') neighborCellNrpci: ElementRef;
46
47   displayedColumns = ['cellIdentifierNrcgi', 'neighborCellNrpci', 'neighborCellNrcgi',
48     'flagNoHo', 'flagNoXn', 'flagNoRemove', 'action'];
49
50   constructor(
51     private anrXappService: ANRXappService,
52     private dialog: MatDialog,
53     private confirmDialogService: ConfirmDialogService,
54     private errorDialogService: ErrorDialogService,
55     private notificationService: NotificationService) { }
56
57   ngOnInit() {
58     this.dataSource = new ANRXappDataSource(this.anrXappService);
59     this.dataSource.loadTable();
60     // Empty string occurs first in the array of gNodeBIds
61     this.anrXappService.getgNodeBs().subscribe((res: string[]) => this.gNodeBIds = res);
62     this.anrXappService.getVersion().subscribe((res: string) => this.anrClientVersion = res);
63   }
64
65   ngAfterViewInit() {
66     // the selector event calls loadNcrtPage() directly.
67     fromEvent(this.servingCellNrcgi.nativeElement, 'keyup')
68       .pipe(
69         debounceTime(150),
70         distinctUntilChanged(),
71         tap(() => {
72           this.loadNcrtPage();
73         })
74       )
75       .subscribe();
76     fromEvent(this.neighborCellNrpci.nativeElement, 'keyup')
77       .pipe(
78         debounceTime(150),
79         distinctUntilChanged(),
80         tap(() => {
81           this.loadNcrtPage();
82         })
83       )
84       .subscribe();
85   }
86
87   loadNcrtPage() {
88     this.dataSource.loadTable(
89       this.ggNodeB.nativeElement.value,
90       this.servingCellNrcgi.nativeElement.value,
91       this.neighborCellNrpci.nativeElement.value);
92   }
93
94   modifyNcr(ncr: ANRNeighborCellRelation): void {
95     const dialogRef = this.dialog.open(ANREditNCRDialogComponent, {
96       width: '300px',
97       data: ncr
98     });
99     dialogRef.afterClosed().subscribe(result => {
100       this.loadNcrtPage();
101     });
102   }
103
104   deleteNcr(ncr: ANRNeighborCellRelation): void {
105     this.confirmDialogService
106       .openConfirmDialog('Are you sure you want to delete this relation?')
107       .afterClosed().subscribe(res => {
108         if (res) {
109           this.anrXappService.deleteNcr(ncr.servingCellNrcgi, ncr.neighborCellNrpci)
110             .subscribe(
111               response => {
112                 switch (response.status) {
113                   case 200:
114                     this.notificationService.success('Delete succeeded!');
115                     break;
116                   default:
117                     this.notificationService.warn('Delete failed.');
118                 }
119               },
120               error => {
121                 this.errorDialogService.displayError(error.message);
122               });
123         }
124       });
125   }
126
127 }