diff --git a/src/app/shared/notifications/notification/notification.component.scss b/src/app/shared/notifications/notification/notification.component.scss
index 6d2a1469d6..9db71232cf 100644
--- a/src/app/shared/notifications/notification/notification.component.scss
+++ b/src/app/shared/notifications/notification/notification.component.scss
@@ -1,142 +1,33 @@
-//.simple-notification {
-// width: 100%;
-// padding: 10px 20px;
-// box-sizing: border-box;
-// position: relative;
-// float: left;
-// margin-bottom: 10px;
-// color: #fff;
-// cursor: pointer;
-// transition: all 0.5s;
-// min-height: 70px;
-//}
-//
-//.simple-notification .sn-title,
-//.simple-notification .sn-content,
-//.simple-notification .sn-html {
-// margin: 0;
-//}
-//
-//.simple-notification .sn-title {
-// line-height: 30px;
-// font-size: 20px;
-//}
-//
-//.simple-notification .sn-content {
-// font-size: 16px;
-// line-height: 20px;
-//}
-//
-//.simple-notification.has-icon .sn-title,
-//.simple-notification.has-icon .sn-content,
-//.simple-notification.has-icon .sn-html {
-// padding: 0 50px 0 0;
-//}
-//
-//.simple-notification {
-// position: absolute;
-// box-sizing: border-box;
-// top: 0;
-// right: 0;
-// width: 70px;
-// height: 70px;
-// padding: 10px;
-//}
-//
-//.simple-notification .icon.icon-hover:hover {
-// opacity: 0.5;
-//}
-//
-//.simple-notification .icon svg {
-// fill: #fff;
-// width: 100%;
-// height: 100%;
-//}
-//
-//.simple-notification .icon svg g {
-// fill: #fff;
-//}
-//
-//.simple-notification.rtl-mode.has-icon .sn-title,
-//.simple-notification.rtl-mode.has-icon .sn-content,
-//.simple-notification.rtl-mode.has-icon .sn-html {
-// padding: 0 0 0 50px;
-//}
-//
-//.simple-notification.rtl-mode {
-// direction: rtl;
-//}
-//
-//.simple-notification.rtl-mode .sn-content {
-// padding: 0 0 0 50px;
-//}
-//
-//.simple-notification.rtl-mode svg {
-// left: 0;
-// right: auto;
-//}
-
-.simple-notification.error { background: #F44336; }
-.simple-notification.success { background: #8BC34A; }
-.simple-notification.alert { background: #ffdb5b; }
-.simple-notification.info { background: #03A9F4; }
-.simple-notification.warn { background: #ffdb5b; }
-
-//.simple-notification .sn-progress-loader {
-// position: absolute;
-// top: 0;
-// left: 0;
-// width: 100%;
-// height: 5px;
-//}
-//
-//.simple-notification .sn-progress-loader span {
-// float: left;
-// height: 100%;
-//}
-
-.simple-notification.success .sn-progress-loader span { background: #689F38; }
-.simple-notification.error .sn-progress-loader span { background: #D32F2F; }
-.simple-notification.alert .sn-progress-loader span { background: #edc242; }
-.simple-notification.info .sn-progress-loader span { background: #0288D1; }
-.simple-notification.warn .sn-progress-loader span { background: #edc242; }
-.simple-notification.bare .sn-progress-loader span { background: #ccc; }
-
-//.simple-notification.warn div .sn-title,
-//.simple-notification.warn div .sn-content,
-//.simple-notification.warn div .sn-html { color: #444; }
-
-
-
.close {
float: right;
- padding-right: 5px;
- color: darkslategray;
+ margin-right: -15px;
+ margin-top: -10px;
}
.icon {
float: left;
+ margin-left: -10px;
padding: 5px;
- color: darkslategray;
}
-//
-//.icon > fa-times-circle {
-// color: red;
-//}
-//
-//.icon > fa-exclamation-triangle {
-// color: orange;
-//}
-//
-//.icon > fa-info {
-// color: white;
-//}
-//
-//.icon > fa-check {
-// color: forestgreen;
-//}
.sn-title, .sn-content, .sn-html {
position: relative;
left: 20px;
}
+
+//.simple-notification.error { background: #F44336; }
+//.simple-notification.success { background: #8BC34A; }
+//.simple-notification.alert { background: #ffdb5b; }
+//.simple-notification.info { background: #03A9F4; }
+//.simple-notification.warn { background: #ffdb5b; }
+//
+//.simple-notification.success .sn-progress-loader span { background: #689F38; }
+//.simple-notification.error .sn-progress-loader span { background: #D32F2F; }
+//.simple-notification.alert .sn-progress-loader span { background: #edc242; }
+//.simple-notification.info .sn-progress-loader span { background: #0288D1; }
+//.simple-notification.warn .sn-progress-loader span { background: #edc242; }
+//.simple-notification.bare .sn-progress-loader span { background: #ccc; }
+
+//.simple-notification.warn div .sn-title,
+//.simple-notification.warn div .sn-content,
+//.simple-notification.warn div .sn-html { color: #444; }
diff --git a/src/app/shared/notifications/notification/notification.component.ts b/src/app/shared/notifications/notification/notification.component.ts
index d228018d25..e1b97331e9 100644
--- a/src/app/shared/notifications/notification/notification.component.ts
+++ b/src/app/shared/notifications/notification/notification.component.ts
@@ -1,4 +1,5 @@
import {
+ AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
@@ -112,38 +113,40 @@ import { INotification } from '../models/notification.model';
export class NotificationComponent implements OnInit, OnDestroy {
- @Input() public timeOut: number;
+ // @Input() public timeOut: number;
// @Input() public showProgressBar: boolean;
// @Input() public pauseOnHover: boolean;
// @Input() public clickToClose: boolean;
// @Input() public clickIconToClose: boolean;
// @Input() public maxLength: number;
// @Input() public theClass: string;
- @Input() public rtl: boolean;
- @Input() public animate: string;
- @Input() public position: number;
+ // @Input() public rtl: boolean;
+ // @Input() public animate: string;
+ // @Input() public position: number;
@Input() public item: INotification;
// Progress bar variables
public title: any;
public content: any;
+ public html: any;
public titleIsTemplate = false;
public contentIsTemplate = false;
public htmlIsTemplate = false;
- public progressWidth = 0;
- public safeSvg: SafeHtml;
+ // public progressWidth = 0;
private stopTime = false;
private timer: any;
private steps: number;
private speed: number;
private count = 0;
- private start: any;
+ private start: any;
private diff: any;
- private icon: string;
+
+ // 'fade' | 'fromTop' | 'fromRight' | 'fromBottom' | 'fromLeft' | 'rotate' | 'scale' = 'fromRight';
+ public animate = 'rotate';
constructor(private notificationService: NotificationsService,
private domSanitizer: DomSanitizer,
@@ -152,70 +155,24 @@ export class NotificationComponent implements OnInit, OnDestroy {
}
ngOnInit(): void {
- // if (this.item.override) {
- // this.attachOverrides();
- // }
- //
- // if (this.animate) {
- // this.item.state = this.animate;
- // }
+ this.animate = this.item.options.animate;
- if (this.timeOut !== 0) {
+ if (this.item.options.timeOut !== 0) {
this.startTimeOut();
}
this.contentType(this.item.title, 'title');
this.contentType(this.item.content, 'content');
this.contentType(this.item.html, 'html');
-
- // this.safeSvg = this.domSanitizer.bypassSecurityTrustHtml(this.icon || this.item.icon);
}
startTimeOut(): void {
- this.steps = this.timeOut / 10;
- this.speed = this.timeOut / this.steps;
+ this.steps = this.item.options.timeOut / 10;
+ this.speed = this.item.options.timeOut / this.steps;
this.start = new Date().getTime();
this.zone.runOutsideAngular(() => this.timer = setTimeout(this.instance, this.speed));
}
- onEnter(): void {
- // if (this.pauseOnHover) {
- // this.stopTime = true;
- // }
- }
-
- onLeave(): void {
- // if (this.pauseOnHover) {
- // this.stopTime = false;
- // this.zone.runOutsideAngular(() => setTimeout(this.instance, (this.speed - this.diff)));
- // }
- }
-
- // onClick($e: MouseEvent): void {
- // this.item.click!.emit($e);
- //
- // // if (this.clickToClose) {
- // // this.remove();
- // // }
- // }
-
- // onClickIcon($e: MouseEvent): void {
- // this.item.clickIcon!.emit($e);
- //
- // // if (this.clickIconToClose) {
- // // this.remove();
- // // }
- // }
-
- // Attach all the overrides
- // attachOverrides(): void {
- // Object.keys(this.item.override).forEach((a) => {
- // if (this.hasOwnProperty(a)) {
- // (this as any)[a] = this.item.override[a];
- // }
- // });
- // }
-
ngOnDestroy(): void {
clearTimeout(this.timer);
}
@@ -237,17 +194,14 @@ export class NotificationComponent implements OnInit, OnDestroy {
};
private remove() {
- // if (this.animate) {
- // this.item.state = this.animate + 'Out';
- // setTimeout(() => {
- // this.notificationService.set(this.item, false);
- // }, 310);
- // } else {
- // this.notificationService.set(this.item, false);
- // }
-
- // this.notificationService.set(this.item, false);
- this.notificationService.remove(this.item);
+ if (this.animate) {
+ this.animate = this.animate + 'Out';
+ setTimeout(() => {
+ this.notificationService.remove(this.item);
+ }, 310);
+ } else {
+ this.notificationService.remove(this.item);
+ }
}
private contentType(item: any, key: string) {
diff --git a/src/app/shared/notifications/notifications-board/notifications-board.component.html b/src/app/shared/notifications/notifications-board/notifications-board.component.html
index a3f322f049..f7254c0610 100644
--- a/src/app/shared/notifications/notifications-board/notifications-board.component.html
+++ b/src/app/shared/notifications/notifications-board/notifications-board.component.html
@@ -1,11 +1,7 @@
+ [item]="a">
diff --git a/src/app/shared/notifications/notifications-board/notifications-board.component.ts b/src/app/shared/notifications/notifications-board/notifications-board.component.ts
index 6501bc7653..40ccf0984c 100644
--- a/src/app/shared/notifications/notifications-board/notifications-board.component.ts
+++ b/src/app/shared/notifications/notifications-board/notifications-board.component.ts
@@ -1,15 +1,22 @@
import {
- Component, EventEmitter, OnInit, OnDestroy, ViewEncapsulation, Input, Output,
- ChangeDetectionStrategy, ChangeDetectorRef
+ ChangeDetectionStrategy,
+ ChangeDetectorRef,
+ Component,
+ EventEmitter,
+ Input,
+ OnDestroy,
+ OnInit,
+ Output,
+ ViewEncapsulation
} from '@angular/core';
-import { Subscription } from 'rxjs/Subscription';
-import { Options } from '../interfaces/options.type';
-import { Notification } from '../interfaces/notification.type';
import { NotificationsService } from '../notifications.service';
import { Store } from '@ngrx/store';
-import { NotificationsActions, NotificationsActionTypes } from '../notifications.actions';
-import { notificationsReducer } from '../notifications.reducers';
import { AppState } from '../../../app.reducer';
+import { notificationsStateSelector } from '../selectors';
+import { difference } from 'lodash';
+import { INotification } from '../models/notification.model';
+import { NotificationsState } from '../notifications.reducers';
+import { INotificationBoardOptions } from '../models/notification-options.model';
@Component({
selector: 'ds-notifications-board',
@@ -20,33 +27,22 @@ import { AppState } from '../../../app.reducer';
})
export class NotificationsBoardComponent implements OnInit, OnDestroy {
- @Input() set options(opt: Options) {
+ @Input() set options(opt: INotificationBoardOptions) {
this.attachChanges(opt);
}
@Output() onCreate = new EventEmitter();
@Output() onDestroy = new EventEmitter();
- public notifications: Notification[] = [];
+ public notifications: INotification[] = [];
public position: ['top' | 'bottom' | 'middle', 'right' | 'left' | 'center'] = ['bottom', 'right'];
- private lastNotificationCreated: Notification;
- private listener: Subscription;
+ // private listener: Subscription;
// Received values
- private lastOnBottom = false;
private maxStack = 8;
- // private preventLastDuplicates: any = true;
- // private preventDuplicates = true;
// Sent values
- public timeOut = 0;
- // public maxLength = 0;
- // public clickToClose = true;
- // public clickIconToClose = false;
- // public showProgressBar = true;
- // public pauseOnHover = true;
- // public theClass = '';
public rtl = false;
public animate: 'fade' | 'fromTop' | 'fromRight' | 'fromBottom' | 'fromLeft' | 'rotate' | 'scale' = 'fromRight';
@@ -56,105 +52,56 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
}
ngOnInit(): void {
- this.listener = this.store.select()
- (action: NotificationsActions) => {
- notificationsReducer(this.notifications, action);
+ // this.listener =
+ this.store.select(notificationsStateSelector)
+ .subscribe((state: NotificationsState) => {
+ if (state.length === 0) {
+ this.notifications = [];
+ } else if (state.length > this.notifications.length) {
+ // Add
+ const newElem = difference(state, this.notifications);
+ console.log('new Elements #', newElem.length);
- // switch (action.type) {
- // case NotificationsActionTypes.NEW_NOTIFICATION:
- //
- // break;
- // case NotificationsActionTypes.NEW_NOTIFICATION_WITH_TIMER:
- //
- // break;
- // case NotificationsActionTypes.REMOVE_NOTIFICATION:
- //
- // break;
- // case NotificationsActionTypes.REMOVE_ALL_NOTIFICATIONS:
- //
- // break;
- // }
+ newElem.forEach((notification) => {
+ this.add(notification);
+ });
+ } else {
+ // Remove
+ const delElem = difference(this.notifications, state);
+ delElem.forEach((notification) => {
+ this.notifications = this.notifications.filter((item: INotification) => item.id !== notification.id);
+
+ });
+ }
+
+ console.log(this.notifications);
+ this.cdr.markForCheck();
});
-
- // Listen for changes in the service
- // this.listener = this.service.emitter
- // .subscribe((item) => { // Subscribe a stato di redux
- // switch (item.command) {
- // case 'cleanAll':
- // this.notifications = [];
- // break;
- //
- // case 'clean':
- // this.cleanSingle(item.id!);
- // break;
- //
- // case 'set':
- // if (item.add) {
- // this.add(item.notification!);
- // } else {
- // this.defaultBehavior(item);
- // }
- // break;
- //
- // default:
- // this.defaultBehavior(item);
- // break;
- // }
- //
- // this.cdr.markForCheck();
- // });
- }
-
- // Default behavior on event
- defaultBehavior(value: any): void {
- this.notifications.splice(this.notifications.indexOf(value.notification), 1);
- this.onDestroy.emit(this.buildEmit(value.notification, false));
}
// Add the new notification to the notification array
- add(item: Notification): void {
- item.createdOn = new Date();
-
- // const toBlock: boolean = this.preventLastDuplicates || this.preventDuplicates ? this.block(item) : false;
-
- // Save this as the last created notification
- this.lastNotificationCreated = item;
- // Override icon if set
- if (item.override && item.override.icons && item.override.icons[item.type]) {
- item.icon = item.override.icons[item.type];
+ add(item: INotification): void {
+ const toBlock: boolean = this.block(item);
+ if (!toBlock) {
+ if (this.notifications.length >= this.maxStack) {
+ this.notifications.splice(this.notifications.length - 1, 1);
+ }
+ this.notifications.splice(0, 0, item);
}
-
- // if (!toBlock) {
- // // Check if the notification should be added at the start or the end of the array
- // if (this.lastOnBottom) {
- // if (this.notifications.length >= this.maxStack) {
- // this.notifications.splice(0, 1);
- // }
- //
- // this.notifications.push(item);
- // } else {
- // if (this.notifications.length >= this.maxStack) {
- // this.notifications.splice(this.notifications.length - 1, 1);
- // }
- //
- // this.notifications.splice(0, 0, item);
- // }
- //
- // this.onCreate.emit(this.buildEmit(item, true));
- // }
}
- // Check if notifications should be prevented
- block(item: Notification): boolean {
-
- const toCheck = item.html ? this.checkHtml : this.checkStandard;
-
- this.notifications.forEach((notification) => {
- if (toCheck(notification, item)) {
- return true;
- }
- });
+ //
+ // // Check if notifications should be prevented
+ block(item: INotification): boolean {
+ // const toCheck = item.html ? this.checkHtml : this.checkStandard;
+ //
+ // this.notifications.forEach((notification) => {
+ // if (toCheck(notification, item)) {
+ // return true;
+ // }
+ // });
+ //
// if (this.notifications.length > 0) {
// for (let i = 0; i < this.notifications.length; i++) {
// if (toCheck(this.notifications[i], item)) {
@@ -163,32 +110,33 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
// }
// }
//
- // if (this.preventLastDuplicates) {
+ // // if (this.preventLastDuplicates) {
//
// let comp: Notification;
//
- // if (this.preventLastDuplicates === 'visible' && this.notifications.length > 0) {
- // if (this.lastOnBottom) {
- // comp = this.notifications[this.notifications.length - 1];
- // } else {
+ // if ( this.notifications.length > 0) {
+ // // if (this.lastOnBottom) {
+ // // comp = this.notifications[this.notifications.length - 1];
+ // // }
+ // // else {
// comp = this.notifications[0];
- // }
- // } else if (this.preventLastDuplicates === 'all' && this.lastNotificationCreated) {
- // comp = this.lastNotificationCreated;
+ // // }
+ // // } else if (this.preventLastDuplicates === 'all' && this.lastNotificationCreated) {
+ // // comp = this.lastNotificationCreated;
// } else {
// return false;
// }
// return toCheck(comp, item);
- // }
-
+ // // }
+ //
return false;
}
- checkStandard(checker: Notification, item: Notification): boolean {
+ checkStandard(checker: INotification, item: INotification): boolean {
return checker.type === item.type && checker.title === item.title && checker.content === item.content;
}
- checkHtml(checker: Notification, item: Notification): boolean {
+ checkHtml(checker: INotification, item: INotification): boolean {
return checker.html ? checker.type === item.type && checker.title === item.title && checker.content === item.content && checker.html === item.html : false;
}
@@ -197,56 +145,13 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
Object.keys(options).forEach((a) => {
if (this.hasOwnProperty(a)) {
(this as any)[a] = options[a];
- } else if (a === 'icons') {
- // this.service.icons = options[a];
}
});
}
- buildEmit(notification: Notification, to: boolean) {
- const toEmit: Notification = {
- createdOn: notification.createdOn,
- type: notification.type,
- icon: notification.icon,
- id: notification.id
- };
-
- if (notification.html) {
- toEmit.html = notification.html;
- } else {
- toEmit.title = notification.title;
- toEmit.content = notification.content;
- }
-
- if (!to) {
- toEmit.destroyedOn = new Date();
- }
-
- return toEmit;
- }
-
- cleanSingle(id: string): void {
- let indexOfDelete = 0;
- let doDelete = false;
- let noti;
-
- this.notifications.forEach((notification, idx) => {
- if (notification.id === id) {
- indexOfDelete = idx;
- noti = notification;
- doDelete = true;
- }
- });
-
- if (doDelete) {
- this.notifications.splice(indexOfDelete, 1);
- this.onDestroy.emit(this.buildEmit(noti, false));
- }
- }
-
ngOnDestroy(): void {
- if (this.listener) {
- this.listener.unsubscribe();
- }
+ // if (this.listener) {
+ // this.listener.unsubscribe();
+ // }
}
}
diff --git a/src/app/shared/notifications/notifications.service.ts b/src/app/shared/notifications/notifications.service.ts
index 4a82ff9eec..60efd32700 100644
--- a/src/app/shared/notifications/notifications.service.ts
+++ b/src/app/shared/notifications/notifications.service.ts
@@ -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();
+
// public emitter = new Subject();
// public icons: Icons = defaultIcons;
- constructor(private store: Store) {
+ constructor(private store: Store,
+ 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);
}