2024-01-08 17:32:07 +01:00
|
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
|
|
|
import { HttpError, HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
|
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { NotificationInAppTracking } from '@app/core/common/enum/notification-inapp-tracking.enum';
|
|
|
|
import { InAppNotification } from '@app/core/model/inapp-notification/inapp-notification.model';
|
|
|
|
import { InAppNotificationLookup } from '@app/core/query/inapp-notification.lookup';
|
|
|
|
import { InAppNotificationService } from '@app/core/services/inapp-notification/inapp-notification.service';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { nameof } from 'ts-simple-nameof';
|
2024-01-12 14:57:38 +01:00
|
|
|
import { IsActive } from '@app/core/common/enum/is-active.enum';
|
2024-01-08 17:32:07 +01:00
|
|
|
|
|
|
|
@Component({
|
2024-01-10 13:24:32 +01:00
|
|
|
selector: 'app-mine-inapp-notification-listing-dialog',
|
|
|
|
templateUrl: './mine-inapp-notification-listing-dialog.component.html',
|
|
|
|
styleUrls: ['./mine-inapp-notification-listing-dialog.component.scss']
|
2024-01-08 17:32:07 +01:00
|
|
|
})
|
2024-01-10 13:24:32 +01:00
|
|
|
export class MineInAppNotificationListingDialogComponent extends BaseComponent implements OnInit {
|
2024-01-08 17:32:07 +01:00
|
|
|
public inappNotifications = new Array<InAppNotification>();
|
|
|
|
public notificationInAppTrackingEnum = NotificationInAppTracking;
|
|
|
|
|
|
|
|
constructor(
|
2024-01-10 13:24:32 +01:00
|
|
|
public dialogRef: MatDialogRef<MineInAppNotificationListingDialogComponent>,
|
2024-01-08 17:32:07 +01:00
|
|
|
@Inject(MAT_DIALOG_DATA) public dialogData: any,
|
|
|
|
private inappNotificationService: InAppNotificationService,
|
|
|
|
private router: Router,
|
|
|
|
private uiNotificationService: UiNotificationService,
|
|
|
|
private httpErrorHandlingService: HttpErrorHandlingService,
|
|
|
|
public authService: AuthService,
|
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
const lookup = new InAppNotificationLookup();
|
|
|
|
lookup.project = {
|
|
|
|
fields: [
|
|
|
|
nameof<InAppNotification>(x => x.id),
|
|
|
|
nameof<InAppNotification>(x => x.subject),
|
|
|
|
nameof<InAppNotification>(x => x.createdAt),
|
|
|
|
nameof<InAppNotification>(x => x.trackingState),
|
|
|
|
]
|
|
|
|
};
|
2024-01-12 14:57:38 +01:00
|
|
|
lookup.page = { offset: 0, size: 10 };
|
2024-01-08 17:32:07 +01:00
|
|
|
lookup.order = { items: ['-' + nameof<InAppNotification>(x => x.createdAt)] };
|
2024-01-12 14:57:38 +01:00
|
|
|
lookup.isActive = [IsActive.Active];
|
2024-01-08 17:32:07 +01:00
|
|
|
this.inappNotificationService.query(lookup)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
data => {
|
|
|
|
this.inappNotifications = data.items;
|
|
|
|
},
|
|
|
|
error => this.onCallbackError(error),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private onCallbackError(errorResponse: HttpErrorResponse) {
|
|
|
|
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
|
|
|
|
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
|
|
|
|
}
|
|
|
|
|
|
|
|
goToNotification(item: InAppNotification) {
|
|
|
|
if (item.trackingState === NotificationInAppTracking.Stored) {
|
|
|
|
this.inappNotificationService.read(item.id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
data => {
|
|
|
|
this.dialogRef.close();
|
2024-01-10 13:24:32 +01:00
|
|
|
this.router.navigate(['/mine-notifications/dialog/' + item.id]);
|
2024-01-08 17:32:07 +01:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.dialogRef.close();
|
2024-01-10 13:24:32 +01:00
|
|
|
this.router.navigate(['/mine-notifications/dialog/' + item.id]);
|
2024-01-08 17:32:07 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.dialogRef.close();
|
2024-01-10 13:24:32 +01:00
|
|
|
this.router.navigate(['/mine-notifications/dialog/' + item.id]);
|
2024-01-08 17:32:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
goToNotifications() {
|
2024-01-10 13:24:32 +01:00
|
|
|
this.router.navigate(['/mine-notifications']);
|
2024-01-08 17:32:07 +01:00
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
2024-01-09 14:52:07 +01:00
|
|
|
|
|
|
|
readAllNotifications() {
|
|
|
|
this.inappNotificationService.readAll()
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
data => {},
|
|
|
|
);
|
|
|
|
}
|
2024-01-08 17:32:07 +01:00
|
|
|
}
|