From fc05e3bd42e20049a76d5fd763aaed528d6ce0a6 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Sat, 13 Nov 2021 18:56:09 +0200 Subject: [PATCH] add new files map service --- .../dossier-overview-screen.component.ts | 63 ++++++------ .../dossiers-listing-screen.component.ts | 2 + .../file-preview-screen.component.html | 23 ++--- .../file-preview-screen.component.ts | 95 ++++++++++--------- .../services/pdf-viewer-data.service.ts | 28 ++---- .../file-actions/file-actions.component.ts | 84 ++++++++-------- .../shared/services/file-action.service.ts | 13 +-- .../entity-services/dossiers.service.ts | 4 - .../entity-services/files-map.service.ts | 64 +++++++++++++ .../services/entity-services/files.service.ts | 4 - apps/red-ui/src/app/state/app-state.guard.ts | 6 +- .../red-ui/src/app/state/app-state.service.ts | 58 ++++------- 12 files changed, 235 insertions(+), 209 deletions(-) create mode 100644 apps/red-ui/src/app/services/entity-services/files-map.service.ts 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 fcfc506bc..85b26c5a0 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 @@ -51,6 +51,8 @@ import { DossierTemplatesService } from '@services/entity-services/dossier-templ import { LongPressEvent } from '@shared/directives/long-press.directive'; import { UserPreferenceService } from '@services/user-preference.service'; import { saveAsCSV } from '@utils/csv-utils'; +import { FilesService } from '@services/entity-services/files.service'; +import { FilesMapService } from '@services/entity-services/files-map.service'; @Component({ templateUrl: './dossier-overview-screen.component.html', @@ -70,7 +72,7 @@ export class DossierOverviewScreenComponent extends ListingComponent imple analysisForced: boolean; displayedInFileListAttributes: IFileAttributeConfig[] = []; displayedAttributes: IFileAttributeConfig[] = []; - readonly workflowConfig: WorkflowConfig = this._configService.workflowConfig(() => this.reloadDossiers()); + readonly workflowConfig: WorkflowConfig = this._configService.workflowConfig(() => this.reloadFiles()); readonly actionConfigs: readonly ActionConfig[]; readonly dossier$: Observable; readonly dossierId: string; @@ -102,6 +104,8 @@ export class DossierOverviewScreenComponent extends ListingComponent imple private readonly _fileAttributesService: FileAttributesService, private readonly _configService: ConfigService, private readonly _userPreferenceService: UserPreferenceService, + private readonly _filesService: FilesService, + private readonly _fileMapService: FilesMapService, activatedRoute: ActivatedRoute, ) { super(_injector); @@ -109,6 +113,11 @@ export class DossierOverviewScreenComponent extends ListingComponent imple this.actionConfigs = this._configService.actionConfig(this.dossierId); this.dossier$ = this._dossiersService.getEntityChanged$(this.dossierId); this.currentDossier = this._dossiersService.find(this.dossierId); + + this.fileAttributeConfigs = this._fileAttributesService.getFileAttributeConfig( + this.currentDossier.dossierTemplateId, + )?.fileAttributeConfigs; + this.tableColumnConfigs = this._configService.tableConfig(this.displayedAttributes); } private _fileAttributeConfigs: IFileAttributeConfig[]; @@ -129,10 +138,10 @@ export class DossierOverviewScreenComponent extends ListingComponent imple async actionPerformed(action?: string, file?: File) { if (action === 'assign-reviewer') { - return this.reloadDossiers(); + return this.reloadFiles(); } - this.calculateData(); + await this.calculateData(); if (action === 'navigate') { await this._router.navigate([file.routerLink]); @@ -144,30 +153,20 @@ export class DossierOverviewScreenComponent extends ListingComponent imple lastOpenedFn = (fileStatus: File) => fileStatus.lastOpened; async ngOnInit(): Promise { - this._loadingService.start(); - this._loadEntitiesFromState(); - this.fileAttributeConfigs = this._fileAttributesService.getFileAttributeConfig( - this.currentDossier.dossierTemplateId, - )?.fileAttributeConfigs; - this.tableColumnConfigs = this._configService.tableConfig(this.displayedAttributes); + await this._loadEntitiesFromState(); try { this._fileDropOverlayService.initFileDropHandling(); - this.calculateData(); + await this.calculateData(); this.addSubscription = timer(0, 20 * 1000).subscribe(async () => { - await this._appStateService.reloadActiveDossierFiles(); - this.calculateData(); + await this.reloadFiles(); }); this.addSubscription = this.listingMode$.subscribe(() => { this._computeAllFilters(); }); - // this.addSubscription = this._appStateService.fileChanged$.subscribe(() => { - // this.calculateData(); - // }); - this.addSubscription = this._dossierTemplatesService.entityChanged$.subscribe(() => { this.fileAttributeConfigs = this._fileAttributesService.getFileAttributeConfig( this.currentDossier.dossierTemplateId, @@ -192,8 +191,8 @@ export class DossierOverviewScreenComponent extends ListingComponent imple } async ngOnAttach() { - await this._appStateService.reloadActiveDossierFiles(); - this._loadEntitiesFromState(); + // await this._appStateService.reloadActiveDossierFiles(); + // await this._loadEntitiesFromState(); await this.ngOnInit(); this._tableComponent.scrollViewport.scrollToIndex(this._lastScrolledIndex, 'smooth'); } @@ -209,24 +208,25 @@ export class DossierOverviewScreenComponent extends ListingComponent imple async reanalyseDossier() { try { await this._appStateService.reanalyzeDossier(); - await this.reloadDossiers(); + await this.reloadFiles(); this._toaster.success(_('dossier-overview.reanalyse-dossier.success')); } catch (e) { this._toaster.error(_('dossier-overview.reanalyse-dossier.error')); } } - async reloadDossiers() { - await this._appStateService.getFiles(this.currentDossier, false); - this.calculateData(); + async reloadFiles() { + const files = await this._appStateService.getFiles(this.currentDossier); + this.entitiesService.setEntities(files); + await this.calculateData(); } - calculateData(): void { + async calculateData(): Promise { if (!this.dossierId) { return; } - this._loadEntitiesFromState(); + await this._loadEntitiesFromState(); this._computeAllFilters(); this._changeDetectorRef.markForCheck(); @@ -278,18 +278,18 @@ export class DossierOverviewScreenComponent extends ListingComponent imple } async bulkActionPerformed(): Promise { - await this.reloadDossiers(); + await this.reloadFiles(); } openAssignDossierMembersDialog(): void { const data = { dossierId: this.dossierId, section: 'members' }; - this._dialogService.openDialog('editDossier', null, data, async () => this.reloadDossiers()); + this._dialogService.openDialog('editDossier', null, data, async () => this.reloadFiles()); } openDossierDictionaryDialog() { const data = { dossierId: this.dossierId, section: 'dossierDictionary' }; this._dialogService.openDialog('editDossier', null, data, async () => { - await this.reloadDossiers(); + await this.reloadFiles(); }); } @@ -300,11 +300,14 @@ export class DossierOverviewScreenComponent extends ListingComponent imple recentlyModifiedChecker = (file: File) => moment(file.lastUpdated).add(this._appConfigService.values.RECENT_PERIOD_IN_HOURS, 'hours').isAfter(moment()); - private _loadEntitiesFromState() { + private async _loadEntitiesFromState() { this.currentDossier = this._dossiersService.find(this.dossierId); - if (this.currentDossier) { - this.entitiesService.setEntities([...this.currentDossier.files]); + if (!this._fileMapService.has(this.dossierId)) { + this._loadingService.start(); + await this._appStateService.getFiles(this.currentDossier); } + + this.entitiesService.setEntities(this._fileMapService.get(this.dossierId)); } private async _uploadFiles(files: FileUploadModel[]) { 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 e8f138a6a..ab35a2aa2 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 @@ -22,6 +22,7 @@ import { DefaultListingServicesTmp, EntitiesService, ListingComponent, OnAttach, import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { ConfigService } from '../config.service'; import { DossiersService } from '@services/entity-services/dossiers.service'; +import { FilesService } from '@services/entity-services/files.service'; @Component({ templateUrl: './dossiers-listing-screen.component.html', @@ -59,6 +60,7 @@ export class DossiersListingScreenComponent private readonly _dialogService: DossiersDialogService, private readonly _translateChartService: TranslateChartService, private readonly _configService: ConfigService, + private readonly _filesService: FilesService, ) { super(_injector); } diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html index 62229d1a4..f8685dc99 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html @@ -1,4 +1,4 @@ -
+