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