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