From 5d14dfeeb837b1afbca9c842fb3d573f9d45fba4 Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Thu, 5 Nov 2020 13:39:56 +0200 Subject: [PATCH] fixed state corner cases --- .../file-preview-screen.component.ts | 14 +++++++------ .../file/service/file-action.service.ts | 6 ++++-- .../red-ui/src/app/state/app-state.service.ts | 20 +++++++++++++------ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts index d5e6236b6..6c78617f7 100644 --- a/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts @@ -95,10 +95,6 @@ export class FilePreviewScreenComponent implements OnInit { return this.instance?.docViewer?.getCurrentPage(); } - get canPerformAnnotationActions() { - return this.appStateService.canPerformAnnotationActionsOnCurrentFile(); - } - private projectId: string; private _activeViewer: 'ANNOTATED' | 'REDACTED' = 'ANNOTATED'; private instance: WebViewerInstance; @@ -120,9 +116,12 @@ export class FilePreviewScreenComponent implements OnInit { private _activeMenuAnnotation: AnnotationWrapper; loadingMessage: string; + canPerformAnnotationActions: boolean; + public ngOnInit(): void { + this.canPerformAnnotationActions = this.appStateService.canPerformAnnotationActionsOnCurrentFile(); this._loadFileData().subscribe(() => {}); - this.appStateService.fileStatusChanged.subscribe((fileStatus: FileStatusWrapper) => { + this.appStateService.fileReanalysed.subscribe((fileStatus: FileStatusWrapper) => { if (fileStatus.fileId === this.fileId) { this._loadFileData().subscribe(() => { this.viewReady = true; @@ -192,7 +191,10 @@ export class FilePreviewScreenComponent implements OnInit { } public assignReviewer() { - this._fileActionService.assignProjectReviewer(); + this._fileActionService.assignProjectReviewer(null, () => { + console.log(this.appStateService.canPerformAnnotationActionsOnCurrentFile()); + this.canPerformAnnotationActions = this.appStateService.canPerformAnnotationActionsOnCurrentFile(); + }); } public handleAnnotationSelected(annotationId: string) { diff --git a/apps/red-ui/src/app/screens/file/service/file-action.service.ts b/apps/red-ui/src/app/screens/file/service/file-action.service.ts index b4ede01ba..bfb448674 100644 --- a/apps/red-ui/src/app/screens/file/service/file-action.service.ts +++ b/apps/red-ui/src/app/screens/file/service/file-action.service.ts @@ -22,7 +22,8 @@ export class FileActionService { if (this._appStateService.isActiveProjectOwnerAndManager) { this._dialogService.openAssignFileReviewerDialog( file ? file : this._appStateService.activeFile, - () => { + async () => { + await this._appStateService.reloadActiveProjectFiles(); if (callback) { callback(); } @@ -35,7 +36,8 @@ export class FileActionService { file ? file.fileId : this._appStateService.activeFileId, this._userService.userId ) - .subscribe(() => { + .subscribe(async () => { + await this._appStateService.reloadActiveProjectFiles(); if (callback) { callback(); } 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 1f6c59b39..bc4de34c5 100644 --- a/apps/red-ui/src/app/state/app-state.service.ts +++ b/apps/red-ui/src/app/state/app-state.service.ts @@ -72,6 +72,7 @@ export class AppStateService { private _appState: AppState; private _dictionaryData: { [key: string]: TypeValue } = null; public fileStatusChanged = new EventEmitter(); + public fileReanalysed = new EventEmitter(); constructor( private readonly _router: Router, @@ -189,7 +190,7 @@ export class AppStateService { } get activeFileId(): string { - return this._appState.activeFile.fileId; + return this._appState.activeFile?.fileId; } get totalAnalysedPages() { @@ -256,12 +257,15 @@ export class AppStateService { if (oldFile.fileId === file.fileId) { // emit when analysis count changed if (oldFile.lastUpdated !== file.lastUpdated) { - this.fileStatusChanged.emit( - new FileStatusWrapper( - file, - this._userService.getNameForId(file.currentReviewer) - ) + const fileStatusWrapper = new FileStatusWrapper( + file, + this._userService.getNameForId(file.currentReviewer) ); + this.fileStatusChanged.emit(fileStatusWrapper); + + if (oldFile.lastProcessed !== file.lastProcessed) { + this.fileReanalysed.emit(fileStatusWrapper); + } } found = true; break; @@ -395,6 +399,10 @@ export class AppStateService { this._appState.totalPeople = totalPeople.size; this._appState.totalAnalysedPages = totalAnalysedPages; this._appState.totalDocuments = totalDocuments; + + if (this.activeProjectId && this.activeFileId) { + this.activateFile(this.activeProjectId, this.activeFileId); + } } async reloadActiveProjectFiles() {