]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Replace toastr calls with notification service 21078/head
authorTiago Melo <tmelo@suse.com>
Tue, 10 Apr 2018 15:01:42 +0000 (16:01 +0100)
committerTiago Melo <tmelo@suse.com>
Tue, 10 Apr 2018 15:07:27 +0000 (16:07 +0100)
Signed-off-by: Tiago Melo <tmelo@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-interceptor.service.ts

index b8307b594e815632ec5be8d92984871c53097778..665a3db0e42910b915e620c543a91de748737573 100644 (file)
@@ -3,8 +3,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 import { FormsModule } from '@angular/forms';
 import { RouterTestingModule } from '@angular/router/testing';
 
-import { ToastModule } from 'ng2-toastr';
-
 import { SharedModule } from '../../../shared/shared.module';
 import { LoginComponent } from './login.component';
 
@@ -18,8 +16,7 @@ describe('LoginComponent', () => {
         FormsModule,
         SharedModule,
         RouterTestingModule,
-        HttpClientTestingModule,
-        ToastModule.forRoot()
+        HttpClientTestingModule
       ],
       declarations: [
         LoginComponent
index f1a1f90f088f3fd604ad5f7cab2034c3406cc62d..4147af81398015bdded1378d4ef8db18d108b8be 100644 (file)
@@ -1,8 +1,6 @@
 import { Component, OnInit, ViewContainerRef } from '@angular/core';
 import { Router } from '@angular/router';
 
-import { ToastsManager } from 'ng2-toastr';
-
 import { AuthService } from '../../../shared/api/auth.service';
 import { Credentials } from '../../../shared/models/credentials';
 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
@@ -18,10 +16,7 @@ export class LoginComponent implements OnInit {
 
   constructor(private authService: AuthService,
               private authStorageService: AuthStorageService,
-              private router: Router,
-              public toastr: ToastsManager,
-              private vcr: ViewContainerRef) {
-    this.toastr.setRootViewContainerRef(vcr);
+              private router: Router) {
   }
 
   ngOnInit() {
index cc7cffe8c2c38d6648aeca80990b5ce4ae25441f..ad391208267d3dc8961a7d5fa68b809d07341421 100644 (file)
@@ -1,43 +1,50 @@
 import {
-  HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest
+  HttpErrorResponse,
+  HttpEvent,
+  HttpHandler,
+  HttpInterceptor,
+  HttpRequest
 } from '@angular/common/http';
 import { Injectable } from '@angular/core';
 import { Router } from '@angular/router';
 
-import { ToastsManager } from 'ng2-toastr';
 import 'rxjs/add/observable/throw';
 import 'rxjs/add/operator/catch';
 import { Observable } from 'rxjs/Observable';
 
+import { NotificationType } from '../enum/notification-type.enum';
 import { AuthStorageService } from './auth-storage.service';
+import { NotificationService } from './notification.service';
 
 @Injectable()
 export class AuthInterceptorService implements HttpInterceptor {
-
-  constructor(private router: Router,
-              private authStorageService: AuthStorageService,
-              public toastr: ToastsManager) {
-  }
+  constructor(
+    private router: Router,
+    private authStorageService: AuthStorageService,
+    public notificationService: NotificationService
+  ) {}
 
   intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
-    return next.handle(request)
-      .catch((resp) => {
-        if (resp instanceof HttpErrorResponse) {
-          switch (resp.status) {
-            case 404:
-              this.router.navigate(['/404']);
-              break;
-            case 401:
-              this.authStorageService.remove();
-              this.router.navigate(['/login']);
-              // falls through
-            default:
-              this.toastr.error(resp.error.detail || '',
-                `${resp.status} - ${resp.statusText}`);
-          }
+    return next.handle(request).catch(resp => {
+      if (resp instanceof HttpErrorResponse) {
+        switch (resp.status) {
+          case 404:
+            this.router.navigate(['/404']);
+            break;
+          case 401:
+            this.authStorageService.remove();
+            this.router.navigate(['/login']);
+          // falls through
+          default:
+            this.notificationService.show(
+              NotificationType.error,
+              resp.error.detail || '',
+              `${resp.status} - ${resp.statusText}`
+            );
         }
-        // Return the error to the method that called it.
-        return Observable.throw(resp);
-      });
+      }
+      // Return the error to the method that called it.
+      return Observable.throw(resp);
+    });
   }
 }