mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Notifications caching + DTOs
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { HubConnection, HubConnectionBuilder, HubConnectionState } from '@microsoft/signalr';
|
||||
import { Observable } from 'rxjs';
|
||||
import { shareReplay } from 'rxjs/operators';
|
||||
import { SignalRHubOptions } from './signalr-hub-options';
|
||||
|
||||
export abstract class SignalrHub {
|
||||
@@ -64,6 +65,6 @@ export abstract class SignalrHub {
|
||||
return () => {
|
||||
this._hubConnection.off(methodName, handler);
|
||||
};
|
||||
});
|
||||
}).pipe(shareReplay());
|
||||
}
|
||||
}
|
||||
|
||||
15
apps/hub/notifications/src/lib/defs/envelope.dto.ts
Normal file
15
apps/hub/notifications/src/lib/defs/envelope.dto.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { TargetDTO } from './target.dto';
|
||||
|
||||
export interface EnvelopeDTO<T> {
|
||||
uId?: string;
|
||||
|
||||
timestamp?: string;
|
||||
|
||||
sequence?: number;
|
||||
|
||||
target?: TargetDTO;
|
||||
|
||||
action?: string;
|
||||
|
||||
data?: T;
|
||||
}
|
||||
5
apps/hub/notifications/src/lib/defs/index.ts
Normal file
5
apps/hub/notifications/src/lib/defs/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// start:ng42.barrel
|
||||
export * from './envelope.dto';
|
||||
export * from './message-board-item.dto';
|
||||
export * from './target.dto';
|
||||
// end:ng42.barrel
|
||||
@@ -0,0 +1,19 @@
|
||||
import { QueryTokenDTO } from '@swagger/cat';
|
||||
|
||||
export interface MessageBoardItemDTO {
|
||||
uId?: string;
|
||||
|
||||
type?: string;
|
||||
|
||||
category?: string;
|
||||
|
||||
command?: string;
|
||||
|
||||
headline?: string;
|
||||
|
||||
text?: string;
|
||||
|
||||
queryToken?: QueryTokenDTO;
|
||||
|
||||
expirationDate?: string;
|
||||
}
|
||||
5
apps/hub/notifications/src/lib/defs/target.dto.ts
Normal file
5
apps/hub/notifications/src/lib/defs/target.dto.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export interface TargetDTO {
|
||||
area?: string;
|
||||
branches?: { id: number }[];
|
||||
users?: { id: number }[];
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Inject, Injectable, InjectionToken } from '@angular/core';
|
||||
import { SignalrHub, SignalRHubOptions } from '@core/signalr';
|
||||
import { merge, of } from 'rxjs';
|
||||
import { filter, tap } from 'rxjs/operators';
|
||||
import { EnvelopeDTO, MessageBoardItemDTO } from './defs';
|
||||
|
||||
export const NOTIFICATIONS_HUB_OPTIONS = new InjectionToken<SignalRHubOptions>('hub.notifications.options');
|
||||
|
||||
@@ -9,5 +12,22 @@ export class NotificationsHub extends SignalrHub {
|
||||
super(options);
|
||||
}
|
||||
|
||||
notifications$ = this.listen<{ data: any[] }>('messageBoard');
|
||||
notifications$ = merge(
|
||||
of(this._getNotifications()).pipe(filter((f) => !!f)),
|
||||
this.listen<EnvelopeDTO<MessageBoardItemDTO[]>>('messageBoard')
|
||||
).pipe(tap((data) => this._storeNotifactions(data)));
|
||||
|
||||
private _storeNotifactions(data: EnvelopeDTO<MessageBoardItemDTO[]>) {
|
||||
if (data) {
|
||||
localStorage.setItem('NOTIFICATIONS_BOARD', JSON.stringify(data));
|
||||
}
|
||||
}
|
||||
|
||||
private _getNotifications(): EnvelopeDTO<MessageBoardItemDTO[]> {
|
||||
const stringData = localStorage.getItem('NOTIFICATIONS_BOARD');
|
||||
if (stringData) {
|
||||
return JSON.parse(stringData);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user