-import { Component, Input, OnInit } from '@angular/core'
+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
import { UserNotificationService } from '@app/shared/users/user-notification.service'
import { UserNotificationType } from '../../../../../shared'
import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pagination.model'
@Input() infiniteScroll = true
@Input() itemsPerPage = 20
+ @Output() notificationsLoaded = new EventEmitter()
+
notifications: UserNotification[] = []
// So we can access it in the template
UserNotificationType = UserNotificationType
- componentPagination: ComponentPagination = {
- currentPage: 1,
- itemsPerPage: this.itemsPerPage,
- totalItems: null
- }
+ componentPagination: ComponentPagination
constructor (
private userNotificationService: UserNotificationService,
) { }
ngOnInit () {
+ this.componentPagination = {
+ currentPage: 1,
+ itemsPerPage: this.itemsPerPage, // Reset items per page, because of the @Input() variable
+ totalItems: null
+ }
+
this.loadMoreNotifications()
}
result => {
this.notifications = this.notifications.concat(result.data)
this.componentPagination.totalItems = result.total
+
+ this.notificationsLoaded.emit()
},
err => this.notifier.error(err.message)
}
markAsRead (notification: UserNotification) {
+ if (notification.read) return
+
this.userNotificationService.markAsRead(notification)
.subscribe(
() => {