argos/dmp-frontend/src/app/library/notification/notification.component.ts

56 lines
2.2 KiB
TypeScript
Raw Normal View History

2019-01-18 18:03:45 +01:00
import { Component, OnInit } from '@angular/core';
2019-09-23 10:17:03 +02:00
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
2019-01-18 18:03:45 +01:00
import { takeUntil } from 'rxjs/operators';
import { BaseComponent } from '../../core/common/base/base.component';
import { UiNotificationService, UiNotificationType, PopupNotification, SnackBarNotification, SnackBarNotificationLevel } from '../../core/services/notification/ui-notification-service';
import { PopupNotificationDialogComponent } from './popup/popup-notification.component';
import { SnackBarNotificationComponent } from './snack-bar/snack-bar-notification.component';
@Component({
selector: 'app-notification',
templateUrl: './notification.component.html',
styleUrls: ['./notification.component.scss']
})
export class NotificationComponent extends BaseComponent implements OnInit {
constructor(
private snackBar: MatSnackBar,
private dialog: MatDialog,
private uiNotificationService: UiNotificationService
) {
super();
}
ngOnInit() {
this.uiNotificationService.getNotificationObservable().pipe(takeUntil(this._destroyed)).subscribe(notification => {
switch (notification.type) {
case UiNotificationType.SnackBar:
const snackBarNotification: SnackBarNotification = notification as SnackBarNotification;
this.snackBar.openFromComponent(SnackBarNotificationComponent, {
data: snackBarNotification,
duration: snackBarNotification.duration,
panelClass: [this.getSnackBarLevelClass(snackBarNotification.level)]
});
break;
case UiNotificationType.Popup:
const popupNotification: PopupNotification = notification as PopupNotification;
this.dialog.open(PopupNotificationDialogComponent, {
data: popupNotification
});
break;
}
});
}
private getSnackBarLevelClass(level: SnackBarNotificationLevel): string {
switch (level) {
case SnackBarNotificationLevel.Warning: return 'snack-bar-notification--warning';
case SnackBarNotificationLevel.Error: return 'snack-bar-notification--error';
case SnackBarNotificationLevel.Success: return 'snack-bar-notification--success';
default: return 'snack-bar-notification--info';
}
}
}