Integrate EPSDK-FW library for auth and users
[portal/ric-dashboard.git] / webapp-frontend / src / app / app-control / app-control.component.ts
index 0e2c06a..35c910d 100644 (file)
@@ -18,6 +18,7 @@
  * ========================LICENSE_END===================================
  */
 import { Component, OnInit, ViewChild } from '@angular/core';
+import { HttpResponse, HttpErrorResponse } from '@angular/common/http';
 import { MatSort } from '@angular/material/sort';
 import { Router } from '@angular/router';
 import { XappControlRow } from '../interfaces/app-mgr.types';
@@ -29,9 +30,9 @@ import { AppControlAnimations } from './app-control.animations';
 import { AppControlDataSource } from './app-control.datasource';
 
 @Component({
-  selector: 'control-app-control',
+  selector: 'rd-app-control',
   templateUrl: './app-control.component.html',
-  styleUrls: ['./app-control.component.css'],
+  styleUrls: ['./app-control.component.scss'],
   animations: [AppControlAnimations.messageTrigger]
 })
 export class AppControlComponent implements OnInit {
@@ -45,10 +46,10 @@ export class AppControlComponent implements OnInit {
     private router: Router,
     private confirmDialogService: ConfirmDialogService,
     private errorDialogService: ErrorDialogService,
-    private notification: NotificationService) { }
+    private notificationService: NotificationService) { }
 
   ngOnInit() {
-    this.dataSource = new AppControlDataSource(this.appMgrSvc, this.sort);
+    this.dataSource = new AppControlDataSource(this.appMgrSvc, this.sort, this.notificationService);
     this.dataSource.loadTable();
   }
 
@@ -67,21 +68,29 @@ export class AppControlComponent implements OnInit {
     }
   }
 
-  undeployApp(app: XappControlRow): void {
-    this.confirmDialogService.openConfirmDialog('Are you sure you want to undeploy xApp ' + app.xapp + '?')
-      .afterClosed().subscribe(res => {
+  onUndeployApp(app: XappControlRow): void {
+    this.confirmDialogService.openConfirmDialog('Are you sure you want to undeploy App ' + app.xapp + '?')
+      .afterClosed().subscribe( (res: boolean) => {
         if (res) {
           this.appMgrSvc.undeployXapp(app.xapp).subscribe(
-            response => {
+            ( httpResponse: HttpResponse<Object>) => {
               this.dataSource.loadTable();
-              switch (response.status) {
+              switch (httpResponse.status) {
                 case 200:
-                  this.notification.success('xApp undeployed successfully!');
+                  this.notificationService.success('App undeployed successfully!');
                   break;
                 default:
-                  this.notification.warn('xApp undeploy failed.');
+                  this.notificationService.warn('App undeploy failed.');
               }
-            }
+            },
+            ( (her: HttpErrorResponse) => {
+              // the error field should have an ErrorTransport object
+              let msg = her.message;
+              if (her.error && her.error.message) {
+                msg = her.error.message;
+              }
+              this.notificationService.warn('App undeploy failed: ' + msg);
+            })
           );
         }
       });