notification options in configuration

This commit is contained in:
Andrea Chiapparelli - 4Science
2018-03-07 14:55:02 +01:00
parent 580a7f6d55
commit 6397e6fae8
7 changed files with 16 additions and 47 deletions

View File

@@ -21,6 +21,12 @@ module.exports = {
msToLive: 15 * 60 * 1000, // 15 minute msToLive: 15 * 60 * 1000, // 15 minute
control: 'max-age=60' // revalidate browser control: 'max-age=60' // revalidate browser
}, },
// Notifications
notifications: {
rtl: false,
position: ['top', 'right'],
maxStack: 8
},
// Angular Universal settings // Angular Universal settings
universal: { universal: {
preboot: true, preboot: true,

View File

@@ -3,9 +3,7 @@
<ds-header></ds-header> <ds-header></ds-header>
<ds-notifications-board <ds-notifications-board
[options]="boardOptions" [options]="config.notifications">
(onCreate)="notificationCreated($event)"
(onDestroy)="notificationDestroyed($event)">
</ds-notifications-board> </ds-notifications-board>
<main class="main-content"> <main class="main-content">

View File

@@ -10,7 +10,6 @@ import { MetadataService } from './core/metadata/metadata.service';
import { HostWindowResizeAction } from './shared/host-window.actions'; import { HostWindowResizeAction } from './shared/host-window.actions';
import { HostWindowState } from './shared/host-window.reducer'; import { HostWindowState } from './shared/host-window.reducer';
import { NativeWindowRef, NativeWindowService } from './shared/window.service'; import { NativeWindowRef, NativeWindowService } from './shared/window.service';
import { INotificationBoardOptions } from './shared/notifications/models/notification-options.model';
@Component({ @Component({
selector: 'ds-app', selector: 'ds-app',
@@ -21,22 +20,6 @@ import { INotificationBoardOptions } from './shared/notifications/models/notific
}) })
export class AppComponent implements OnInit { export class AppComponent implements OnInit {
public boardOptions: INotificationBoardOptions = {
position: ['top', 'right'],
maxStack: 5,
rtl: false
};
notificationCreated(event) {
console.log('Notification created');
console.log(event);
}
notificationDestroyed() {
console.log('Notification destroyed');
console.log(event);
}
constructor(@Inject(GLOBAL_CONFIG) public config: GlobalConfig, constructor(@Inject(GLOBAL_CONFIG) public config: GlobalConfig,
@Inject(NativeWindowService) private _window: NativeWindowRef, @Inject(NativeWindowService) private _window: NativeWindowRef,
private translate: TranslateService, private translate: TranslateService,

View File

@@ -3,35 +3,20 @@ import { NotificationAnimationsType } from './notification-animations-type';
export interface INotificationOptions { export interface INotificationOptions {
timeOut: number; timeOut: number;
clickToClose: boolean; clickToClose: boolean;
rtl: boolean;
animate: NotificationAnimationsType; animate: NotificationAnimationsType;
position: ['top' | 'bottom' | 'middle', 'right' | 'left' | 'center'];
} }
export class NotificationOptions implements INotificationOptions { export class NotificationOptions implements INotificationOptions {
public timeOut: number; public timeOut: number;
public clickToClose: boolean; public clickToClose: boolean;
public rtl: boolean;
public animate: any; public animate: any;
public position: any;
constructor(timeOut = 0, constructor(timeOut = 0,
clickToClose = true, clickToClose = true,
animate = NotificationAnimationsType.Scale, animate = NotificationAnimationsType.Scale) {
position = ['top' , 'right'],
rtl = false) {
this.timeOut = timeOut; this.timeOut = timeOut;
this.clickToClose = clickToClose; this.clickToClose = clickToClose;
this.animate = animate; this.animate = animate;
this.position = position;
this.rtl = rtl;
} }
} }
export interface INotificationBoardOptions {
rtl: boolean;
position: ['top' | 'bottom' | 'middle', 'right' | 'left' | 'center'];
maxStack: number;
maxLength?: number;
}

View File

@@ -61,11 +61,8 @@ export class NotificationComponent implements OnInit, OnDestroy {
private steps: number; private steps: number;
private speed: number; private speed: number;
private count = 0; private count = 0;
private start: any; private start: any;
private diff: any; private diff: any;
// 'fade' | 'fromTop' | 'fromRight' | 'fromBottom' | 'fromLeft' | 'rotate' | 'scale' ;
public animate: string; public animate: string;
constructor(private notificationService: NotificationsService, constructor(private notificationService: NotificationsService,

View File

@@ -2,11 +2,9 @@ import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
EventEmitter,
Input, Input,
OnDestroy, OnDestroy,
OnInit, OnInit,
Output,
ViewEncapsulation ViewEncapsulation
} from '@angular/core'; } from '@angular/core';
import { NotificationsService } from '../notifications.service'; import { NotificationsService } from '../notifications.service';
@@ -16,8 +14,8 @@ import { notificationsStateSelector } from '../selectors';
import { difference } from 'lodash'; import { difference } from 'lodash';
import { INotification } from '../models/notification.model'; import { INotification } from '../models/notification.model';
import { NotificationsState } from '../notifications.reducers'; import { NotificationsState } from '../notifications.reducers';
import { INotificationBoardOptions } from '../models/notification-options.model';
import { Subscription } from 'rxjs/Subscription'; import { Subscription } from 'rxjs/Subscription';
import { INotificationBoardOptions } from '../../../../config/notifications-config.interfaces';
@Component({ @Component({
selector: 'ds-notifications-board', selector: 'ds-notifications-board',
@@ -33,9 +31,6 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
this.attachChanges(opt); this.attachChanges(opt);
} }
@Output() onCreate = new EventEmitter();
@Output() onDestroy = new EventEmitter();
public notifications: INotification[] = []; public notifications: INotification[] = [];
public position: ['top' | 'bottom' | 'middle', 'right' | 'left' | 'center'] = ['bottom', 'right']; public position: ['top' | 'bottom' | 'middle', 'right' | 'left' | 'center'] = ['bottom', 'right'];
@@ -60,8 +55,6 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
} else if (state.length > this.notifications.length) { } else if (state.length > this.notifications.length) {
// Add // Add
const newElem = difference(state, this.notifications); const newElem = difference(state, this.notifications);
console.log('new Elements #', newElem.length);
newElem.forEach((notification) => { newElem.forEach((notification) => {
this.add(notification); this.add(notification);
}); });

View File

@@ -0,0 +1,7 @@
import { Config } from './config.interface';
export interface INotificationBoardOptions extends Config {
rtl: boolean;
position: ['top' | 'bottom' | 'middle', 'right' | 'left' | 'center'];
maxStack: number;
}