all files / directives/ ng2-notify.ts

95.45% Statements 21/22
100% Branches 0/0
85.71% Functions 6/7
95% Lines 19/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                         
///<reference path="../../../typings/browser.d.ts"/>
import {bootstrap} from 'angular2/platform/browser';
import {Component, View, Input} from 'angular2/core';
import {Ng2NotifyService} from '../services/ng2-notify';
 
@Component({
	selector: 'ng2-notify',
	bindings: [Ng2NotifyService],
	template: `
		<ul class="{{corner}}">
			<li *ngFor="#notification of notifications" class="{{notification.type || 'default' }}" [ngClass]="{'animate': notification.notify}" (mouseenter)="clear()" (click)="notification.notify = !notification.notify">
						{{ notification.message }}
				</li>
		</ul>
	`,
})
 
export class Ng2Notify {
	public notifications: any;
	public corner: string = null;
 
	constructor(public notifyService: Ng2NotifyService) {
		this.notifyService.notify.subscribe(uploaded => {
				this.setNotify(uploaded);
		});
		this.notifications = [];
	};
 
	// private clear(obj) {
	// 	clearTimeout(obj);
	// }
 
	public createTimeout(notification) {
		notification.timeout = setTimeout(() => {
			notification.notify = !notification.notify;
			setTimeout(() => {
				this.notifications.shift();
			}, 500);
		}, notification.delay);
	}
 
	public setNotify(obj) {
		obj.notify = true;
		this.corner = obj.corner;
		this.notifications.push(obj);
		this.createTimeout(obj);
	}
}