blob: c91ef5fe2fc9112f77c142dbc58a20676f9d9f82 [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 {IWSEvent} from '../../datasources/websocket/global';
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08004import {IStoreService} from '../../datasources/stores/synchronizer.store';
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 Scandolof2c3ed62016-12-15 14:32:50 -080011 static $inject = ['$scope', '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(
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080017 private $scope: angular.IScope,
Matteo Scandolo63e43eb2016-12-14 14:18:53 -080018 private syncStore: IStoreService
19 ) {
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080020 this.title = StyleConfig.projectName;
Matteo Scandolo63e43eb2016-12-14 14:18:53 -080021
22 this.syncStore.query()
23 .subscribe(
24 (event: IWSEvent) => {
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080025 $scope.$evalAsync(() => {
26 this.notifications.unshift(event);
27 this.newNotifications = this.getNewNotifications(this.notifications);
28 });
Matteo Scandolo63e43eb2016-12-14 14:18:53 -080029 }
30 );
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080031 }
Matteo Scandoloc719e792016-12-14 15:48:31 -080032
33 public viewNotification = (notification: INotification) => {
34 notification.viewed = true;
35 this.newNotifications = this.getNewNotifications(this.notifications);
36 };
37
38 private getNewNotifications = (notifications: INotification[]) => {
39 return this.notifications.filter((n: INotification) => {
40 return !n.viewed;
41 });
42 };
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080043}
44
45export const xosHeader: angular.IComponentOptions = {
46 template: require('./header.html'),
47 controllerAs: 'vm',
48 controller: HeaderController
49};