1 import { Component, Input, OnInit } from '@angular/core'
2 import { UserNotificationService } from '@app/shared/users/user-notification.service'
3 import { UserNotificationType } from '../../../../../shared'
4 import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pagination.model'
5 import { Notifier } from '@app/core'
6 import { UserNotification } from '@app/shared/users/user-notification.model'
9 selector: 'my-user-notifications',
10 templateUrl: 'user-notifications.component.html',
11 styleUrls: [ 'user-notifications.component.scss' ]
13 export class UserNotificationsComponent implements OnInit {
14 @Input() ignoreLoadingBar = false
15 @Input() infiniteScroll = true
17 notifications: UserNotification[] = []
19 // So we can access it in the template
20 UserNotificationType = UserNotificationType
22 componentPagination: ComponentPagination = {
29 private userNotificationService: UserNotificationService,
30 private notifier: Notifier
34 this.loadMoreNotifications()
37 loadMoreNotifications () {
38 this.userNotificationService.listMyNotifications(this.componentPagination, undefined, this.ignoreLoadingBar)
41 this.notifications = this.notifications.concat(result.data)
42 this.componentPagination.totalItems = result.total
45 err => this.notifier.error(err.message)
50 if (this.infiniteScroll === false) return
52 this.componentPagination.currentPage++
54 if (hasMoreItems(this.componentPagination)) {
55 this.loadMoreNotifications()
59 markAsRead (notification: UserNotification) {
60 this.userNotificationService.markAsRead(notification)
63 notification.read = true
66 err => this.notifier.error(err.message)
71 this.userNotificationService.markAllAsRead()
74 for (const notification of this.notifications) {
75 notification.read = true
79 err => this.notifier.error(err.message)