RED-9175: prevent search re-trigger upon navigating the file pages.

This commit is contained in:
Nicoleta Panaghiu 2024-05-31 11:33:14 +03:00
parent f02323561c
commit 1ea03ac015
3 changed files with 34 additions and 11 deletions

View File

@ -36,6 +36,7 @@ export class PageExclusionComponent {
try {
const pageRanges = extractPageRanges(inputValue, file);
await this._reanalysisService.excludePages({ pageRanges }, file);
this._state.excludedPages.update(value => [...value, ...this.flattenPageRanges(pageRanges)]);
this._inputComponent.reset();
} catch (e) {
this._toaster.error(_('file-preview.tabs.exclude-pages.error'));
@ -46,6 +47,7 @@ export class PageExclusionComponent {
async includePagesRange(range: IPageRange): Promise<void> {
this._loadingService.start();
await this._reanalysisService.includePages({ pageRanges: [range] }, this._state.file());
this._state.excludedPages.update(value => value.filter(page => !this.flattenPageRanges([range]).includes(page)));
this._inputComponent.reset();
this._loadingService.stop();
}
@ -64,4 +66,15 @@ export class PageExclusionComponent {
return ranges;
}, []);
}
flattenPageRanges(ranges: IPageRange[]) {
const flattenedPages = [];
ranges.forEach(range => {
for (let page = range.startPage; page <= range.endPage; page++) {
flattenedPages.push(page);
}
});
return flattenedPages;
}
}

View File

@ -32,7 +32,7 @@ import {
Toaster,
} from '@iqser/common-ui';
import { copyLocalStorageFiltersValues, FilterService, NestedFilter, processFilters } from '@iqser/common-ui/lib/filtering';
import { AutoUnsubscribe, Bind, bool, Debounce, List, OnAttach, OnDetach } from '@iqser/common-ui/lib/utils';
import { AutoUnsubscribe, Bind, bool, Debounce, List, log, OnAttach, OnDetach } from '@iqser/common-ui/lib/utils';
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { ManualRedactionEntryTypes, ManualRedactionEntryWrapper } from '@models/file/manual-redaction-entry.wrapper';
import { Dictionary, File, ViewModes } from '@red/domain';
@ -173,14 +173,17 @@ export class FilePreviewScreenComponent
}
});
effect(() => {
this._viewModeService.viewMode();
this.updateViewMode().then();
});
effect(() => {
this.state.updateExcludedPagesStyle();
if (this._viewModeService.viewMode()) {
this.updateViewMode().then();
if (_documentViewer.loaded()) {
this._logger.info('[PDF] Stamp pdf');
this._stampService.stampPDF().then();
}
this._viewModeService.viewMode();
if (_documentViewer.loaded()) {
this._logger.info('[PDF] Stamp pdf');
this._stampService.stampPDF().then();
}
});
}
@ -810,6 +813,7 @@ export class FilePreviewScreenComponent
_('error.deleted-entity.file-dossier.label'),
_('error.deleted-entity.file-dossier.action'),
'iqser:expand',
null,
);
this._errorService.set(error);
}

View File

@ -1,10 +1,10 @@
import { HttpEvent, HttpEventType, HttpProgressEvent, HttpResponse } from '@angular/common/http';
import { computed, effect, inject, Injectable, signal, Signal } from '@angular/core';
import { computed, effect, inject, Injectable, signal, Signal, WritableSignal } from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { LoadingService, wipeCache } from '@iqser/common-ui';
import { getParam } from '@iqser/common-ui/lib/utils';
import { TranslateService } from '@ngx-translate/core';
import { Dictionary, Dossier, DOSSIER_ID, DOSSIER_TEMPLATE_ID, File, FILE_ID } from '@red/domain';
import { Dictionary, Dossier, DOSSIER_ID, DOSSIER_TEMPLATE_ID, File, FILE_ID, ViewModes } from '@red/domain';
import { DossiersService } from '@services/dossiers/dossiers.service';
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
import { DossierDictionariesMapService } from '@services/entity-services/dossier-dictionaries-map.service';
@ -44,7 +44,10 @@ export class FilePreviewStateService {
readonly dossierId = getParam(DOSSIER_ID);
readonly dossierTemplateId = getParam(DOSSIER_TEMPLATE_ID);
readonly fileId = getParam(FILE_ID);
readonly updateExcludedPagesStyle = computed(() => this.file().excludedPages);
readonly excludedPages: WritableSignal<number[]>;
readonly updateExcludedPagesStyle = computed(() => {
return this.excludedPages();
});
readonly isEditingReviewer = signal(false);
constructor(
@ -61,6 +64,7 @@ export class FilePreviewStateService {
this.dossier = toSignal(dossiersServiceResolver().getEntityChanged$(this.dossierId));
this.file$ = inject(FilesMapService).watch$(this.dossierId, this.fileId);
this.file = toSignal(this.file$);
this.excludedPages = signal(this.file().excludedPages);
this.isWritable = computed(() => {
const isWritable = this._permissionsService.canPerformAnnotationActions(this.file(), this.dossier());
this._logger.info('[FILE] Is writeable:', isWritable);
@ -80,7 +84,9 @@ export class FilePreviewStateService {
effect(
() => {
if (this._viewModeService.isEarmarks() && !this.file().hasHighlights) {
this._viewModeService.switchToStandard();
if (this._viewModeService.viewMode() !== ViewModes.STANDARD) {
this._viewModeService.switchToStandard();
}
}
},
{ allowSignalWrites: true },