Add loading component
[portal/ric-dashboard.git] / webapp-frontend / src / app / anr-xapp / anr-xapp.component.ts
index d173505..9e25391 100644 (file)
  * ========================LICENSE_END===================================
  */
 
+import { HttpResponse } from '@angular/common/http';
 import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
+import { MatSort } from '@angular/material';
 import { MatDialog } from '@angular/material/dialog';
 import { fromEvent } from 'rxjs/observable/fromEvent';
-import { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators';
+import { debounceTime, distinctUntilChanged, finalize, tap } from 'rxjs/operators';
 import { ANRNeighborCellRelation } from '../interfaces/anr-xapp.types';
-import { ANRXappDataSource } from './anr-xapp.datasource';
 import { ANRXappService } from '../services/anr-xapp/anr-xapp.service';
-import { ANREditNCRDialogComponent } from './anr-edit-ncr-dialog.component';
-import { ConfirmDialogService } from './../services/ui/confirm-dialog.service';
 import { ErrorDialogService } from '../services/ui/error-dialog.service';
+import { LoadingDialogService } from '../services/ui/loading-dialog.service';
+import { ConfirmDialogService } from './../services/ui/confirm-dialog.service';
 import { NotificationService } from './../services/ui/notification.service';
+import { AnrEditNcrDialogComponent } from './anr-edit-ncr-dialog.component';
+import { ANRXappDataSource } from './anr-xapp.datasource';
 
 @Component({
-  selector: 'app-anr',
+  selector: 'rd-anr',
   templateUrl: './anr-xapp.component.html',
   styleUrls: ['./anr-xapp.component.scss']
 })
 export class AnrXappComponent implements AfterViewInit, OnInit {
 
   dataSource: ANRXappDataSource;
-  anrClientVersion: string;
   gNodeBIds: string[];
-  @ViewChild('ggNodeB') ggNodeB: ElementRef;
-  @ViewChild('servingCellNrcgi') servingCellNrcgi: ElementRef;
-  @ViewChild('neighborCellNrpci') neighborCellNrpci: ElementRef;
+  @ViewChild('ggNodeB', {static: true}) ggNodeB: ElementRef;
+  @ViewChild('servingCellNrcgi', {static: true}) servingCellNrcgi: ElementRef;
+  @ViewChild('neighborCellNrpci', {static: true}) neighborCellNrpci: ElementRef;
+  @ViewChild(MatSort, {static: true}) sort: MatSort;
 
   displayedColumns = ['cellIdentifierNrcgi', 'neighborCellNrpci', 'neighborCellNrcgi',
     'flagNoHo', 'flagNoXn', 'flagNoRemove', 'action'];
@@ -52,14 +55,14 @@ export class AnrXappComponent implements AfterViewInit, OnInit {
     private dialog: MatDialog,
     private confirmDialogService: ConfirmDialogService,
     private errorDialogService: ErrorDialogService,
+    private loadingDialogService: LoadingDialogService,
     private notificationService: NotificationService) { }
 
   ngOnInit() {
-    this.dataSource = new ANRXappDataSource(this.anrXappService);
+    this.dataSource = new ANRXappDataSource(this.anrXappService, this.sort, this.notificationService);
     this.dataSource.loadTable();
     // Empty string occurs first in the array of gNodeBIds
     this.anrXappService.getgNodeBs().subscribe((res: string[]) => this.gNodeBIds = res);
-    this.anrXappService.getVersion().subscribe((res: string) => this.anrClientVersion = res);
   }
 
   ngAfterViewInit() {
@@ -92,7 +95,7 @@ export class AnrXappComponent implements AfterViewInit, OnInit {
   }
 
   modifyNcr(ncr: ANRNeighborCellRelation): void {
-    const dialogRef = this.dialog.open(ANREditNCRDialogComponent, {
+    const dialogRef = this.dialog.open(AnrEditNcrDialogComponent, {
       width: '300px',
       data: ncr
     });
@@ -106,9 +109,13 @@ export class AnrXappComponent implements AfterViewInit, OnInit {
       .openConfirmDialog('Are you sure you want to delete this relation?')
       .afterClosed().subscribe(res => {
         if (res) {
+          this.loadingDialogService.startLoading("Deleting");
           this.anrXappService.deleteNcr(ncr.servingCellNrcgi, ncr.neighborCellNrpci)
+            .pipe(
+              finalize(() => this.loadingDialogService.stopLoading())
+            )
             .subscribe(
-              response => {
+              (response: HttpResponse<Object>) => {
                 switch (response.status) {
                   case 200:
                     this.notificationService.success('Delete succeeded!');