load only open dossier's stats

This commit is contained in:
Dan Percic 2022-02-17 13:42:02 +02:00
parent 7c2b78d31f
commit 7b7a4cff81

View File

@ -2,7 +2,7 @@ import { Injectable, Injector } from '@angular/core';
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, firstValueFrom, Observable, of, Subject, throwError, timer } from 'rxjs';
import { combineLatest, firstValueFrom, forkJoin, Observable, of, Subject, throwError, timer } from 'rxjs';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
import { DossierStatsService } from '@services/entity-services/dossier-stats.service';
@ -62,13 +62,16 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
}
loadAllIfChanged(): Observable<ChangesDetails> {
return this.hasChangesDetails$().pipe(switchMap(changes => this.loadAll().pipe(mapTo(changes))));
return this.hasChangesDetails$().pipe(
switchMap(changes => forkJoin(changes.dossierChanges.map(change => this.load(change.dossierId))).pipe(mapTo(changes))),
);
}
hasChangesDetails$(): Observable<ChangesDetails> {
const body = { value: this._lastCheckedForChanges.get('root') ?? '0' };
return this._post<ChangesDetails>(body, `${this._defaultModelPath}/changes/details`).pipe(
filter(changes => changes.dossierChanges.length > 0),
tap(() => this._updateLastChanged()),
);
}
@ -115,6 +118,14 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
return this.all.filter(dossier => dossier.dossierStatusId === dossierStatusId).length;
}
load(id: string, queryParams?: List<QueryParam>): Observable<Dossier> {
return super._getOne([id], this._defaultModelPath, queryParams).pipe(
map(entity => new Dossier(entity)),
switchMap(dossier => this._dossierStatsService.getFor([dossier.dossierId]).pipe(mapTo(dossier))),
tap(dossier => this.replace(dossier)),
);
}
private _emitFileChanges(changes: ChangesDetails): void {
changes.dossierChanges.filter(change => change.fileChanges).forEach(change => this.dossierFileChanges$.next(change.dossierId));
}