html hybrid store/static var

This commit is contained in:
Andrea Chiapparelli - 4Science
2018-03-06 15:45:37 +01:00
parent f61f246f23
commit 74dc5f8067
17 changed files with 229 additions and 607 deletions

View File

@@ -1,35 +1,30 @@
import { Injectable, EventEmitter } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { NotificationEvent } from './interfaces/notification-event.type';
import { Injectable } from '@angular/core';
import { INotification, Notification } from './models/notification.model';
// import {Icons, defaultIcons} from './interfaces/icons';
import { NotificationType } from './models/notification-type';
import { NotificationOptions } from './models/notification-options.model';
import * as _ from 'lodash';
import { uniqueId } from 'lodash';
import { Store } from '@ngrx/store';
import {
NewNotificationAction, NewNotificationWithTimerAction, RemoveAllNotificationsAction,
NewNotificationAction,
NewNotificationWithTimerAction,
RemoveAllNotificationsAction,
RemoveNotificationAction
} from './notifications.actions';
import { DomSanitizer } from '@angular/platform-browser';
@Injectable()
export class NotificationsService {
public static htmlArray = new Map<string, any>();
// public emitter = new Subject<NotificationEvent>();
// public icons: Icons = defaultIcons;
constructor(private store: Store<Notification>) {
constructor(private store: Store<Notification>,
private domSanitizer: DomSanitizer,) {
}
// private set(notification: Notification, to: boolean): Notification {
// notification.id = notification.override && notification.override.id ? notification.override.id : Math.random().toString(36).substring(3);
// notification.click = new EventEmitter<{}>();
// notification.timeoutEnd = new EventEmitter<{}>();
//
// this.emitter.next({command: 'set', notification: notification, add: to});
// return notification;
// };
private add(notification: Notification) {
let notificationAction;
if (notification.options.timeOut > 0) {
@@ -41,75 +36,46 @@ export class NotificationsService {
}
success(title: any = '', content: any = '', options = new NotificationOptions()): Notification {
const notification = new Notification(_.uniqueId(), NotificationType.Success, title, content, options);
const notification = new Notification(uniqueId(), NotificationType.Success, title, content, options);
this.add(notification);
return notification;
}
// error(title: any = '', content: any = '', override?: any): Notification {
// return this.set({title: title, content: content || '', type: NotificationType.Error, override: override}, true);
// }
danger(title: any = '', content: any = '', options = new NotificationOptions()): Notification {
const notification = new Notification(_.uniqueId(), NotificationType.Danger, title, content, options);
error(title: any = '', content: any = '', options = new NotificationOptions()): Notification {
const notification = new Notification(uniqueId(), NotificationType.Error, title, content, options);
this.add(notification);
return notification;
}
info(title: any = '', content: any = '', options = new NotificationOptions()): Notification {
const notification = new Notification(_.uniqueId(), NotificationType.Info, title, content, options);
const notification = new Notification(uniqueId(), NotificationType.Info, title, content, options);
this.add(notification);
return notification;
}
warning(title: any = '', content: any = '', options = new NotificationOptions()): Notification {
const notification = new Notification(_.uniqueId(), NotificationType.Warning, title, content, options);
const notification = new Notification(uniqueId(), NotificationType.Warning, title, content, options);
this.add(notification);
return notification;
}
// bare(title: any = '', content: any = '', override?: any): Notification {
// return this.set({title: title, content: content || '', type: 'bare', icon: 'bare', override: override}, true);
// }
// With type method
// create(title: any = '', content: any = '', type = 'success'): Notification {
// return this.set({
// title: title,
// content: content,
// type: type,
// icon: (this.icons as any)[type],
// override: override
// }, true);
// }
// HTML Notification method
// html(html: any, type = 'success', override?: any, icon = 'bare'): Notification {
// return this.set({html: html, type: type, icon: (this.icons as any)[icon], override: override}, true);
// }
html(html: any, type = NotificationType.Success, options = new NotificationOptions()): Notification {
const notification = new Notification(_.uniqueId(), type, null, null, options);
notification.html = html;
const notification = new Notification(uniqueId(), type, '', '', options);
NotificationsService.htmlArray.set(notification.id, html);
// notification.html = true;
this.add(notification);
return notification;
}
// Remove all notifications method
// remove(id?: string): void {
// if (id) {
// this.emitter.next({command: 'clean', id: id});
// } else {
// this.emitter.next({command: 'cleanAll'});
// }
// }
remove(notification: INotification) {
const actionRemove = new RemoveNotificationAction(notification.id);
NotificationsService.htmlArray.delete(notification.id);
this.store.dispatch(actionRemove);
}
removeAll() {
const actionRemoveAll = new RemoveAllNotificationsAction();
NotificationsService.htmlArray.clear();
this.store.dispatch(actionRemoveAll);
}