Prepare for notifications changes check
This commit is contained in:
parent
88e0f8aa42
commit
0833f0847b
@ -8,7 +8,10 @@ import { NotificationsService } from '@services/notifications.service';
|
||||
import { Notification } from '@red/domain';
|
||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { List, shareLast } from '@iqser/common-ui';
|
||||
import { AutoUnsubscribe, List, shareLast } from '@iqser/common-ui';
|
||||
|
||||
const REFRESH_INTERVAL = 3000;
|
||||
const INCLUDE_SEEN = false;
|
||||
|
||||
interface NotificationsGroup {
|
||||
date: string;
|
||||
@ -21,7 +24,7 @@ interface NotificationsGroup {
|
||||
styleUrls: ['./notifications.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class NotificationsComponent implements OnInit {
|
||||
export class NotificationsComponent extends AutoUnsubscribe implements OnInit {
|
||||
notifications$: Observable<Notification[]>;
|
||||
hasUnreadNotifications$: Observable<boolean>;
|
||||
groupedNotifications$: Observable<NotificationsGroup[]>;
|
||||
@ -35,6 +38,7 @@ export class NotificationsComponent implements OnInit {
|
||||
private readonly _dossiersService: DossiersService,
|
||||
private readonly _datePipe: DatePipe,
|
||||
) {
|
||||
super();
|
||||
this.notifications$ = this._notifications$.asObservable().pipe(shareLast());
|
||||
this.groupedNotifications$ = this.notifications$.pipe(map(notifications => this._groupNotifications(notifications)));
|
||||
this.hasUnreadNotifications$ = this.notifications$.pipe(
|
||||
@ -46,6 +50,13 @@ export class NotificationsComponent implements OnInit {
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this._loadData();
|
||||
|
||||
// this.addSubscription = timer(REFRESH_INTERVAL, REFRESH_INTERVAL)
|
||||
// .pipe(
|
||||
// switchMap(() => this._notificationsService.getNotificationsIfChanged(INCLUDE_SEEN)),
|
||||
// tap(notifications => this._notifications$.next(notifications)),
|
||||
// )
|
||||
// .subscribe();
|
||||
}
|
||||
|
||||
async markRead($event, notifications: List<string> = this._notifications$.getValue().map(n => n.id), isRead = true): Promise<void> {
|
||||
@ -55,7 +66,7 @@ export class NotificationsComponent implements OnInit {
|
||||
}
|
||||
|
||||
private async _loadData(): Promise<void> {
|
||||
const notifications = await this._notificationsService.getNotifications(false).toPromise();
|
||||
const notifications = await this._notificationsService.getNotifications(INCLUDE_SEEN).toPromise();
|
||||
this._notifications$.next(notifications);
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ const GENERIC_MGS = _('add-dossier-dialog.errors.generic');
|
||||
})
|
||||
export class DossiersService extends EntitiesService<Dossier, IDossier> {
|
||||
readonly generalStats$ = this.all$.pipe(switchMap(entities => this._generalStats$(entities)));
|
||||
private _lastCheckedForChanges = '0';
|
||||
|
||||
constructor(
|
||||
private readonly _toaster: Toaster,
|
||||
@ -30,19 +29,9 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
|
||||
super(_injector, Dossier, 'dossier');
|
||||
}
|
||||
|
||||
private get _hasChanges$(): Observable<boolean> {
|
||||
return this._post<{ value: boolean }>({ since: this._lastCheckedForChanges }, `${this._defaultModelPath}/changes`).pipe(
|
||||
map(res => res.value),
|
||||
tap(() => this._updateLastChanged()),
|
||||
);
|
||||
}
|
||||
|
||||
loadAll(): Observable<Dossier[]> {
|
||||
const dossierIds = (dossiers: Dossier[]) => dossiers.map(d => d.dossierId);
|
||||
return super.loadAll().pipe(
|
||||
tap(() => this._updateLastChanged()),
|
||||
switchMap(dossiers => this._dossierStatsService.getFor(dossierIds(dossiers)).pipe(mapTo(dossiers))),
|
||||
);
|
||||
return super.loadAll().pipe(switchMap(dossiers => this._dossierStatsService.getFor(dossierIds(dossiers)).pipe(mapTo(dossiers))));
|
||||
}
|
||||
|
||||
loadAllIfChanged(): Observable<boolean> {
|
||||
@ -88,10 +77,6 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
|
||||
return super.delete(body, 'deleted-dossiers/hard-delete', body).toPromise();
|
||||
}
|
||||
|
||||
private _updateLastChanged(): void {
|
||||
this._lastCheckedForChanges = new Date().toISOString();
|
||||
}
|
||||
|
||||
private _computeStats(entities: List<Dossier>): IDossiersStats {
|
||||
let totalAnalyzedPages = 0;
|
||||
const totalPeople = new Set<string>();
|
||||
|
||||
@ -17,20 +17,8 @@ export class FilesService extends EntitiesService<File, IFile> {
|
||||
this.get().pipe(map(files => files.map(file => new File(file, this._userService.getNameForId(file.currentReviewer)))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status for all files.
|
||||
*/
|
||||
get(): Observable<IFile[]>;
|
||||
/**
|
||||
* Gets the status for a file from a dossier.
|
||||
*/
|
||||
get(dossierId: string, fileId: string): Observable<IFile>;
|
||||
get(dossierId?: string, fileId?: string): Observable<IFile | IFile[]> {
|
||||
if (dossierId && fileId) {
|
||||
return super._getOne([dossierId, fileId]);
|
||||
}
|
||||
|
||||
return super.getAll();
|
||||
getOne(dossierId: string, fileId: string): Observable<IFile> {
|
||||
return super._getOne([dossierId, fileId]);
|
||||
}
|
||||
|
||||
getFor(dossierId: string): Observable<IFile[]>;
|
||||
|
||||
@ -2,9 +2,9 @@ import { Injectable, Injector } from '@angular/core';
|
||||
import { GenericService, List, mapEach, QueryParam, RequiredParam, Validate } from '@iqser/common-ui';
|
||||
import * as moment from 'moment';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { iif, Observable } from 'rxjs';
|
||||
import { INotification, Notification, NotificationTypes } from '@red/domain';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { notificationsTranslations } from '../translations/notifications-translations';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { DossiersService } from '@services/entity-services/dossiers.service';
|
||||
@ -14,7 +14,7 @@ import { FilesMapService } from '@services/entity-services/files-map.service';
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class NotificationsService extends GenericService<unknown> {
|
||||
export class NotificationsService extends GenericService<Notification> {
|
||||
constructor(
|
||||
protected readonly _injector: Injector,
|
||||
private readonly _translateService: TranslateService,
|
||||
@ -32,12 +32,17 @@ export class NotificationsService extends GenericService<unknown> {
|
||||
queryParam = { key: 'includeSeen', value: includeSeen };
|
||||
}
|
||||
|
||||
return this._getOne<{ notifications: INotification[] }>([], this._defaultModelPath, [queryParam]).pipe(
|
||||
return this.getAll<{ notifications: Notification[] }>(this._defaultModelPath, [queryParam]).pipe(
|
||||
map(response => response.notifications.filter(n => n.notificationType in NotificationTypes)),
|
||||
mapEach(notification => this._new(notification)),
|
||||
);
|
||||
}
|
||||
|
||||
@Validate()
|
||||
getNotificationsIfChanged(@RequiredParam() includeSeen: boolean): Observable<Notification[]> {
|
||||
return this._hasChanges$.pipe(switchMap(changed => iif(() => changed, this.getNotifications(includeSeen))));
|
||||
}
|
||||
|
||||
@Validate()
|
||||
toggleNotificationRead(@RequiredParam() body: List, @RequiredParam() setRead: boolean) {
|
||||
let queryParam: QueryParam;
|
||||
|
||||
@ -104,7 +104,7 @@ export class AppStateService {
|
||||
return null;
|
||||
}
|
||||
|
||||
const iFile = await this._filesService.get(dossierId, fileId).toPromise();
|
||||
const iFile = await this._filesService.getOne(dossierId, fileId).toPromise();
|
||||
|
||||
const newFile = new File(
|
||||
iFile,
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 4242cd442b4ada713c9d44788d6d4a66fd06ced3
|
||||
Subproject commit 1408f81f2b230d0338aa856531a705bf8cc5014c
|
||||
Loading…
x
Reference in New Issue
Block a user