@Output() notificationsLoaded = new EventEmitter()
notifications: UserNotification[] = []
+ sortField = 'createdAt'
// So we can access it in the template
UserNotificationType = UserNotificationType
totalItems: null
}
- this.loadMoreNotifications()
+ this.loadNotifications()
if (this.markAllAsReadSubject) {
this.markAllAsReadSubject.subscribe(() => this.markAllAsRead())
}
}
- loadMoreNotifications () {
- this.userNotificationService.listMyNotifications(this.componentPagination, undefined, this.ignoreLoadingBar)
+ loadNotifications (reset?: boolean) {
+ this.userNotificationService.listMyNotifications({
+ pagination: this.componentPagination,
+ ignoreLoadingBar: this.ignoreLoadingBar,
+ sort: {
+ field: this.sortField,
+ order: this.sortField === 'createdAt' ? -1 : 1
+ }
+ })
.subscribe(
result => {
- this.notifications = this.notifications.concat(result.data)
+ this.notifications = reset ? result.data : this.notifications.concat(result.data)
this.componentPagination.totalItems = result.total
this.notificationsLoaded.emit()
this.componentPagination.currentPage++
if (hasMoreItems(this.componentPagination)) {
- this.loadMoreNotifications()
+ this.loadNotifications()
}
}
err => this.notifier.error(err.message)
)
}
+
+ changeSortColumn (column: string) {
+ this.componentPagination = {
+ currentPage: 1,
+ itemsPerPage: this.itemsPerPage,
+ totalItems: null
+ }
+ this.sortField = column
+ this.loadNotifications(true)
+ }
}