File
    Implements
    
    
    Metadata
    
        
            
                | selector | cd-notifications | 
            
                | styleUrls | ./notifications.component.scss | 
            
                | templateUrl | ./notifications.component.html | 
        
    
    
    
    
    
    
        Methods
    
    
        
            
                | ngOnDestroy | 
            
                | ngOnDestroy() | 
            
                |  | 
            
                |  | 
        
    
    
    
    
        
            
                | Private
                            triggerPrometheusAlerts | 
            
                | triggerPrometheusAlerts() | 
            
                |  | 
            
                |  | 
        
    
    
    
        
        
            
                
                    | Private
                            interval | 
                    
                        | Type : number | 
                        
                            |  | 
            
        
        
        
        import { Component, NgZone, OnDestroy, OnInit } from '@angular/core';
import * as _ from 'lodash';
import { CdNotification } from '../../../shared/models/cd-notification';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
import { NotificationService } from '../../../shared/services/notification.service';
import { PrometheusAlertService } from '../../../shared/services/prometheus-alert.service';
import { PrometheusNotificationService } from '../../../shared/services/prometheus-notification.service';
@Component({
  selector: 'cd-notifications',
  templateUrl: './notifications.component.html',
  styleUrls: ['./notifications.component.scss']
})
export class NotificationsComponent implements OnInit, OnDestroy {
  notifications: CdNotification[];
  private interval: number;
  constructor(
    public notificationService: NotificationService,
    private prometheusNotificationService: PrometheusNotificationService,
    private authStorageService: AuthStorageService,
    private prometheusAlertService: PrometheusAlertService,
    private ngZone: NgZone
  ) {
    this.notifications = [];
  }
  ngOnDestroy() {
    window.clearInterval(this.interval);
  }
  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']);
    });
  }
  private triggerPrometheusAlerts() {
    this.prometheusAlertService.refresh();
    this.prometheusNotificationService.refresh();
  }
  removeAll() {
    this.notificationService.removeAll();
  }
}
     
    
        <ng-template #notificationsTpl>
  <div *ngIf="notifications.length > 0">
    <button type="button" class="btn btn-default btn-sm btn-block" (click)="removeAll()">
      <i class="fa fa-trash-o" aria-hidden="true"></i>
       
      <ng-container i18n>Remove all</ng-container>
    </button>
    <hr>
    <div *ngFor="let notification of notifications">
      <table>
        <tr>
          <td rowspan="3" class="icon-col text-center">
            <span [ngClass]="['fa-stack fa-2x', notification.textClass]">
              <i class="fa fa-circle fa-stack-2x"></i>
              <i [ngClass]="['fa fa-stack-1x fa-inverse', notification.iconClass]"></i>
            </span>
          </td>
          <td>
            <strong>{{ notification.title }}</strong>
          </td>
        </tr>
        <tr>
          <td [innerHtml]="notification.message">
          </td>
        </tr>
        <tr>
          <td [innerHtml]="notificationService.renderTimeAndApplicationHtml(notification)"></td>
        </tr>
      </table>
      <hr>
    </div>
  </div>
</ng-template>
<ng-template #emptyTpl>
  <div *ngIf="notifications.length === 0">
    <div class="message">
      There are no notifications.
    </div>
  </div>
</ng-template>
<ng-template #popTpl>
  <ng-container *ngTemplateOutlet="notificationsTpl"></ng-container>
  <ng-container *ngTemplateOutlet="emptyTpl"></ng-container>
</ng-template>
<a [popover]="popTpl"
   placement="bottom"
   container="body"
   outsideClick="true"
   i18n-title
   title="Recent Notifications">
  <i class="fa fa-fw fa-bell"></i>
  <span i18n
        class="visible-xs-inline-block">Recent Notifications</span>
</a>
     
    
                
                @import '../../../../styles/popover.scss';
     
    
        
        
            
                Legend
            
            
            
            
                Html element with directive