blob: 140abff1a99c2a50266db4a68beaf4695e2a8bab [file] [log] [blame]
Matteo Scandolo63e43eb2016-12-14 14:18:53 -08001import './header.scss';
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08002import {StyleConfig} from '../../config/style.config';
Matteo Scandolo63e43eb2016-12-14 14:18:53 -08003import {IStoreService} from '../../datasources/stores/slices.store';
4import {IWSEvent} from '../../datasources/websocket/global';
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08005
Matteo Scandoloc719e792016-12-14 15:48:31 -08006interface INotification extends IWSEvent {
7 viewed?: boolean;
8}
9
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080010class HeaderController {
Matteo Scandolo63e43eb2016-12-14 14:18:53 -080011 static $inject = ['SynchronizerStore'];
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080012 public title: string;
Matteo Scandoloc719e792016-12-14 15:48:31 -080013 public notifications: INotification[] = [];
14 public newNotifications: INotification[] = [];
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080015
Matteo Scandolo63e43eb2016-12-14 14:18:53 -080016 constructor(
17 private syncStore: IStoreService
18 ) {
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080019 this.title = StyleConfig.projectName;
Matteo Scandolo63e43eb2016-12-14 14:18:53 -080020
21 this.syncStore.query()
22 .subscribe(
23 (event: IWSEvent) => {
Matteo Scandoloc719e792016-12-14 15:48:31 -080024 this.notifications.unshift(event);
25 this.newNotifications = this.getNewNotifications(this.notifications);
Matteo Scandolo63e43eb2016-12-14 14:18:53 -080026 }
27 );
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080028 }
Matteo Scandoloc719e792016-12-14 15:48:31 -080029
30 public viewNotification = (notification: INotification) => {
31 notification.viewed = true;
32 this.newNotifications = this.getNewNotifications(this.notifications);
33 };
34
35 private getNewNotifications = (notifications: INotification[]) => {
36 return this.notifications.filter((n: INotification) => {
37 return !n.viewed;
38 });
39 };
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080040}
41
42export const xosHeader: angular.IComponentOptions = {
43 template: require('./header.html'),
44 controllerAs: 'vm',
45 controller: HeaderController
46};