naive filter completation
This commit is contained in:
parent
7da5a0bb3c
commit
60b41168d0
@ -13,6 +13,47 @@ export function processFilters(oldFilters: FilterModel[], newFilters: FilterMode
|
||||
return newFilters;
|
||||
}
|
||||
|
||||
export function handleFilterDelta(oldFilters: FilterModel[], newFilters: FilterModel[], allFilters: FilterModel[]) {
|
||||
const newFiltersDelta = {};
|
||||
for (const newFilter of newFilters) {
|
||||
const oldFilter = oldFilters.find((f) => f.key === newFilter.key);
|
||||
if (!oldFilter) {
|
||||
newFiltersDelta[newFilter.key] = {};
|
||||
newFilter.filters.forEach((filter) => (newFiltersDelta[newFilter.key][filter.key] = {}));
|
||||
} else {
|
||||
for (const childFilter of newFilter.filters) {
|
||||
const oldFilterChild = oldFilter.filters.find((f) => f.key === childFilter.key);
|
||||
if (!oldFilterChild) {
|
||||
if (!newFiltersDelta[newFilter.key]) {
|
||||
newFiltersDelta[newFilter.key] = {};
|
||||
}
|
||||
newFiltersDelta[newFilter.key][childFilter.key] = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of Object.keys(newFiltersDelta)) {
|
||||
const foundFilter = allFilters.find((f) => f.key === key);
|
||||
if (foundFilter) {
|
||||
// if has children
|
||||
if (!foundFilter.filters?.length) {
|
||||
foundFilter.checked = true;
|
||||
} else {
|
||||
for (const subKey of Object.keys(newFiltersDelta[key])) {
|
||||
const childFilter = foundFilter.filters.find((f) => f.key === subKey);
|
||||
if (childFilter) {
|
||||
childFilter.checked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
allFilters.forEach((filter) => {
|
||||
handleCheckedValue(filter);
|
||||
});
|
||||
}
|
||||
|
||||
function copySettings(oldFilters: FilterModel[], newFilters: FilterModel[]) {
|
||||
if (oldFilters && newFilters) {
|
||||
for (const oldFilter of oldFilters) {
|
||||
|
||||
@ -23,7 +23,7 @@ import { TranslateService } from '@ngx-translate/core';
|
||||
import { FileStatusWrapper } from '../model/file-status.wrapper';
|
||||
import { PermissionsService } from '../../../common/service/permissions.service';
|
||||
import { Subscription, timer } from 'rxjs';
|
||||
import { processFilters } from '../../../common/filter/utils/filter-utils';
|
||||
import { handleFilterDelta, processFilters } from '../../../common/filter/utils/filter-utils';
|
||||
import { UserPreferenceService } from '../../../common/service/user-preference.service';
|
||||
import { UserService } from '../../../user/user.service';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
@ -226,31 +226,15 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy {
|
||||
const annotation = this.activeViewer.annotManager.getAnnotationById(response.manualRedactionEntryWrapper.rectId);
|
||||
this.activeViewer.annotManager.deleteAnnotation(annotation);
|
||||
this.fileData.fileStatus = await this.appStateService.reloadActiveFile();
|
||||
this._cleanupAndRedrawManualAnnotations(response.annotationId);
|
||||
const distinctPages = $event.manualRedactionEntry.positions.map((p) => p.page).filter((item, pos, self) => self.indexOf(item) === pos);
|
||||
distinctPages.forEach((page) => {
|
||||
this._cleanupAndRedrawManualAnnotationsForEntirePage(page);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private _updateFiltersWith(key: string, subKey?: string) {
|
||||
const hasAnyFilterSet = this.annotationFilters.find((f) => f.checked || f.indeterminate);
|
||||
if (hasAnyFilterSet) {
|
||||
const filter = this.annotationFilters.find((f) => f.key === key);
|
||||
if (filter) {
|
||||
if (subKey) {
|
||||
const subFilter = filter.filters.find((f) => f.key === subKey);
|
||||
if (subFilter) {
|
||||
filter.checked = true;
|
||||
this.filtersChanged(this.annotationFilters);
|
||||
}
|
||||
} else {
|
||||
filter.checked = true;
|
||||
this.filtersChanged(this.annotationFilters);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@debounce()
|
||||
private _scrollViews() {
|
||||
this._scrollQuickNavigation();
|
||||
@ -460,22 +444,20 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
private _cleanupAndRedrawManualAnnotations(annotationIdToDraw?: string) {
|
||||
private _cleanupAndRedrawManualAnnotations() {
|
||||
this._fileDownloadService.loadActiveFileManualAnnotations().subscribe((manualRedactions) => {
|
||||
this.fileData.manualRedactions = manualRedactions;
|
||||
this._rebuildFilters();
|
||||
if (!this.redactedView) {
|
||||
this._annotationDrawService.drawAnnotations(
|
||||
this.instance,
|
||||
this.annotations.filter((item) => (annotationIdToDraw ? item.id === annotationIdToDraw : true))
|
||||
);
|
||||
this._annotationDrawService.drawAnnotations(this.instance, this.annotations);
|
||||
document.querySelectorAll('iframe')[0].click();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async _cleanupAndRedrawManualAnnotationsForEntirePage(page: number) {
|
||||
const currentPageAnnotationIds = this.annotations.filter((a) => a.pageNumber === page).map((a) => a.id);
|
||||
const currentPageAnnotations = this.annotations.filter((a) => a.pageNumber === page);
|
||||
const currentPageAnnotationIds = currentPageAnnotations.map((a) => a.id);
|
||||
this.fileData.fileStatus = await this.appStateService.reloadActiveFile();
|
||||
|
||||
this._fileDownloadService.loadActiveFileManualAnnotations().subscribe((manualRedactions) => {
|
||||
@ -485,15 +467,24 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy {
|
||||
currentPageAnnotationIds.forEach((id) => {
|
||||
this._findAndDeleteAnnotation(id);
|
||||
});
|
||||
this._annotationDrawService.drawAnnotations(
|
||||
this.instance,
|
||||
this.annotations.filter((item) => item.pageNumber === page)
|
||||
);
|
||||
const newPageAnnotations = this.annotations.filter((item) => item.pageNumber === page);
|
||||
this._handleDeltaAnnotationFilters(currentPageAnnotations, newPageAnnotations);
|
||||
this._annotationDrawService.drawAnnotations(this.instance, newPageAnnotations);
|
||||
document.querySelectorAll('iframe')[0].click();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _handleDeltaAnnotationFilters(currentPageAnnotations: AnnotationWrapper[], newPageAnnotations: AnnotationWrapper[]) {
|
||||
const hasAnyFilterSet = this.annotationFilters.find((f) => f.checked || f.indeterminate);
|
||||
if (hasAnyFilterSet) {
|
||||
const oldPageSpecificFilters = this._annotationProcessingService.getAnnotationFilter(currentPageAnnotations);
|
||||
const newPageSpecificFilters = this._annotationProcessingService.getAnnotationFilter(newPageAnnotations);
|
||||
handleFilterDelta(oldPageSpecificFilters, newPageSpecificFilters, this.annotationFilters);
|
||||
this.filtersChanged(this.annotationFilters);
|
||||
}
|
||||
}
|
||||
|
||||
async annotationsChangedByReviewAction(annotation: AnnotationWrapper) {
|
||||
await this._cleanupAndRedrawManualAnnotationsForEntirePage(annotation.pageNumber);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user