-import { Component, NgZone, OnDestroy, OnInit } from '@angular/core';
+import { Component, OnInit } from '@angular/core';
import * as _ from 'lodash';
-import { CdNotification } from '../../../shared/models/cd-notification';
-import { AuthStorageService } from '../../../shared/services/auth-storage.service';
+import { Icons } from '../../../shared/enum/icons.enum';
import { NotificationService } from '../../../shared/services/notification.service';
-import { PrometheusAlertService } from '../../../shared/services/prometheus-alert.service';
-import { PrometheusNotificationService } from '../../../shared/services/prometheus-notification.service';
+import { SummaryService } from '../../../shared/services/summary.service';
@Component({
selector: 'cd-notifications',
templateUrl: './notifications.component.html',
styleUrls: ['./notifications.component.scss']
})
-export class NotificationsComponent implements OnInit, OnDestroy {
- notifications: CdNotification[];
- private interval: number;
+export class NotificationsComponent implements OnInit {
+ icons = Icons;
+
+ hasRunningTasks = false;
constructor(
public notificationService: NotificationService,
- private prometheusNotificationService: PrometheusNotificationService,
- private authStorageService: AuthStorageService,
- private prometheusAlertService: PrometheusAlertService,
- private ngZone: NgZone
- ) {
- this.notifications = [];
- }
-
- ngOnDestroy() {
- window.clearInterval(this.interval);
- }
+ private summaryService: SummaryService
+ ) {}
ngOnInit() {
- if (this.authStorageService.getPermissions().prometheus.read) {
- this.triggerPrometheusAlerts();
- this.ngZone.runOutsideAngular(() => {
- this.interval = window.setInterval(() => {
- this.ngZone.run(() => {
- this.triggerPrometheusAlerts();
- });
- }, 5000);
- });
- }
- this.notificationService.data$.subscribe((notifications: CdNotification[]) => {
- this.notifications = _.orderBy(notifications, ['timestamp'], ['desc']);
+ this.summaryService.subscribe((data: any) => {
+ if (!data) {
+ return;
+ }
+ this.hasRunningTasks = data.executing_tasks.length > 0;
});
}
- private triggerPrometheusAlerts() {
- this.prometheusAlertService.refresh();
- this.prometheusNotificationService.refresh();
- }
-
- removeAll() {
- this.notificationService.removeAll();
+ toggleSidebar() {
+ this.notificationService.toggleSidebar();
}
}