|
|
|
@ -1,8 +1,9 @@
|
|
|
|
import { Component, ElementRef, EventEmitter, OnInit, Output } from '@angular/core';
|
|
|
|
import { Component, ElementRef, EventEmitter, OnInit, Output } from '@angular/core';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { PostsService } from 'app/posts.services';
|
|
|
|
import { PostsService } from 'app/posts.services';
|
|
|
|
import { Notification } from 'api-types';
|
|
|
|
import { Notification, NotificationType } from 'api-types';
|
|
|
|
import { NotificationAction } from 'api-types/models/NotificationAction';
|
|
|
|
import { NotificationAction } from 'api-types/models/NotificationAction';
|
|
|
|
|
|
|
|
import { MatChipListboxChange } from '@angular/material/chips';
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
selector: 'app-notifications',
|
|
|
|
selector: 'app-notifications',
|
|
|
|
@ -12,9 +13,27 @@ import { NotificationAction } from 'api-types/models/NotificationAction';
|
|
|
|
export class NotificationsComponent implements OnInit {
|
|
|
|
export class NotificationsComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
|
|
notifications: Notification[] = null;
|
|
|
|
notifications: Notification[] = null;
|
|
|
|
|
|
|
|
filtered_notifications: Notification[] = null;
|
|
|
|
|
|
|
|
|
|
|
|
@Output() notificationCount = new EventEmitter<number>();
|
|
|
|
@Output() notificationCount = new EventEmitter<number>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notificationFilters: { [key in NotificationType]: {key: string, label: string} } = {
|
|
|
|
|
|
|
|
download_complete: {
|
|
|
|
|
|
|
|
key: 'download_complete',
|
|
|
|
|
|
|
|
label: $localize`Download completed`
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
download_error: {
|
|
|
|
|
|
|
|
key: 'download_error',
|
|
|
|
|
|
|
|
label: $localize`Download error`
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
task_finished: {
|
|
|
|
|
|
|
|
key: 'task_finished',
|
|
|
|
|
|
|
|
label: $localize`Task`
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectedFilters = [];
|
|
|
|
|
|
|
|
|
|
|
|
constructor(public postsService: PostsService, private router: Router, private elRef: ElementRef) { }
|
|
|
|
constructor(public postsService: PostsService, private router: Router, private elRef: ElementRef) { }
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
ngOnInit(): void {
|
|
|
|
@ -33,7 +52,10 @@ export class NotificationsComponent implements OnInit {
|
|
|
|
getNotifications(): void {
|
|
|
|
getNotifications(): void {
|
|
|
|
this.postsService.getNotifications().subscribe(res => {
|
|
|
|
this.postsService.getNotifications().subscribe(res => {
|
|
|
|
this.notifications = res['notifications'];
|
|
|
|
this.notifications = res['notifications'];
|
|
|
|
|
|
|
|
this.notifications.sort((a, b) => b.timestamp - a.timestamp);
|
|
|
|
this.notificationCount.emit(this.notifications.filter(notification => !notification.read).length);
|
|
|
|
this.notificationCount.emit(this.notifications.filter(notification => !notification.read).length);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.filterNotifications();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -51,6 +73,9 @@ export class NotificationsComponent implements OnInit {
|
|
|
|
this.deleteNotification(action_info['notification']['uid']);
|
|
|
|
this.deleteNotification(action_info['notification']['uid']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NotificationAction.VIEW_TASKS:
|
|
|
|
|
|
|
|
this.router.navigate(['tasks']);
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
console.error(`Notification action ${action_info['action']} does not exist!`);
|
|
|
|
console.error(`Notification action ${action_info['action']} does not exist!`);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@ -60,6 +85,7 @@ export class NotificationsComponent implements OnInit {
|
|
|
|
deleteNotification(uid: string): void {
|
|
|
|
deleteNotification(uid: string): void {
|
|
|
|
this.postsService.deleteNotification(uid).subscribe(res => {
|
|
|
|
this.postsService.deleteNotification(uid).subscribe(res => {
|
|
|
|
this.notifications.filter(notification => notification['uid'] !== uid);
|
|
|
|
this.notifications.filter(notification => notification['uid'] !== uid);
|
|
|
|
|
|
|
|
this.filterNotifications();
|
|
|
|
this.notificationCount.emit(this.notifications.length);
|
|
|
|
this.notificationCount.emit(this.notifications.length);
|
|
|
|
this.getNotifications();
|
|
|
|
this.getNotifications();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -68,6 +94,7 @@ export class NotificationsComponent implements OnInit {
|
|
|
|
deleteAllNotifications(): void {
|
|
|
|
deleteAllNotifications(): void {
|
|
|
|
this.postsService.deleteAllNotifications().subscribe(res => {
|
|
|
|
this.postsService.deleteAllNotifications().subscribe(res => {
|
|
|
|
this.notifications = [];
|
|
|
|
this.notifications = [];
|
|
|
|
|
|
|
|
this.filtered_notifications = [];
|
|
|
|
this.getNotifications();
|
|
|
|
this.getNotifications();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.notificationCount.emit(0);
|
|
|
|
this.notificationCount.emit(0);
|
|
|
|
@ -81,4 +108,17 @@ export class NotificationsComponent implements OnInit {
|
|
|
|
this.notificationCount.emit(0);
|
|
|
|
this.notificationCount.emit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filterNotifications(): void {
|
|
|
|
|
|
|
|
this.filtered_notifications = this.notifications.filter(notification => this.selectedFilters.length === 0 || this.selectedFilters.includes(notification.type));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectedFiltersChanged(event: MatChipListboxChange): void {
|
|
|
|
|
|
|
|
this.selectedFilters = event.value;
|
|
|
|
|
|
|
|
this.filterNotifications();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
originalOrder = (): number => {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|