naive filter completation

This commit is contained in:
Timo 2020-12-23 10:58:16 +02:00
parent 7da5a0bb3c
commit 60b41168d0
2 changed files with 63 additions and 31 deletions

View File

@ -13,6 +13,47 @@ export function processFilters(oldFilters: FilterModel[], newFilters: FilterMode
return newFilters; 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[]) { function copySettings(oldFilters: FilterModel[], newFilters: FilterModel[]) {
if (oldFilters && newFilters) { if (oldFilters && newFilters) {
for (const oldFilter of oldFilters) { for (const oldFilter of oldFilters) {

View File

@ -23,7 +23,7 @@ import { TranslateService } from '@ngx-translate/core';
import { FileStatusWrapper } from '../model/file-status.wrapper'; import { FileStatusWrapper } from '../model/file-status.wrapper';
import { PermissionsService } from '../../../common/service/permissions.service'; import { PermissionsService } from '../../../common/service/permissions.service';
import { Subscription, timer } from 'rxjs'; 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 { UserPreferenceService } from '../../../common/service/user-preference.service';
import { UserService } from '../../../user/user.service'; import { UserService } from '../../../user/user.service';
import { FormBuilder, FormGroup } from '@angular/forms'; 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); const annotation = this.activeViewer.annotManager.getAnnotationById(response.manualRedactionEntryWrapper.rectId);
this.activeViewer.annotManager.deleteAnnotation(annotation); this.activeViewer.annotManager.deleteAnnotation(annotation);
this.fileData.fileStatus = await this.appStateService.reloadActiveFile(); 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() @debounce()
private _scrollViews() { private _scrollViews() {
this._scrollQuickNavigation(); this._scrollQuickNavigation();
@ -460,22 +444,20 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy {
} }
} }
private _cleanupAndRedrawManualAnnotations(annotationIdToDraw?: string) { private _cleanupAndRedrawManualAnnotations() {
this._fileDownloadService.loadActiveFileManualAnnotations().subscribe((manualRedactions) => { this._fileDownloadService.loadActiveFileManualAnnotations().subscribe((manualRedactions) => {
this.fileData.manualRedactions = manualRedactions; this.fileData.manualRedactions = manualRedactions;
this._rebuildFilters(); this._rebuildFilters();
if (!this.redactedView) { if (!this.redactedView) {
this._annotationDrawService.drawAnnotations( this._annotationDrawService.drawAnnotations(this.instance, this.annotations);
this.instance,
this.annotations.filter((item) => (annotationIdToDraw ? item.id === annotationIdToDraw : true))
);
document.querySelectorAll('iframe')[0].click(); document.querySelectorAll('iframe')[0].click();
} }
}); });
} }
private async _cleanupAndRedrawManualAnnotationsForEntirePage(page: number) { 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.fileData.fileStatus = await this.appStateService.reloadActiveFile();
this._fileDownloadService.loadActiveFileManualAnnotations().subscribe((manualRedactions) => { this._fileDownloadService.loadActiveFileManualAnnotations().subscribe((manualRedactions) => {
@ -485,15 +467,24 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy {
currentPageAnnotationIds.forEach((id) => { currentPageAnnotationIds.forEach((id) => {
this._findAndDeleteAnnotation(id); this._findAndDeleteAnnotation(id);
}); });
this._annotationDrawService.drawAnnotations( const newPageAnnotations = this.annotations.filter((item) => item.pageNumber === page);
this.instance, this._handleDeltaAnnotationFilters(currentPageAnnotations, newPageAnnotations);
this.annotations.filter((item) => item.pageNumber === page) this._annotationDrawService.drawAnnotations(this.instance, newPageAnnotations);
);
document.querySelectorAll('iframe')[0].click(); 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) { async annotationsChangedByReviewAction(annotation: AnnotationWrapper) {
await this._cleanupAndRedrawManualAnnotationsForEntirePage(annotation.pageNumber); await this._cleanupAndRedrawManualAnnotationsForEntirePage(annotation.pageNumber);
} }