blob: 6d79cb08757b4cebc6e345fd4607a2b35736ed04 [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2015-2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
import { Component, OnInit, OnDestroy } from '@angular/core';
import { MessageService } from 'primeng/api';
import { MDMNotificationService } from './mdm-notification.service';
import { Subscription } from 'rxjs';
@Component({
selector: 'mdm-notifications',
template: '<p-toast baseZIndex="2000"></p-toast>'
})
export class MDMNotificationComponent implements OnInit, OnDestroy {
subscription: Subscription;
constructor(private notificationsService: MDMNotificationService,
private messageService: MessageService) { }
ngOnInit() {
this.subscribeToNotifications();
}
subscribeToNotifications() {
this.subscription = this.notificationsService.notificationChange
.subscribe(notification => {
notification.life = 10000;
if (notification.severity === 'error') {
notification.sticky = true;
}
this.messageService.add(notification);
});
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}