From 623ff89f1a6412fed0a0478360b220bb3e32845e Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Wed, 16 Oct 2019 06:58:59 -0700 Subject: [PATCH] Notifications added --- .../project-map/project-map.component.html | 3 ++ .../project-map/project-map.component.ts | 32 +++++++++++++++++++ src/app/services/toaster.service.ts | 15 +++++++++ src/styles.css | 5 +++ 4 files changed, 55 insertions(+) diff --git a/src/app/components/project-map/project-map.component.html b/src/app/components/project-map/project-map.component.html index 3a21ddfd..4e640dcb 100644 --- a/src/app/components/project-map/project-map.component.html +++ b/src/app/components/project-map/project-map.component.html @@ -87,6 +87,9 @@ Show topology/servers summary + + Show notifications + diff --git a/src/app/components/project-map/project-map.component.ts b/src/app/components/project-map/project-map.component.ts index fbe54469..1894e0c2 100644 --- a/src/app/components/project-map/project-map.component.ts +++ b/src/app/components/project-map/project-map.component.ts @@ -82,6 +82,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy { public isConsoleVisible: boolean = false; public isTopologySummaryVisible: boolean = false; public isInterfaceLabelVisible: boolean = false; + public notificationsVisibility: boolean = false; tools = { selection: true, @@ -222,6 +223,21 @@ export class ProjectMapComponent implements OnInit, OnDestroy { }) ); + this.subscriptions.push(this.projectWebServiceHandler.errorNotificationEmitter.subscribe((message) => { + this.showMessage({ + type: 'error', + message: message + }); + })); + + this.subscriptions.push(this.projectWebServiceHandler.warningNotificationEmitter.subscribe((message) => { + this.showMessage({ + type: 'warning', + message: message + }); + })); + + this.notificationsVisibility = localStorage.getItem('notificationsVisibility') === 'true' ? true : false; this.addKeyboardListeners(); } @@ -454,6 +470,22 @@ export class ProjectMapComponent implements OnInit, OnDestroy { this.mapSettingsService.toggleTopologySummary(this.isTopologySummaryVisible); } + public toggleNotifications(visible: boolean) { + this.notificationsVisibility = visible; + if (this.notificationsVisibility) { + localStorage.setItem('notificationsVisibility', 'true'); + } else { + localStorage.removeItem('notificationsVisibility'); + } + } + + private showMessage(msg) { + if (this.notificationsVisibility) { + if (msg.type === 'error') this.toasterService.error(msg.message); + if (msg.type === 'warning') this.toasterService.warning(msg.message); + } + } + public hideMenu() { this.projectMapMenuComponent.resetDrawToolChoice() this.isProjectMapMenuVisible = false; diff --git a/src/app/services/toaster.service.ts b/src/app/services/toaster.service.ts index 0c579428..e9ef7f35 100644 --- a/src/app/services/toaster.service.ts +++ b/src/app/services/toaster.service.ts @@ -9,12 +9,21 @@ export class ToasterService { MatSnackBarHorizontalPosition: 'center', MatSnackBarVerticalPosition: 'bottom' }; + + snackBarConfigForWarning = { + duration: 2000, + panelClass: ['snackabar-warning'], + MatSnackBarHorizontalPosition: 'center', + MatSnackBarVerticalPosition: 'bottom' + }; + snackBarConfigForError = { duration: 2000, panelClass: ['snackabar-error'], MatSnackBarHorizontalPosition: 'center', MatSnackBarVerticalPosition: 'bottom' }; + constructor( private snackbar: MatSnackBar, private zone: NgZone) {} @@ -25,6 +34,12 @@ export class ToasterService { }); } + public warning(message: string) { + this.zone.run(() => { + this.snackbar.open(message, 'Close', this.snackBarConfigForWarning); + }); + } + public success(message: string) { this.zone.run(() => { this.snackbar.open(message, 'Close', this.snackBarConfigForSuccess); diff --git a/src/styles.css b/src/styles.css index 4c521464..c2ab0e3e 100644 --- a/src/styles.css +++ b/src/styles.css @@ -11,6 +11,11 @@ a.table-link { color: white!important; } +.snackbar-warning { + background: rgb(197, 199, 64)!important; + color: white!important; +} + .snackbar-error { background: #B00020!important; color: white!important;