From d7ed6fa1bce904c38e9d48f556e7c896a1dd2e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 18 Nov 2021 21:16:19 +0200 Subject: [PATCH] Refresh files with check for changes --- .../dictionary-listing-screen.component.ts | 2 +- .../dictionary-overview-screen.component.ts | 2 +- .../edit-dossier-deleted-documents.component.ts | 2 +- .../dictionary/edit-dossier-dictionary.component.ts | 2 +- .../screen/dossier-overview-screen.component.ts | 13 ++++++++++--- .../file-preview-screen.component.ts | 4 ++-- .../file-actions/file-actions.component.ts | 2 +- .../dictionary-manager.component.ts | 4 ++-- .../modules/shared/services/dictionary.service.ts | 2 +- .../services/entity-services/dossiers.service.ts | 2 +- .../app/services/entity-services/files.service.ts | 10 ---------- .../src/app/services/notifications.service.ts | 2 +- apps/red-ui/src/app/state/app-state.service.ts | 2 +- libs/common-ui | 2 +- 14 files changed, 24 insertions(+), 27 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts index 8b776254d..07c195482 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts @@ -115,7 +115,7 @@ export class DictionaryListingScreenComponent extends ListingComponent - this._dictionaryService.getFor(this._dossierTemplatesService.activeDossierTemplateId, dict.type).pipe( + this._dictionaryService.getForType(this._dossierTemplatesService.activeDossierTemplateId, dict.type).pipe( tap(values => (dict.entries = [...values.entries] ?? [])), catchError(() => { dict.entries = []; diff --git a/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.ts index 196dcdb50..6f32d193a 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.ts @@ -150,7 +150,7 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges imple private async _loadEntries() { this._loadingService.start(); await this._dictionaryService - .getFor(this.dictionary.dossierTemplateId, this.dictionary.type) + .getForType(this.dictionary.dossierTemplateId, this.dictionary.type) .toPromise() .then( data => { diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/deleted-documents/edit-dossier-deleted-documents.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/deleted-documents/edit-dossier-deleted-documents.component.ts index acba817b3..1ef89bd72 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/deleted-documents/edit-dossier-deleted-documents.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/deleted-documents/edit-dossier-deleted-documents.component.ts @@ -115,7 +115,7 @@ export class EditDossierDeletedDocumentsComponent extends ListingComponent f.fileId); await this._fileManagementService.restore(fileIds, this.dossier.id).toPromise(); this._removeFromList(fileIds); - await this._appStateService.reloadDossierFiles(); + await this._appStateService.reloadDossierFiles(files[0].dossierId); this.updateDossier.emit(); } diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.ts index 6e5af5471..e59bca316 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.ts @@ -75,6 +75,6 @@ export class EditDossierDictionaryComponent implements EditDossierSectionInterfa private async _updateDossierDictionary() { const { dossierId, dossierTemplateId } = this.dossier; - this.dossierDictionary = await this._dictionaryService.getFor(dossierTemplateId, 'dossier_redaction', dossierId).toPromise(); + this.dossierDictionary = await this._dictionaryService.getForType(dossierTemplateId, 'dossier_redaction', dossierId).toPromise(); } } 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 d02b6f91e..f1e25c1ff 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 @@ -18,9 +18,10 @@ 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 { switchMap, tap } from 'rxjs/operators'; +import { filter, switchMap, tap } from 'rxjs/operators'; import { convertFiles, Files, handleFileDrop } from '@utils/index'; import { + CHANGED_CHECK_INTERVAL, CircleButtonTypes, DefaultListingServices, ListingComponent, @@ -46,6 +47,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 { DossierStatsService } from '@services/entity-services/dossier-stats.service'; +import { FilesService } from '@services/entity-services/files.service'; @Component({ templateUrl: './dossier-overview-screen.component.html', @@ -84,6 +86,7 @@ export class DossierOverviewScreenComponent extends ListingComponent imple private readonly _dossierTemplatesService: DossierTemplatesService, private readonly _appConfigService: AppConfigService, private readonly _fileUploadService: FileUploadService, + private readonly _filesService: FilesService, private readonly _statusOverlayService: StatusOverlayService, private readonly _fileDropOverlayService: FileDropOverlayService, private readonly _dossierAttributesService: DossierAttributesService, @@ -158,8 +161,12 @@ export class DossierOverviewScreenComponent extends ListingComponent imple await this.calculateData(); - this.addSubscription = timer(0, 20 * 1000) - .pipe(switchMap(() => this.reloadFiles())) + this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL) + .pipe( + switchMap(() => this._filesService.hasChanges$(this.dossierId)), + filter(changed => changed), + switchMap(() => this.reloadFiles()), + ) .subscribe(); this.addSubscription = this.configService.listingMode$.subscribe(() => { diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index 353dd2552..115f5bd13 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -477,11 +477,11 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni case 'reanalyse': await this._loadFileData(true); this._updateCanPerformActions(); - await this.appStateService.reloadDossierFiles(); + await this.appStateService.reloadDossierFiles(this.dossierId); return; case 'exclude-pages': - await this.appStateService.reloadDossierFiles(); + await this.appStateService.reloadDossierFiles(this.dossierId); await this._loadFileData(true); this._cleanupAndRedrawManualAnnotations$(); await this._stampPDF(); 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 5f14565ed..17e7bf8ac 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 @@ -117,7 +117,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, .catch(error => { this._toaster.error(_('error.http.generic'), { params: error }); }); - await this.appStateService.reloadDossierFiles(); + await this.appStateService.reloadDossierFiles(this.file.dossierId); this.actionPerformed.emit('delete'); this._loadingService.stop(); }, diff --git a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.ts b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.ts index 9daa1733e..43a61d1f5 100644 --- a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.ts @@ -111,7 +111,7 @@ export class DictionaryManagerComponent implements OnChanges { } this._dictionaryService - .getFor(this._dictionary.dossierTemplateId, this._dictionary.type) + .getForType(this._dictionary.dossierTemplateId, this._dictionary.type) .pipe( tap(values => (this._dictionary.entries = [...values.entries] ?? [])), catchError(() => { @@ -206,7 +206,7 @@ export class DictionaryManagerComponent implements OnChanges { } private _onDossierChanged(dossierTemplateId: string, dossierId?: string, type = 'dossier_redaction'): Observable { - const dictionary$ = this._dictionaryService.getFor(dossierTemplateId, type, dossierId); + const dictionary$ = this._dictionaryService.getForType(dossierTemplateId, type, dossierId); return dictionary$.pipe(map(data => this._toString([...data.entries]))); } diff --git a/apps/red-ui/src/app/modules/shared/services/dictionary.service.ts b/apps/red-ui/src/app/modules/shared/services/dictionary.service.ts index 3e6aad186..5f953475a 100644 --- a/apps/red-ui/src/app/modules/shared/services/dictionary.service.ts +++ b/apps/red-ui/src/app/modules/shared/services/dictionary.service.ts @@ -19,7 +19,7 @@ export class DictionaryService extends EntitiesService * Retrieves all dictionary entries of an entry type */ @Validate() - getFor(@RequiredParam() dossierTemplateId: string, @RequiredParam() type: string, dossierId?: string) { + getForType(@RequiredParam() dossierTemplateId: string, @RequiredParam() type: string, dossierId?: string) { const queryParams = dossierId ? [{ key: 'dossierId', value: dossierId }] : undefined; return this._getOne([type, dossierTemplateId], this._defaultModelPath, queryParams); } 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 3da2b813e..9c7c10672 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 @@ -40,7 +40,7 @@ export class DossiersService extends EntitiesService { } loadAllIfChanged(): Observable { - return this._hasChanges$.pipe(switchMap(changed => iif(() => changed, this.loadAll()).pipe(mapTo(changed)))); + return this.hasChanges$().pipe(switchMap(changed => iif(() => changed, this.loadAll()).pipe(mapTo(changed)))); } @Validate() diff --git a/apps/red-ui/src/app/services/entity-services/files.service.ts b/apps/red-ui/src/app/services/entity-services/files.service.ts index 2f7cf3dda..ba8a1db0d 100644 --- a/apps/red-ui/src/app/services/entity-services/files.service.ts +++ b/apps/red-ui/src/app/services/entity-services/files.service.ts @@ -21,16 +21,6 @@ export class FilesService extends EntitiesService { return super._getOne([dossierId, fileId]); } - getFor(dossierId: string): Observable; - getFor(dossierIds: List): Observable>; - getFor(args: string | List) { - if (typeof args === 'string') { - return super.getAll(`${this._defaultModelPath}/${args}`); - } - - return this._post>(args); - } - @Validate() setUnderApprovalFor(@RequiredParam() body: List, @RequiredParam() dossierId: string, approverId: string) { const url = `${this._defaultModelPath}/under-approval/${dossierId}/bulk`; diff --git a/apps/red-ui/src/app/services/notifications.service.ts b/apps/red-ui/src/app/services/notifications.service.ts index dd7410f19..3425ca5c8 100644 --- a/apps/red-ui/src/app/services/notifications.service.ts +++ b/apps/red-ui/src/app/services/notifications.service.ts @@ -40,7 +40,7 @@ export class NotificationsService extends GenericService { @Validate() getNotificationsIfChanged(@RequiredParam() includeSeen: boolean): Observable { - return this._hasChanges$.pipe(switchMap(changed => iif(() => changed, this.getNotifications(includeSeen)))); + return this.hasChanges$().pipe(switchMap(changed => iif(() => changed, this.getNotifications(includeSeen)))); } @Validate() diff --git a/apps/red-ui/src/app/state/app-state.service.ts b/apps/red-ui/src/app/state/app-state.service.ts index 5e8bc6c10..fd157f62c 100644 --- a/apps/red-ui/src/app/state/app-state.service.ts +++ b/apps/red-ui/src/app/state/app-state.service.ts @@ -142,7 +142,7 @@ export class AppStateService { this._appState.activeDictionaryType = null; } - async reloadDossierFiles(dossierId = this._activeDossierId) { + async reloadDossierFiles(dossierId: string) { if (dossierId) { return this.getFiles(this._dossiersService.find(dossierId)); } diff --git a/libs/common-ui b/libs/common-ui index b338dd9ba..cdd20751d 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit b338dd9baa8fd67a83d2f8c5710f8b56b0e360cd +Subproject commit cdd20751dc8845f45258a033214a6fdf52b1a760