From 92af6cdea089262ce7bc56ea93860c8f6f0156cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Tue, 18 Jan 2022 23:20:41 +0200 Subject: [PATCH] Fixed canSwitchToDeltaView --- .../src/app/models/file/file-data.model.ts | 16 ++++++++-------- .../view-switch/view-switch.component.html | 18 +++++++++--------- .../view-switch/view-switch.component.ts | 18 ++++++++++-------- libs/common-ui | 2 +- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/apps/red-ui/src/app/models/file/file-data.model.ts b/apps/red-ui/src/app/models/file/file-data.model.ts index 10ce0ec5c..6e2204c29 100644 --- a/apps/red-ui/src/app/models/file/file-data.model.ts +++ b/apps/red-ui/src/app/models/file/file-data.model.ts @@ -2,12 +2,12 @@ import { Dictionary, File, IRedactionLog, IRedactionLogEntry, IViewedPage, ViewM import { AnnotationWrapper } from './annotation.wrapper'; import { RedactionLogEntryWrapper } from './redaction-log-entry.wrapper'; import * as moment from 'moment'; +import { BehaviorSubject } from 'rxjs'; export class FileDataModel { static readonly DELTA_VIEW_TIME = 10 * 60 * 1000; // 10 minutes; - - hasChangeLog: boolean; allAnnotations: AnnotationWrapper[]; + readonly hasChangeLog$ = new BehaviorSubject(false); constructor( public file: File, @@ -20,15 +20,15 @@ export class FileDataModel { this._buildAllAnnotations(); } + get redactionLog() { + return this._redactionLog; + } + set redactionLog(redactionLog: IRedactionLog) { this._redactionLog = redactionLog; this._buildAllAnnotations(); } - get redactionLog() { - return this._redactionLog; - } - getVisibleAnnotations(viewMode: ViewMode) { return this.allAnnotations.filter(annotation => { if (viewMode === 'STANDARD') { @@ -122,7 +122,7 @@ export class FileDataModel { private _isChangeLogEntry(redactionLogEntry: IRedactionLogEntry, wrapper: RedactionLogEntryWrapper) { if (this.file.numberOfAnalyses > 1) { - var viableChanges = redactionLogEntry.changes.filter(c => c.analysisNumber > 1); + const viableChanges = redactionLogEntry.changes.filter(c => c.analysisNumber > 1); viableChanges.sort((a, b) => moment(a.dateTime).valueOf() - moment(b.dateTime).valueOf()); const lastChange = viableChanges.length >= 1 ? viableChanges[viableChanges.length - 1] : undefined; @@ -141,7 +141,7 @@ export class FileDataModel { wrapper.changeLogType = relevantChanges[relevantChanges.length - 1].type; wrapper.isChangeLogEntry = true; viewedPage.showAsUnseen = moment(viewedPage.viewedTime).valueOf() < moment(lastChange.dateTime).valueOf(); - this.hasChangeLog = true; + this.hasChangeLog$.next(true); } else { // no relevant changes - hide removed anyway wrapper.isChangeLogEntry = false; diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/view-switch/view-switch.component.html b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/view-switch/view-switch.component.html index 4daf4a4ee..c99ce4ba5 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/view-switch/view-switch.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/view-switch/view-switch.component.html @@ -1,5 +1,5 @@ -
{{ 'file-preview.standard' | translate }} -
+ -
{{ 'file-preview.delta' | translate }} -
+ -
{{ 'file-preview.redacted' | translate }} -
+
diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/view-switch/view-switch.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/view-switch/view-switch.component.ts index 5b45956f6..b069922d9 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/view-switch/view-switch.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/view-switch/view-switch.component.ts @@ -1,7 +1,9 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; import { File, ViewMode } from '@red/domain'; import { ViewModeService } from '../../services/view-mode.service'; -import { FileDataModel } from '@models/file/file-data.model'; +import { FilePreviewStateService } from '../../services/file-preview-state.service'; +import { Observable } from 'rxjs'; +import { filter, switchMap } from 'rxjs/operators'; @Component({ selector: 'redaction-view-switch [file]', @@ -13,17 +15,17 @@ export class ViewSwitchComponent implements OnChanges { @Output() readonly switchView = new EventEmitter(); @Input() file: File; - canSwitchToDeltaView = false; + readonly canSwitchToDeltaView$: Observable; canSwitchToRedactedView = false; - constructor(readonly viewModeService: ViewModeService) {} + constructor(readonly viewModeService: ViewModeService, private readonly _stateService: FilePreviewStateService) { + this.canSwitchToDeltaView$ = this._stateService.fileData$.pipe( + filter(fileData => !!fileData), + switchMap(fileData => fileData?.hasChangeLog$), + ); + } ngOnChanges(changes: SimpleChanges) { - if (changes.fileData) { - const fileData = changes.fileData.currentValue as FileDataModel; - this.canSwitchToDeltaView = fileData?.hasChangeLog; - } - if (changes.file) { const file = changes?.file.currentValue as File; this.canSwitchToRedactedView = !file.analysisRequired && !file.excluded; diff --git a/libs/common-ui b/libs/common-ui index d11b54bb1..85ec2446a 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit d11b54bb118e639274c011c41594703c71018292 +Subproject commit 85ec2446a35436786573dfdad8fc5c7bb16d5ac0