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
16 @Input() itemsPerPage = 20
18 notifications: UserNotification[] = []
20 // So we can access it in the template
21 UserNotificationType = UserNotificationType
23 componentPagination: ComponentPagination = {
25 itemsPerPage: this.itemsPerPage,
30 private userNotificationService: UserNotificationService,
31 private notifier: Notifier
35 this.loadMoreNotifications()
38 loadMoreNotifications () {
39 this.userNotificationService.listMyNotifications(this.componentPagination, undefined, this.ignoreLoadingBar)
42 this.notifications = this.notifications.concat(result.data)
43 this.componentPagination.totalItems = result.total
46 err => this.notifier.error(err.message)
51 if (this.infiniteScroll === false) return
53 this.componentPagination.currentPage++
55 if (hasMoreItems(this.componentPagination)) {
56 this.loadMoreNotifications()
60 markAsRead (notification: UserNotification) {
61 this.userNotificationService.markAsRead(notification)
64 notification.read = true
67 err => this.notifier.error(err.message)
72 this.userNotificationService.markAllAsRead()
75 for (const notification of this.notifications) {
76 notification.read = true
80 err => this.notifier.error(err.message)