Refresh dossiers & notifications with check for changes

This commit is contained in:
Adina Țeudan 2021-11-18 17:49:20 +02:00
parent a9acd3daba
commit 4b7cfadfa6
4 changed files with 29 additions and 17 deletions

View File

@ -6,11 +6,10 @@ import { UserService } from '@services/user.service';
import { DossiersService } from '@services/entity-services/dossiers.service';
import { NotificationsService } from '@services/notifications.service';
import { Notification } from '@red/domain';
import { distinctUntilChanged, map } from 'rxjs/operators';
import { BehaviorSubject, Observable } from 'rxjs';
import { AutoUnsubscribe, List, shareLast } from '@iqser/common-ui';
import { distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators';
import { BehaviorSubject, Observable, timer } from 'rxjs';
import { AutoUnsubscribe, CHANGED_CHECK_INTERVAL, List, shareLast } from '@iqser/common-ui';
const REFRESH_INTERVAL = 3000;
const INCLUDE_SEEN = false;
interface NotificationsGroup {
@ -51,12 +50,12 @@ export class NotificationsComponent extends AutoUnsubscribe 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();
this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_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> {

View File

@ -7,7 +7,15 @@ import { TranslateChartService } from '@services/translate-chart.service';
import { timer } from 'rxjs';
import { Router } from '@angular/router';
import { DossiersDialogService } from '../../../services/dossiers-dialog.service';
import { DefaultListingServicesTmp, EntitiesService, ListingComponent, OnAttach, OnDetach, TableComponent } from '@iqser/common-ui';
import {
CHANGED_CHECK_INTERVAL,
DefaultListingServicesTmp,
EntitiesService,
ListingComponent,
OnAttach,
OnDetach,
TableComponent,
} from '@iqser/common-ui';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { ConfigService } from '../config.service';
import { DossiersService } from '@services/entity-services/dossiers.service';
@ -60,9 +68,9 @@ export class DossiersListingScreenComponent extends ListingComponent<Dossier> im
ngOnInit(): void {
this.computeAllFilters();
this.addSubscription = timer(20000, 20000)
this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL)
.pipe(
switchMap(() => this._dossiersService.loadAll()),
switchMap(() => this._dossiersService.loadAllIfChanged()),
tap(() => this.computeAllFilters()),
)
.subscribe();
@ -79,7 +87,7 @@ export class DossiersListingScreenComponent extends ListingComponent<Dossier> im
openAddDossierDialog(): void {
this._dialogService.openDialog('addDossier', null, null, async (addResponse: { dossier: Dossier; addMembers: boolean }) => {
await this._router.navigate([`/main/dossiers/${addResponse.dossier.id}`]);
await this._router.navigate([addResponse.dossier.routerLink]);
if (addResponse.addMembers) {
this._dialogService.openDialog('editDossier', null, {
dossierId: addResponse.dossier.dossierId,

View File

@ -1,5 +1,5 @@
import { Injectable, Injector } from '@angular/core';
import { EntitiesService, List, QueryParam, RequiredParam, shareLast, Toaster, Validate } from '@iqser/common-ui';
import { EntitiesService, List, mapEach, QueryParam, RequiredParam, shareLast, Toaster, Validate } from '@iqser/common-ui';
import { Dossier, IDossier, IDossierRequest } from '@red/domain';
import { catchError, filter, map, mapTo, switchMap, tap } from 'rxjs/operators';
import { combineLatest, iif, Observable, of, throwError } from 'rxjs';
@ -31,7 +31,12 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
loadAll(): Observable<Dossier[]> {
const dossierIds = (dossiers: Dossier[]) => dossiers.map(d => d.dossierId);
return super.loadAll().pipe(switchMap(dossiers => this._dossierStatsService.getFor(dossierIds(dossiers)).pipe(mapTo(dossiers))));
return this.getAll().pipe(
mapEach(entity => new Dossier(entity)),
/* Load stats before updating entities */
switchMap(dossiers => this._dossierStatsService.getFor(dossierIds(dossiers)).pipe(mapTo(dossiers))),
tap(dossiers => this.replace(dossiers)),
);
}
loadAllIfChanged(): Observable<boolean> {

@ -1 +1 @@
Subproject commit 1408f81f2b230d0338aa856531a705bf8cc5014c
Subproject commit 5b26f76f0e48f4ead6d6f5dfe9a3d76e4a429bfc