# All files / src/app/shared/models cd-notification.ts

100% Statements 26/26
100% Branches 8/8
100% Functions 4/4
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    49x

    49x

    202x

    240x
    202x
    202x
    202x
    285x

    202x

    49x

    49x

    73x
    73x

    110x
    73x
    73x

    73x
    73x
    73x

    49x
     import { ToastOptions } from 'ng2-toastr';
    import { NotificationType } from '../enum/notification-type.enum';

    export class CdNotificationConfig {
      applicationClass: string;

      private classes = {
        Ceph: 'ceph-icon',
        Prometheus: 'prometheus-icon'
      };

      constructor(
        public type: NotificationType = NotificationType.info,
        public title?: string,
        public message?: string, // Use this for additional information only
        public options?: any | ToastOptions,
        public application: string = 'Ceph'
      ) {
        this.applicationClass = this.classes[this.application];
      }
    }

    export class CdNotification extends CdNotificationConfig {
      timestamp: string;
      textClass: string;
      iconClass: string;

      private textClasses = ['text-danger', 'text-info', 'text-success'];
      private iconClasses = ['fa-exclamation-triangle', 'fa-info', 'fa-check'];

      constructor(private config: CdNotificationConfig = new CdNotificationConfig()) {
        super(config.type, config.title, config.message, config.options, config.application);
        delete this.config;
        /* string representation of the Date object so it can be directly compared
        with the timestamps parsed from localStorage */
        this.timestamp = new Date().toJSON();
        this.iconClass = this.iconClasses[this.type];
        this.textClass = this.textClasses[this.type];
      }
    }