From a2a96ad2df62f8120295790634689287b3cc6ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Mon, 13 Dec 2021 21:24:16 +0200 Subject: [PATCH] Fixed dossier / files changes --- .../dossier-overview-screen.component.ts | 18 +++++++++--------- .../dossiers-listing-screen.component.ts | 8 +------- .../file-actions/file-actions.component.ts | 9 ++++++++- .../entity-services/dossiers.service.ts | 12 ++++++++++-- libs/common-ui | 2 +- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/screen/dossier-overview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/screen/dossier-overview-screen.component.ts index bf8865bdd..7995c6d03 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/screen/dossier-overview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/screen/dossier-overview-screen.component.ts @@ -16,8 +16,8 @@ import { FileUploadModel } from '@upload-download/model/file-upload.model'; import { FileUploadService } from '@upload-download/services/file-upload.service'; import { StatusOverlayService } from '@upload-download/services/status-overlay.service'; import * as moment from 'moment'; -import { Observable, timer } from 'rxjs'; -import { filter, skip, switchMap, tap } from 'rxjs/operators'; +import { combineLatest, Observable } from 'rxjs'; +import { skip, switchMap, tap } from 'rxjs/operators'; import { convertFiles, Files, handleFileDrop } from '@utils/index'; import { CircleButtonTypes, @@ -45,7 +45,7 @@ import { LongPressEvent } from '@shared/directives/long-press.directive'; import { UserPreferenceService } from '@services/user-preference.service'; import { FilesMapService } from '@services/entity-services/files-map.service'; import { FilesService } from '@services/entity-services/files.service'; -import { CHANGED_CHECK_INTERVAL } from '@utils/constants'; +import { DossierStatsService } from '@services/entity-services/dossier-stats.service'; @Component({ templateUrl: './dossier-overview-screen.component.html', @@ -81,6 +81,7 @@ export class DossierOverviewScreenComponent extends ListingComponent imple readonly permissionsService: PermissionsService, private readonly _loadingService: LoadingService, private readonly _dossiersService: DossiersService, + private readonly _dossierStatsService: DossierStatsService, private readonly _dossierTemplatesService: DossierTemplatesService, private readonly _appConfigService: AppConfigService, private readonly _fileUploadService: FileUploadService, @@ -128,12 +129,11 @@ export class DossierOverviewScreenComponent extends ListingComponent imple this._fileDropOverlayService.initFileDropHandling(this.dossierId); - this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL) - .pipe( - switchMap(() => this._filesService.hasChanges$(this.dossierId)), - filter(changed => changed), - switchMap(() => this._reloadFiles()), - ) + this.addSubscription = combineLatest([ + this._dossiersService.getEntityChanged$(this.dossierId), + this._dossierStatsService.watch$(this.dossierId), + ]) + .pipe(switchMap(() => this._reloadFiles())) .subscribe(); this.addSubscription = this.configService.listingMode$.subscribe(() => { 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 c7ba3f10b..79b8fd977 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 @@ -3,7 +3,6 @@ import { Dossier } from '@red/domain'; import { UserService } from '@services/user.service'; import { PermissionsService } from '@services/permissions.service'; 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'; @@ -12,8 +11,7 @@ import { ConfigService } from '../config.service'; import { DossiersService } from '@services/entity-services/dossiers.service'; import { FilesService } from '@services/entity-services/files.service'; import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service'; -import { switchMap, tap } from 'rxjs/operators'; -import { CHANGED_CHECK_INTERVAL } from '@utils/constants'; +import { tap } from 'rxjs/operators'; @Component({ templateUrl: './dossiers-listing-screen.component.html', @@ -57,10 +55,6 @@ export class DossiersListingScreenComponent extends ListingComponent im } ngOnInit(): void { - this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL) - .pipe(switchMap(() => this._dossiersService.loadAllIfChanged())) - .subscribe(); - this.addSubscription = this._dossiersService.all$.pipe(tap(() => this._computeAllFilters())).subscribe(); } diff --git a/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts b/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts index 150f44c55..95a6427cd 100644 --- a/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts +++ b/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectionStrategy, + ChangeDetectorRef, Component, EventEmitter, HostBinding, @@ -96,6 +97,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, private readonly _userPreferenceService: UserPreferenceService, private readonly _reanalysisService: ReanalysisService, private readonly _router: Router, + private readonly _changeRef: ChangeDetectorRef, ) { super(); } @@ -224,7 +226,10 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, } ngOnInit() { - this._dossiersService.getEntityChanged$(this.file.dossierId).pipe(tap(() => this._setup())); + this.addSubscription = this._dossiersService + .getEntityChanged$(this.file.dossierId) + .pipe(tap(() => this._setup())) + .subscribe(); } ngOnChanges() { @@ -353,6 +358,8 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, this.showReanalyseDossierOverview = this.canReanalyse && this.isDossierOverview && this.analysisForced; this.buttons = this._buttons; + + this._changeRef.markForCheck(); } private async _setFileApproved() { 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 7f4bbdc68..e3543d71b 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,11 +1,12 @@ import { Injectable, Injector } from '@angular/core'; -import { EntitiesService, List, mapEach, QueryParam, RequiredParam, shareLast, Toaster, Validate } from '@iqser/common-ui'; +import { EntitiesService, List, log, 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'; +import { combineLatest, iif, Observable, of, 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'; +import { CHANGED_CHECK_INTERVAL } from '@utils/constants'; export interface IDossiersStats { totalPeople: number; @@ -27,6 +28,13 @@ export class DossiersService extends EntitiesService { private readonly _dossierStatsService: DossierStatsService, ) { super(_injector, Dossier, 'dossier'); + + timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL) + .pipe( + switchMap(() => this.loadAllIfChanged()), + log(), + ) + .subscribe(); } loadAll(): Observable { diff --git a/libs/common-ui b/libs/common-ui index 51f3d7502..a1c1be7ed 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 51f3d7502b5545663afa2fa0a62abc3578f92905 +Subproject commit a1c1be7edc783bdea42b86c0f8b1f74437065b76