Skip to content
Snippets Groups Projects
Commit afc915b9 authored by Andrea Chiapparelli - 4Science's avatar Andrea Chiapparelli - 4Science
Browse files

duplicates

parent 74dc5f80
No related merge requests found
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
<button (click)="createNotification2()">Notify!</button> <button (click)="createNotification2()">Notify!</button>
<ng-template #example> <button (click)="deleteHtmlNotification()">Delete Html Notification</button>
<p>Simple Error example</p> <button (click)="deleteAllNotifications()">Delete All</button>
<button [routerLink]="['/mydspace']">Go to mydspace</button>
</ng-template> <!--<ng-template #example>-->
<!--<p>Simple Error example</p>-->
<!--<button [routerLink]="['/mydspace']">Go to mydspace</button>-->
<!--</ng-template>-->
import { Component, TemplateRef, ViewChild } from '@angular/core'; import { Component, TemplateRef, ViewChild } from '@angular/core';
import { NotificationsService } from '../shared/notifications/notifications.service'; import { NotificationsService } from '../shared/notifications/notifications.service';
import { import { NotificationOptions } from '../shared/notifications/models/notification-options.model';
INotificationBoardOptions,
NotificationOptions
} from '../shared/notifications/models/notification-options.model';
@Component({ @Component({
selector: 'ds-home-page', selector: 'ds-home-page',
...@@ -13,45 +10,31 @@ import { ...@@ -13,45 +10,31 @@ import {
export class HomePageComponent { export class HomePageComponent {
@ViewChild('example') example: TemplateRef<any>; @ViewChild('example') example: TemplateRef<any>;
private htmlNotification;
constructor(private notificationsService: NotificationsService) { constructor(private notificationsService: NotificationsService) {
} }
createNotification() { createNotification() {
const n1 = this.notificationsService.success('Welcome in DSpace', 'Good choice!', const n1 = this.notificationsService.success('Welcome in DSpace', 'Good choice!',
new NotificationOptions(10000, false, 'fromLeft', ['bottom', 'left'])); new NotificationOptions(10000, true, 'fromLeft', ['bottom', 'left']));
// const n2 = this.notificationsService.info('Info in DSpace', 'For your info...!');
// const n3 = this.notificationsService.warning('Warning in DSpace', 'This is a fake alert!');
// // const n4 = this.notificationsService.danger(this.example);
// console.log('Notifications pushed');
// console.log(n1);
// console.log(n2);
// console.log(n3);
// // console.log(n4);
} }
createNotification1() { createNotification1() {
const n1 = this.notificationsService.warning('Welcome in DSpace', 'Good choice!', const n1 = this.notificationsService.warning('Welcome in DSpace', 'Good choice!',
new NotificationOptions(10000, false, 'fromLeft', ['bottom', 'left'])); new NotificationOptions(10000, false, 'fromLeft', ['bottom', 'left']));
// const n2 = this.notificationsService.info('Info in DSpace', 'For your info...!');
// const n3 = this.notificationsService.warning('Warning in DSpace', 'This is a fake alert!');
// // const n4 = this.notificationsService.danger(this.example);
// console.log('Notifications pushed');
// console.log(n1);
// console.log(n2);
// console.log(n3);
// // console.log(n4);
} }
createNotification2() { createNotification2() {
// const n1 = this.notificationsService.error('Welcome in DSpace', 'Good choice!', const html = "<h1>Html Alert</h1> <p><button [routerLink]=\"['/mydspace']\">Go to mydspace</button></p>";
// new NotificationOptions(100000, false, 'fromLeft', ['bottom', 'left'])); this.htmlNotification = this.notificationsService.info('Ciao', null, null, html);
// const n2 = this.notificationsService.info('Info in DSpace', 'For your info...!'); }
// const n3 = this.notificationsService.warning('Warning in DSpace', 'This is a fake alert!');
const n4 = this.notificationsService.html(this.example); deleteHtmlNotification() {
// console.log('Notifications pushed'); this.notificationsService.remove(this.htmlNotification);
// console.log(n1); }
// console.log(n2);
// console.log(n3); deleteAllNotifications() {
// // console.log(n4); this.notificationsService.removeAll();
} }
} }
...@@ -21,27 +21,30 @@ export class Notification implements INotification { ...@@ -21,27 +21,30 @@ export class Notification implements INotification {
public title: any; public title: any;
public content: any; public content: any;
public options: INotificationOptions; public options: INotificationOptions;
public html: any;
constructor(id: string, constructor(id: string,
type: NotificationType, type: NotificationType,
title?: any, title?: any,
content?: any, content?: any,
options?: NotificationOptions) { options?: NotificationOptions,
html?: any) {
this.id = id; this.id = id;
this.type = type; this.type = type;
this.title = title; this.title = title;
this.content = content; this.content = content;
this.options = isEmpty(options) ? new NotificationOptions() : options; this.options = isEmpty(options) ? new NotificationOptions() : options;
this.html = html;
} }
get html() { // get html() {
if (this.title === '' && this.content === '') { // if (this.title === '' && this.content === '') {
return NotificationsService.htmlArray.get(this.id); // return NotificationsService.htmlArray.get(this.id);
} else { // } else {
return null; // return null;
} // }
} // }
} }
<div class="alert {{item.type}}" role="alert" <div class="alert {{item.type}} alert-dismissible" role="alert"
[@enterLeave]="animate" [@enterLeave]="animate"
[ngClass]="{ [ngClass]="{
'rtl-mode': rtl 'rtl-mode': rtl
...@@ -12,12 +12,18 @@ ...@@ -12,12 +12,18 @@
'fa-info': item.type == 'alert-info' 'fa-info': item.type == 'alert-info'
}"></i></div> }"></i></div>
<div class="close" (click)="remove()"><i class="fa fa-times"></i></div> <!--<div class="close" (click)="remove()">-->
<button *ngIf="item.options.clickToClose"
(click)="remove()"
type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<div *ngIf="!item.html">
<div *ngIf="!item.html">
<div class="sn-title" *ngIf="titleIsTemplate; else regularTitle"> <div class="sn-title" *ngIf="titleIsTemplate; else regularTitle">
<ng-container *ngTemplateOutlet="title"></ng-container> <ng-container *ngTemplateOutlet="title"></ng-container>
...@@ -42,11 +48,11 @@ ...@@ -42,11 +48,11 @@
<div *ngIf="item.html"> <div *ngIf="item.html">
<div class="sn-html" *ngIf="htmlIsTemplate; else regularHtml"> <div class="sn-html" *ngIf="htmlIsTemplate; else regularHtml">
<ng-container *ngTemplateOutlet="item.html"></ng-container> <ng-container *ngTemplateOutlet="html"></ng-container>
</div> </div>
<ng-template #regularHtml> <ng-template #regularHtml>
<div class="sn-content" [innerHTML]="item.html"></div> <div class="sn-content" [innerHTML]="html"></div>
</ng-template> </ng-template>
......
.close { //.close {
float: right; // float: right;
margin-right: -15px; // margin-right: -15px;
margin-top: -10px; // margin-top: -10px;
//}
close:active {
border: 0;
} }
.icon { .icon {
......
import { import {
AfterViewInit,
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
...@@ -11,7 +10,7 @@ import { ...@@ -11,7 +10,7 @@ import {
ViewEncapsulation ViewEncapsulation
} from '@angular/core'; } from '@angular/core';
import { animate, state, style, transition, trigger } from '@angular/animations'; import { animate, state, style, transition, trigger } from '@angular/animations';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';
import { NotificationsService } from '../notifications.service'; import { NotificationsService } from '../notifications.service';
import { INotification } from '../models/notification.model'; import { INotification } from '../models/notification.model';
...@@ -103,7 +102,7 @@ import { INotification } from '../models/notification.model'; ...@@ -103,7 +102,7 @@ import { INotification } from '../models/notification.model';
transition('rotate => rotateOut', [ transition('rotate => rotateOut', [
style({opacity: 1, transform: 'rotate(0deg)'}), style({opacity: 1, transform: 'rotate(0deg)'}),
animate('400ms ease-in-out') animate('400ms ease-in-out')
]) ]),
]) ])
], ],
templateUrl: './notification.component.html', templateUrl: './notification.component.html',
...@@ -129,7 +128,6 @@ export class NotificationComponent implements OnInit, OnDestroy { ...@@ -129,7 +128,6 @@ export class NotificationComponent implements OnInit, OnDestroy {
public title: any; public title: any;
public content: any; public content: any;
public html: any; public html: any;
public titleIsTemplate = false; public titleIsTemplate = false;
public contentIsTemplate = false; public contentIsTemplate = false;
public htmlIsTemplate = false; public htmlIsTemplate = false;
...@@ -195,7 +193,7 @@ export class NotificationComponent implements OnInit, OnDestroy { ...@@ -195,7 +193,7 @@ export class NotificationComponent implements OnInit, OnDestroy {
private remove() { private remove() {
if (this.animate) { if (this.animate) {
this.animate = this.animate + 'Out'; // this.animate = this.animate + 'Out';
setTimeout(() => { setTimeout(() => {
this.notificationService.remove(this.item); this.notificationService.remove(this.item);
}, 310); }, 310);
...@@ -213,4 +211,8 @@ export class NotificationComponent implements OnInit, OnDestroy { ...@@ -213,4 +211,8 @@ export class NotificationComponent implements OnInit, OnDestroy {
this[key + 'IsTemplate'] = item instanceof TemplateRef; this[key + 'IsTemplate'] = item instanceof TemplateRef;
} }
// setAnimationOut() {
// this.animate = this.animate + 'Out';
// }
} }
...@@ -73,8 +73,6 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy { ...@@ -73,8 +73,6 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
}); });
} }
console.log(this.notifications);
this.cdr.markForCheck(); this.cdr.markForCheck();
}); });
} }
...@@ -87,49 +85,37 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy { ...@@ -87,49 +85,37 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
this.notifications.splice(this.notifications.length - 1, 1); this.notifications.splice(this.notifications.length - 1, 1);
} }
this.notifications.splice(0, 0, item); this.notifications.splice(0, 0, item);
} else {
// Remove the notification from the store
// This notification was in the store, but not in this.notifications
// because it was a blocked duplicate
this.service.remove(item);
} }
} }
//
// // Check if notifications should be prevented
block(item: INotification): boolean { block(item: INotification): boolean {
const toCheck = item.html ? this.checkHtml : this.checkStandard;
this.notifications.forEach((notification) => {
if (toCheck(notification, item)) {
return true;
}
});
// const toCheck = item.html ? this.checkHtml : this.checkStandard; if (this.notifications.length > 0) {
// this.notifications.forEach( (notification) => {
// this.notifications.forEach((notification) => { if (toCheck(notification, item)) {
// if (toCheck(notification, item)) { return true;
// return true; }
// } });
// }); }
//
// if (this.notifications.length > 0) { let comp: INotification;
// for (let i = 0; i < this.notifications.length; i++) { if (this.notifications.length > 0) {
// if (toCheck(this.notifications[i], item)) { comp = this.notifications[0];
// return true; } else {
// } return false;
// } }
// } return toCheck(comp, item);
//
// // if (this.preventLastDuplicates) {
//
// let comp: Notification;
//
// 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 {
// return false;
// }
// return toCheck(comp, item);
// // }
//
return false;
} }
checkStandard(checker: INotification, item: INotification): boolean { checkStandard(checker: INotification, item: INotification): boolean {
......
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { INotification, Notification } from './models/notification.model'; import { INotification, Notification } from './models/notification.model';
// import {Icons, defaultIcons} from './interfaces/icons';
import { NotificationType } from './models/notification-type'; import { NotificationType } from './models/notification-type';
import { NotificationOptions } from './models/notification-options.model'; import { NotificationOptions } from './models/notification-options.model';
import { uniqueId } from 'lodash'; import { uniqueId } from 'lodash';
...@@ -16,13 +15,8 @@ import { DomSanitizer } from '@angular/platform-browser'; ...@@ -16,13 +15,8 @@ import { DomSanitizer } from '@angular/platform-browser';
@Injectable() @Injectable()
export class NotificationsService { 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 domSanitizer: DomSanitizer,) {
} }
private add(notification: Notification) { private add(notification: Notification) {
...@@ -35,47 +29,37 @@ export class NotificationsService { ...@@ -35,47 +29,37 @@ export class NotificationsService {
this.store.dispatch(notificationAction); this.store.dispatch(notificationAction);
} }
success(title: any = '', content: any = '', options = new NotificationOptions()): Notification { success(title: any = '', content: any = '', options = new NotificationOptions(), html?: any): INotification {
const notification = new Notification(uniqueId(), NotificationType.Success, title, content, options); const notification = new Notification(uniqueId(), NotificationType.Success, title, content, options, html);
this.add(notification);
return notification;
}
error(title: any = '', content: any = '', options = new NotificationOptions()): Notification {
const notification = new Notification(uniqueId(), NotificationType.Error, title, content, options);
this.add(notification); this.add(notification);
return notification; return notification;
} }
info(title: any = '', content: any = '', options = new NotificationOptions()): Notification { error(title: any = '', content: any = '', options = new NotificationOptions(), html?: any): INotification {
const notification = new Notification(uniqueId(), NotificationType.Info, title, content, options); const notification = new Notification(uniqueId(), NotificationType.Error, title, content, options, html);
this.add(notification); this.add(notification);
return notification; return notification;
} }
warning(title: any = '', content: any = '', options = new NotificationOptions()): Notification { info(title: any = '', content: any = '', options = new NotificationOptions(), html?: any): INotification {
const notification = new Notification(uniqueId(), NotificationType.Warning, title, content, options); const notification = new Notification(uniqueId(), NotificationType.Info, title, content, options, html);
this.add(notification); this.add(notification);
return notification; return notification;
} }
html(html: any, type = NotificationType.Success, options = new NotificationOptions()): Notification { warning(title: any = '', content: any = '', options = new NotificationOptions(), html?: any): INotification {
const notification = new Notification(uniqueId(), type, '', '', options); const notification = new Notification(uniqueId(), NotificationType.Warning, title, content, options, html);
NotificationsService.htmlArray.set(notification.id, html);
// notification.html = true;
this.add(notification); this.add(notification);
return notification; return notification;
} }
remove(notification: INotification) { remove(notification: INotification) {
const actionRemove = new RemoveNotificationAction(notification.id); const actionRemove = new RemoveNotificationAction(notification.id);
NotificationsService.htmlArray.delete(notification.id);
this.store.dispatch(actionRemove); this.store.dispatch(actionRemove);
} }
removeAll() { removeAll() {
const actionRemoveAll = new RemoveAllNotificationsAction(); const actionRemoveAll = new RemoveAllNotificationsAction();
NotificationsService.htmlArray.clear();
this.store.dispatch(actionRemoveAll); this.store.dispatch(actionRemoveAll);
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment