From aeaf748c61a40d38e1450ce01b67abd7ecdc5cae Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Sat, 7 Jan 2023 17:24:05 +0200 Subject: [PATCH] RED-5908: viewed pages update --- .../file-workload.component.html | 1 - .../file-workload/file-workload.component.ts | 7 +++---- .../page-indicator.component.html | 2 +- .../page-indicator.component.ts | 21 +++++++------------ .../file-preview-screen.component.ts | 6 ++---- .../services/annotation-processing.service.ts | 8 +++---- .../services/file-data.service.ts | 2 +- .../services/files/viewed-pages.service.ts | 12 +++++++---- libs/common-ui | 2 +- 9 files changed, 28 insertions(+), 33 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html index edf2e4659..e5f5dfaae 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html +++ b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html @@ -94,7 +94,6 @@ [active]="pageNumber === activeViewerPage" [number]="pageNumber" [showDottedIcon]="hasOnlyManualRedactionsAndIsExcluded(pageNumber)" - [viewedPages]="fileDataService.viewedPages" > diff --git a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts index 5888f7f6b..519ef73a9 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts @@ -40,7 +40,6 @@ import { PdfViewer } from '../../../pdf-viewer/services/pdf-viewer.service'; import { REDAnnotationManager } from '../../../pdf-viewer/services/annotation-manager.service'; import { AnnotationsListingService } from '../../services/annotations-listing.service'; import { REDDocumentViewer } from '../../../pdf-viewer/services/document-viewer.service'; -import { UserPreferenceService } from '@users/user-preference.service'; import { SuggestionsService } from '../../services/suggestions.service'; const COMMAND_KEY_ARRAY = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Escape']; @@ -87,11 +86,11 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnDestroy private readonly _changeDetectorRef: ChangeDetectorRef, private readonly _annotationProcessingService: AnnotationProcessingService, private readonly _viewModeService: ViewModeService, - private readonly _userPreferencesService: UserPreferenceService, private readonly _suggestionsService: SuggestionsService, ) { super(); + // TODO: ngOnDetach is not called here, so we need to unsubscribe manually this.addActiveScreenSubscription = this.pdf.currentPage$.subscribe(pageNumber => { this._scrollViews(); this.scrollAnnotationsToPage(pageNumber, 'always'); @@ -111,7 +110,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnDestroy this.displayedAnnotations$ = this._displayedAnnotations$; this.multiSelectInactive$ = this._multiSelectInactive$; this.showExcludedPages$ = this._showExcludedPages$; - this.isEarmarks$ = this._isHighlights$; + this.isEarmarks$ = this._isEarmarks$; this.title$ = this._title$; } @@ -140,7 +139,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnDestroy ); } - private get _isHighlights$(): Observable { + private get _isEarmarks$(): Observable { return this.viewModeService.viewMode$.pipe( tap(() => this._scrollViews()), map(() => this.viewModeService.isEarmarks), diff --git a/apps/red-ui/src/app/modules/file-preview/components/page-indicator/page-indicator.component.html b/apps/red-ui/src/app/modules/file-preview/components/page-indicator/page-indicator.component.html index 331337b1d..b1ad66c77 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/page-indicator/page-indicator.component.html +++ b/apps/red-ui/src/app/modules/file-preview/components/page-indicator/page-indicator.component.html @@ -1,7 +1,7 @@
(); @@ -38,13 +36,14 @@ export class PageIndicatorComponent extends ContextComponent p.page === this.number); + return this._fileDataService.viewedPages.find(p => p.page === this.number); } get dossierId() { @@ -111,23 +110,19 @@ export class PageIndicatorComponent extends ContextComponent p.page === this.number), - 1, - ); + await this._viewedPagesService.removePage(this.dossierId, this.fileId, this.number); + const pageToDelete = this._fileDataService.viewedPages.findIndex(p => p.page === this.number); + this._fileDataService.viewedPages.splice(pageToDelete, 1); this._setReadState(); } } 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 3b60d84a5..81adfb99a 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 @@ -509,13 +509,11 @@ export class FilePreviewScreenComponent filters: processFilters(primaryFilters, annotationFilters), }); const secondaryFilters = this._filterService.getGroup('secondaryFilters')?.filters; + const secondaryAnnotationFilters = this._annotationProcessingService.secondaryAnnotationFilters; this._filterService.addFilterGroup({ slug: 'secondaryFilters', filterTemplate: this._filterTemplate, - filters: processFilters( - secondaryFilters, - AnnotationProcessingService.secondaryAnnotationFilters(this._fileDataService.viewedPages), - ), + filters: processFilters(secondaryFilters, secondaryAnnotationFilters), }); this._logger.info(`[FILTERS] Rebuild time: ${new Date().getTime() - startTime} ms`); diff --git a/apps/red-ui/src/app/modules/file-preview/services/annotation-processing.service.ts b/apps/red-ui/src/app/modules/file-preview/services/annotation-processing.service.ts index a4ab3bfa2..4611431f2 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/annotation-processing.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/annotation-processing.service.ts @@ -4,7 +4,7 @@ import { SuperTypeSorter } from '../../../utils'; import { Filter, handleCheckedValue, IFilter, INestedFilter, NestedFilter } from '@iqser/common-ui'; import { annotationTypesTranslations } from '@translations/annotation-types-translations'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; -import { annotationDefaultColorConfig, IViewedPage } from '@red/domain'; +import { annotationDefaultColorConfig } from '@red/domain'; import { FilePreviewStateService } from './file-preview-state.service'; import { FileDataService } from './file-data.service'; import { DefaultColorsService } from '@services/entity-services/default-colors.service'; @@ -18,8 +18,7 @@ export class AnnotationProcessingService { private readonly _defaultColorsService: DefaultColorsService, ) {} - static secondaryAnnotationFilters(viewedPages?: IViewedPage[]): INestedFilter[] { - const _viewedPages = viewedPages ? viewedPages.map(page => page.page) : []; + get secondaryAnnotationFilters(): INestedFilter[] { return [ { id: 'with-comments', @@ -43,7 +42,8 @@ export class AnnotationProcessingService { label: _('filter-menu.unseen-pages'), checked: false, topLevelFilter: true, - checker: (annotation: AnnotationWrapper) => !_viewedPages.includes(annotation.pageNumber), + checker: (annotation: AnnotationWrapper) => + !this._fileDataService.viewedPages.some(page => page.page === annotation.pageNumber), }, { id: 'pages-without-annotations', diff --git a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts index 975f77543..2153b59c6 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts @@ -152,7 +152,7 @@ export class FileDataService extends EntitiesService { @Validate() addPage(@RequiredParam() body: IViewedPagesRequest, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { - return this._post(body, `${this._defaultModelPath}/${dossierId}/${fileId}`); + const modelPath = `${this._defaultModelPath}/${dossierId}/${fileId}`; + return firstValueFrom(this._post(body, modelPath)); } @Validate() removePage(@RequiredParam() dossierId: string, @RequiredParam() fileId: string, @RequiredParam() page: number) { - return super.delete({}, `${this._defaultModelPath}/${dossierId}/${fileId}/${page}`); + const modelPath = `${this._defaultModelPath}/${dossierId}/${fileId}/${page}`; + return firstValueFrom(super.delete({}, modelPath)); } @Validate() getViewedPages(@RequiredParam() dossierId: string, @RequiredParam() fileId: string) { - return this._getOne<{ pages?: IViewedPage[] }>([dossierId, fileId]).pipe( + const request = this._getOne<{ pages?: IViewedPage[] }>([dossierId, fileId]).pipe( map(res => res.pages), catchError(() => of([] as IViewedPage[])), ); + + return firstValueFrom(request); } } diff --git a/libs/common-ui b/libs/common-ui index b20d4e938..b60331ca0 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit b20d4e938cc5f172eda5a327ba9e0d2d4b6b4a4b +Subproject commit b60331ca0816d481adc29048874db97aa49ae8ce