From 4b7cfadfa64935e2288b620d681594ee51c26fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 18 Nov 2021 17:49:20 +0200 Subject: [PATCH] Refresh dossiers & notifications with check for changes --- .../notifications/notifications.component.ts | 19 +++++++++---------- .../dossiers-listing-screen.component.ts | 16 ++++++++++++---- .../entity-services/dossiers.service.ts | 9 +++++++-- libs/common-ui | 2 +- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/apps/red-ui/src/app/components/notifications/notifications.component.ts b/apps/red-ui/src/app/components/notifications/notifications.component.ts index 06d939c39..1e4d7fbd1 100644 --- a/apps/red-ui/src/app/components/notifications/notifications.component.ts +++ b/apps/red-ui/src/app/components/notifications/notifications.component.ts @@ -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 { 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 = this._notifications$.getValue().map(n => n.id), isRead = true): Promise { diff --git a/apps/red-ui/src/app/modules/dossier/screens/dossiers-listing/screen/dossiers-listing-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/dossiers-listing/screen/dossiers-listing-screen.component.ts index 70634dfc4..343b79224 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/dossiers-listing/screen/dossiers-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/dossiers-listing/screen/dossiers-listing-screen.component.ts @@ -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 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 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, diff --git a/apps/red-ui/src/app/services/entity-services/dossiers.service.ts b/apps/red-ui/src/app/services/entity-services/dossiers.service.ts index 2bd531b20..0a3e0a9ab 100644 --- a/apps/red-ui/src/app/services/entity-services/dossiers.service.ts +++ b/apps/red-ui/src/app/services/entity-services/dossiers.service.ts @@ -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 { loadAll(): Observable { 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 { diff --git a/libs/common-ui b/libs/common-ui index 1408f81f2..5b26f76f0 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 1408f81f2b230d0338aa856531a705bf8cc5014c +Subproject commit 5b26f76f0e48f4ead6d6f5dfe9a3d76e4a429bfc