1d4f526a881f0ae2c82795231042fa275c766f0b
[dcaegen2/services.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : DataLake
4  * ================================================================================
5  * Copyright 2019 QCT
6  *=================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 /**
22  * This component is to display the notification.
23  *
24  * @author Ekko Chang
25  *
26  */
27
28 import { Component, OnInit } from "@angular/core";
29 import {
30   Notification,
31   NotificationType
32 } from "src/app/core/models/toastr-notification.model";
33 import { ToastrNotificationService } from "src/app/core/services/toastr-notification.service";
34
35 @Component({
36   selector: "app-toastr-notification",
37   templateUrl: "./toastr-notification.component.html",
38   styleUrls: ["./toastr-notification.component.css"]
39 })
40 export class ToastrNotificationComponent implements OnInit {
41   notifications: Notification[] = [];
42
43   constructor(public _notificationService: ToastrNotificationService) {}
44
45   ngOnInit() {
46     this._notificationService.getAlert().subscribe((alert: Notification) => {
47       this.notifications = [];
48       if (!alert) {
49         this.notifications = [];
50         return;
51       }
52       this.notifications.push(alert);
53       setTimeout(() => {
54         this.notifications = this.notifications.filter(x => x !== alert);
55       }, 5000);
56     });
57   }
58
59   removeNotification(notification: Notification) {
60     this.notifications = this.notifications.filter(x => x !== notification);
61   }
62
63   /*
64     Set css class for Alert -- Called from alert component
65   */
66   cssClass(notification: Notification) {
67     if (!notification) {
68       return;
69     }
70     switch (notification.type) {
71       case NotificationType.Success:
72         return "toast-success";
73       case NotificationType.Error:
74         return "toast-error";
75       case NotificationType.Info:
76         return "toast-info";
77       case NotificationType.Warning:
78         return "toast-warning";
79     }
80   }
81 }