Matteo Scandolo | 63e43eb | 2016-12-14 14:18:53 -0800 | [diff] [blame] | 1 | import './header.scss'; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 2 | import {StyleConfig} from '../../config/style.config'; |
Matteo Scandolo | 63e43eb | 2016-12-14 14:18:53 -0800 | [diff] [blame] | 3 | import {IStoreService} from '../../datasources/stores/slices.store'; |
| 4 | import {IWSEvent} from '../../datasources/websocket/global'; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 5 | |
Matteo Scandolo | c719e79 | 2016-12-14 15:48:31 -0800 | [diff] [blame^] | 6 | interface INotification extends IWSEvent { |
| 7 | viewed?: boolean; |
| 8 | } |
| 9 | |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 10 | class HeaderController { |
Matteo Scandolo | 63e43eb | 2016-12-14 14:18:53 -0800 | [diff] [blame] | 11 | static $inject = ['SynchronizerStore']; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 12 | public title: string; |
Matteo Scandolo | c719e79 | 2016-12-14 15:48:31 -0800 | [diff] [blame^] | 13 | public notifications: INotification[] = []; |
| 14 | public newNotifications: INotification[] = []; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 15 | |
Matteo Scandolo | 63e43eb | 2016-12-14 14:18:53 -0800 | [diff] [blame] | 16 | constructor( |
| 17 | private syncStore: IStoreService |
| 18 | ) { |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 19 | this.title = StyleConfig.projectName; |
Matteo Scandolo | 63e43eb | 2016-12-14 14:18:53 -0800 | [diff] [blame] | 20 | |
| 21 | this.syncStore.query() |
| 22 | .subscribe( |
| 23 | (event: IWSEvent) => { |
Matteo Scandolo | c719e79 | 2016-12-14 15:48:31 -0800 | [diff] [blame^] | 24 | this.notifications.unshift(event); |
| 25 | this.newNotifications = this.getNewNotifications(this.notifications); |
Matteo Scandolo | 63e43eb | 2016-12-14 14:18:53 -0800 | [diff] [blame] | 26 | } |
| 27 | ); |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 28 | } |
Matteo Scandolo | c719e79 | 2016-12-14 15:48:31 -0800 | [diff] [blame^] | 29 | |
| 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 Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | export const xosHeader: angular.IComponentOptions = { |
| 43 | template: require('./header.html'), |
| 44 | controllerAs: 'vm', |
| 45 | controller: HeaderController |
| 46 | }; |