diff --git a/packages/core/src/lib/message/shared/message.interface.ts b/packages/core/src/lib/message/shared/message.interface.ts index 56f87f79d2..8916d9366d 100644 --- a/packages/core/src/lib/message/shared/message.interface.ts +++ b/packages/core/src/lib/message/shared/message.interface.ts @@ -1,5 +1,6 @@ import { TemplateRef } from '@angular/core'; import { MessageType } from './message.enum'; +import { Notification } from 'angular2-notifications'; export interface Message { title?: string; @@ -7,11 +8,12 @@ export interface Message { html?: string | TemplateRef; icon?: string; type?: MessageType; - options?: any; + options?: MessageOptions; format?: 'text' | 'html'; } -export interface MessageOptions { - timeOut?: number; +export interface MessageOptions extends Notification { template?: string; + from?: Date | string; + to?: Date | string; } diff --git a/packages/core/src/lib/message/shared/message.service.ts b/packages/core/src/lib/message/shared/message.service.ts index 0d1a7faf00..cae3f899f8 100644 --- a/packages/core/src/lib/message/shared/message.service.ts +++ b/packages/core/src/lib/message/shared/message.service.ts @@ -34,38 +34,53 @@ export class MessageService { message(message: Message) { this.messages$.next(this.messages$.value.concat([message])); - message.options = message.options || {}; - message = this.handleTemplate(message); - - let notification: Notification; - if (message.text) { - notification = this.notificationService.create( - message.title, - message.text, - (message.type as any) as NotificationType, - message.options - ); - } else if (message.html) { - if (!message.icon) { - message.options.theClass = message.options.theClass - ? message.options.theClass + ' noIcon' - : 'noIcon'; - } + message.options = message.options || {} as MessageOptions; + const currentDate = new Date(); - notification = this.notificationService.html( - message.html, - (message.type as any) as NotificationType, - message.options - ); - } else { - return; + message.options.from = message.options.from ? message.options.from : new Date('1 jan 1900'); + message.options.to = message.options.to ? message.options.to : new Date('1 jan 3000'); + if (typeof message.options.from === 'string') { + message.options.from = new Date(Date.parse(message.options.from.replace(/-/g, ' '))); } - - if (message.icon !== undefined) { - this.addIcon(notification, message.icon); + if (typeof message.options.to === 'string') { + message.options.to = new Date(Date.parse(message.options.to.replace(/-/g, ' '))); } + if ( + currentDate > message.options.from && currentDate < message.options.to) { + + message = this.handleTemplate(message); + + let notification: Notification; + if (message.text) { + notification = this.notificationService.create( + message.title, + message.text, + (message.type as any) as NotificationType, + message.options + ); + } else if (message.html) { + if (!message.icon) { + message.options.theClass = message.options.theClass + ? message.options.theClass + ' noIcon' + : 'noIcon'; + } + + notification = this.notificationService.html( + message.html, + (message.type as any) as NotificationType, + message.options + ); + } else { + return; + } - return notification; + if (message.icon !== undefined) { + this.addIcon(notification, message.icon); + } + + return notification; + } + return; } success(text: string, title?: string, options: any = {}) {