From 0a8a8afb973eab53b157146212a06ad61b34bc4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Fri, 22 Sep 2023 13:05:11 +0300 Subject: [PATCH] RED-6768: Reload thumbnails when load all annotations enabled --- .../file-preview-screen.component.ts | 145 +++++++++--------- 1 file changed, 76 insertions(+), 69 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index 5230dfddc..3be5dda62 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -50,7 +50,7 @@ import { PreferencesKeys, UserPreferenceService } from '@users/user-preference.s import { saveAs } from 'file-saver'; import JSZip from 'jszip'; import { NGXLogger } from 'ngx-logger'; -import { combineLatest, first, firstValueFrom, of, pairwise } from 'rxjs'; +import { combineLatest, first, firstValueFrom, Observable, of, pairwise } from 'rxjs'; import { catchError, filter, map, startWith, switchMap, tap } from 'rxjs/operators'; import { byId, byPage, download, handleFilterDelta, hasChanges } from '../../utils'; import { AnnotationDrawService } from '../pdf-viewer/services/annotation-draw.service'; @@ -90,13 +90,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements AfterViewInit, OnInit, OnDestroy, OnAttach, OnDetach, ComponentCanDeactivate { - @ViewChild('annotationFilterTemplate', { - read: TemplateRef, - static: false, - }) - private readonly _filterTemplate: TemplateRef; - @ViewChild('actionsWrapper', { static: false }) private readonly _actionsWrapper: ElementRef; - readonly #isDocumine = getConfig().IS_DOCUMINE; readonly circleButtonTypes = CircleButtonTypes; readonly roles = Roles; fullScreen = false; @@ -105,6 +98,42 @@ export class FilePreviewScreenComponent readonly lastAssignee = computed(() => this.getLastAssignee()); width: number; readonly isIqserDevMode = isIqserDevMode(); + @ViewChild('annotationFilterTemplate', { + read: TemplateRef, + static: false, + }) + private readonly _filterTemplate: TemplateRef; + #loadAllAnnotationsEnabled = false; + @ViewChild('actionsWrapper', { static: false }) private readonly _actionsWrapper: ElementRef; + readonly #isDocumine = getConfig().IS_DOCUMINE; + + get changed() { + return this._pageRotationService.hasRotations(); + } + + get #earmarks$() { + const isEarmarksViewMode$ = this._viewModeService.viewMode$.pipe(filter(() => this._viewModeService.isEarmarks())); + + const earmarks$ = isEarmarksViewMode$.pipe( + tap(() => this._loadingService.start()), + switchMap(() => this._fileDataService.loadEarmarks()), + tap(() => this.updateViewMode().then(() => this._loadingService.stop())), + ); + + const currentPageIfEarmarksView$ = combineLatest([this.pdf.currentPage$, this._viewModeService.viewMode$]).pipe( + filter(() => this._viewModeService.isEarmarks()), + map(([page]) => page), + ); + + const currentPageEarmarks$ = combineLatest([currentPageIfEarmarksView$, earmarks$]).pipe( + map(([page, earmarks]) => earmarks.get(page)), + ); + + return currentPageEarmarks$.pipe( + map(earmarks => [earmarks, this._skippedService.hideSkipped(), this.state.dossierTemplateId] as const), + tap(args => this._annotationDrawService.draw(...args)), + ); + } constructor( readonly pdf: PdfViewer, @@ -181,34 +210,6 @@ export class FilePreviewScreenComponent }); } - get changed() { - return this._pageRotationService.hasRotations(); - } - - get #earmarks$() { - const isEarmarksViewMode$ = this._viewModeService.viewMode$.pipe(filter(() => this._viewModeService.isEarmarks())); - - const earmarks$ = isEarmarksViewMode$.pipe( - tap(() => this._loadingService.start()), - switchMap(() => this._fileDataService.loadEarmarks()), - tap(() => this.updateViewMode().then(() => this._loadingService.stop())), - ); - - const currentPageIfEarmarksView$ = combineLatest([this.pdf.currentPage$, this._viewModeService.viewMode$]).pipe( - filter(() => this._viewModeService.isEarmarks()), - map(([page]) => page), - ); - - const currentPageEarmarks$ = combineLatest([currentPageIfEarmarksView$, earmarks$]).pipe( - map(([page, earmarks]) => earmarks.get(page)), - ); - - return currentPageEarmarks$.pipe( - map(earmarks => [earmarks, this._skippedService.hideSkipped(), this.state.dossierTemplateId] as const), - tap(args => this._annotationDrawService.draw(...args)), - ); - } - getLastAssignee() { const { isApproved, lastReviewer, lastApprover } = this.state.file(); const isRss = this._iqserPermissionsService.has(this.roles.getRss); @@ -457,7 +458,7 @@ export class FilePreviewScreenComponent this._dialogService.openDialog('rss', { file: this.state.file() }); } - loadAnnotations() { + loadAnnotations$() { const annotations$ = this._fileDataService.annotations$.pipe( startWith([] as AnnotationWrapper[]), pairwise(), @@ -470,16 +471,17 @@ export class FilePreviewScreenComponent ); const currentPageAnnotations$ = combineLatest([currentPageIfNotHighlightsView$, annotations$]).pipe( - map( - ([page, [oldAnnotations, newAnnotations]]) => - [oldAnnotations.filter(byPage(page)), newAnnotations.filter(byPage(page))] as const, + map(([page, [oldAnnotations, newAnnotations]]) => + this.#loadAllAnnotationsEnabled + ? ([oldAnnotations, newAnnotations] as const) + : ([oldAnnotations.filter(byPage(page)), newAnnotations.filter(byPage(page))] as const), ), ); return combineLatest([currentPageAnnotations$, this._documentViewer.loaded$]).pipe( filter(([, loaded]) => loaded), map(([annotations]) => annotations), - tap(annotations => this.drawChangedAnnotations(...annotations)?.then(() => this.updateViewMode())), + tap(([oldA, newA]) => this.drawChangedAnnotations(oldA, newA)?.then(() => this.updateViewMode())), tap(([, newAnnotations]) => this.#highlightSelectedAnnotations(newAnnotations)), ); } @@ -641,8 +643,38 @@ export class FilePreviewScreenComponent } } + #annotationsExceedingThresholdWarning(annotations: AnnotationWrapper[]): Observable { + const data = { + question: _('load-all-annotations-threshold-exceeded'), + checkboxes: [ + { + label: _('load-all-annotations-threshold-exceeded-checkbox'), + value: false, + }, + ], + checkboxesValidation: false, + translateParams: { + threshold: this.configService.values.ANNOTATIONS_THRESHOLD, + }, + } as IConfirmationDialogData; + + const ref = this._dialogService.openDialog('confirm', data); + return ref.afterClosed().pipe( + switchMap(async (result: ConfirmOption) => { + const doNotShowWarningAgain = result === ConfirmOptions.SECOND_CONFIRM; + if (doNotShowWarningAgain) { + await this.userPreferenceService.save(PreferencesKeys.loadAllAnnotationsWarning, 'true'); + await this.userPreferenceService.reload(); + } + const validOptions: number[] = [ConfirmOptions.CONFIRM, ConfirmOptions.SECOND_CONFIRM]; + const shouldLoad = validOptions.includes(result); + return [shouldLoad, annotations] as const; + }), + ); + } + #subscribeToFileUpdates(): void { - this.addActiveScreenSubscription = this.loadAnnotations().subscribe(); + this.addActiveScreenSubscription = this.loadAnnotations$().subscribe(); this.addActiveScreenSubscription = this._dossiersService .getEntityDeleted$(this.dossierId) @@ -694,39 +726,14 @@ export class FilePreviewScreenComponent const annotationsExceedThreshold = annotations.length >= this.configService.values.ANNOTATIONS_THRESHOLD; if (annotationsExceedThreshold && showWarning) { - const data = { - question: _('load-all-annotations-threshold-exceeded'), - checkboxes: [ - { - label: _('load-all-annotations-threshold-exceeded-checkbox'), - value: false, - }, - ], - checkboxesValidation: false, - translateParams: { - threshold: this.configService.values.ANNOTATIONS_THRESHOLD, - }, - } as IConfirmationDialogData; - - const ref = this._dialogService.openDialog('confirm', data); - return ref.afterClosed().pipe( - switchMap(async (result: ConfirmOption) => { - const doNotShowWarningAgain = result === ConfirmOptions.SECOND_CONFIRM; - if (doNotShowWarningAgain) { - await this.userPreferenceService.save(PreferencesKeys.loadAllAnnotationsWarning, 'true'); - await this.userPreferenceService.reload(); - } - const validOptions: number[] = [ConfirmOptions.CONFIRM, ConfirmOptions.SECOND_CONFIRM]; - const shouldLoad = validOptions.includes(result); - return [shouldLoad, annotations] as const; - }), - ); + return this.#annotationsExceedingThresholdWarning(annotations); } return of([true, annotations] as const); }), filter(([confirmed]) => confirmed), map(([, annotations]) => { + this.#loadAllAnnotationsEnabled = true; this.drawChangedAnnotations([], annotations).then(() => { this._toaster.success(_('load-all-annotations-success')); this._viewerHeaderService.disableLoadAllAnnotations();