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 8912203dc..d2ea83336 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 @@ -139,9 +139,9 @@ export class DossierOverviewScreenComponent extends ListingComponent imple } } - disabledFn = (fileStatus: File) => fileStatus.excluded; + disabledFn = (file: File) => file.excluded; - lastOpenedFn = (fileStatus: File) => fileStatus.lastOpened; + lastOpenedFn = (file: File) => this._userPreferenceService.getLastOpenedFileForDossier(file.dossierId) === file.id; async ngOnInit(): Promise { await this._loadEntitiesFromState(); 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 ab39b0e99..0f96dec24 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 @@ -119,6 +119,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni private readonly _translateService: TranslateService, private readonly _filesMapService: FilesMapService, private readonly _dossiersService: DossiersService, + private readonly _userPreferenceService: UserPreferenceService, ) { super(); this._loadingService.start(); @@ -258,6 +259,8 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni } async ngOnInit(): Promise { + await this._userPreferenceService.saveLastOpenedFileForDossier(this.dossierId, this.fileId); + await this._loadFileData(); this.displayPDFViewer = true; this._updateCanPerformActions(); 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 6476ab145..233781ad1 100644 --- a/apps/red-ui/src/app/state/app-state.service.ts +++ b/apps/red-ui/src/app/state/app-state.service.ts @@ -6,7 +6,6 @@ import { forkJoin, Observable, of } from 'rxjs'; import { catchError, first, map, tap } from 'rxjs/operators'; import { currentComponentRoute, FALLBACK_COLOR, hexToRgb } from '@utils/functions'; import { DossiersService } from '@services/entity-services/dossiers.service'; -import { UserPreferenceService } from '@services/user-preference.service'; import { FilesService } from '@services/entity-services/files.service'; import { DictionaryService } from '@shared/services/dictionary.service'; import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service'; @@ -35,7 +34,6 @@ export class AppStateService { private readonly _dossierStatsService: DossierStatsService, private readonly _fileAttributesService: FileAttributesService, private readonly _filesMapService: FilesMapService, - private readonly _userPreferenceService: UserPreferenceService, ) { _router.events.pipe(currentComponentRoute).subscribe(async (event: ActivationEnd) => { const fileId = event.snapshot.paramMap.get('fileId'); @@ -50,7 +48,7 @@ export class AppStateService { } const dossierId = event.snapshot.paramMap.get('dossierId'); - return this.activateFile(dossierId, fileId); + return this._activateFile(dossierId, fileId); }); } @@ -154,26 +152,11 @@ export class AppStateService { const fileAttributes = this._fileAttributesService.getFileAttributeConfig(dossier.dossierTemplateId); const newFiles = files.map(iFile => new File(iFile, this._userService.getNameForId(iFile.currentReviewer), fileAttributes)); - - const lastOpenedFileId = this._userPreferenceService.getLastOpenedFileForDossier(dossier.id); - newFiles.forEach(file => (file.lastOpened = file.fileId === lastOpenedFileId)); this._filesMapService.set(dossier.dossierId, newFiles); return newFiles; } - async activateFile(dossierId: string, fileId: string) { - const activeDossierId = await this._dossiersService.activeDossierId$.pipe(first()).toPromise(); - if (activeDossierId === dossierId && this.activeFileId === fileId) { - return; - } - - if (this._dossiersService.activeDossier) { - this._appState.activeFileId = fileId; - } - await this._updateLastActiveFileForDossier(dossierId, fileId); - } - activateDictionary(dictionaryType: string) { if (this._dossierTemplatesService.activeDossierTemplate) { this._appState.activeDictionaryType = dictionaryType; @@ -258,6 +241,17 @@ export class AppStateService { ); } + private async _activateFile(dossierId: string, fileId: string) { + const activeDossierId = await this._dossiersService.activeDossierId$.pipe(first()).toPromise(); + if (activeDossierId === dossierId && this.activeFileId === fileId) { + return; + } + + if (this._dossiersService.activeDossier) { + this._appState.activeFileId = fileId; + } + } + private _getDictionaryDataForDossierTemplate$(dossierTemplateId: string): Observable<{ [key: string]: any }> { const dictionaryData: { [key: string]: any } = {}; @@ -449,12 +443,4 @@ export class AppStateService { return forkJoin([typeObs, colorsObs]).pipe(map(() => dictionaryData)); } - - private async _updateLastActiveFileForDossier(dossierId: string, fileId: string) { - this._filesMapService.get(dossierId).forEach(f => { - f.lastOpened = f.fileId === fileId; - }); - - await this._userPreferenceService.saveLastOpenedFileForDossier(dossierId, fileId); - } } diff --git a/libs/red-domain/src/lib/files/file.model.ts b/libs/red-domain/src/lib/files/file.model.ts index e2b29c1a6..805cc5757 100644 --- a/libs/red-domain/src/lib/files/file.model.ts +++ b/libs/red-domain/src/lib/files/file.model.ts @@ -39,7 +39,6 @@ export class File extends Entity implements IFile { readonly workflowStatus: WorkflowFileStatus; readonly primaryAttribute?: string; - lastOpened = false; readonly statusSort: number; readonly cacheIdentifier?: string; readonly hintsOnly: boolean;