RED-3837: fix annotations redraw
This commit is contained in:
parent
6d61d0519d
commit
9dec57a7ee
@ -65,9 +65,8 @@ function cleanupBaseUrl(baseUrl: string) {
|
||||
return '';
|
||||
} else if (baseUrl[baseUrl.length - 1] === '/') {
|
||||
return baseUrl.substring(0, baseUrl.length - 1);
|
||||
} else {
|
||||
return baseUrl;
|
||||
}
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
const screens = [BaseScreenComponent, DownloadsListScreenComponent];
|
||||
@ -128,7 +127,13 @@ const components = [AppComponent, AuthErrorComponent, NotificationsComponent, Sp
|
||||
enabled: false,
|
||||
},
|
||||
PDF: {
|
||||
enabled: true,
|
||||
enabled: false,
|
||||
},
|
||||
FILE: {
|
||||
enabled: false,
|
||||
},
|
||||
CHANGES: {
|
||||
enabled: false,
|
||||
},
|
||||
STATS: {
|
||||
enabled: false,
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
Debounce,
|
||||
ErrorService,
|
||||
FilterService,
|
||||
List,
|
||||
LoadingService,
|
||||
NestedFilter,
|
||||
OnAttach,
|
||||
@ -26,7 +27,7 @@ import { File, ViewMode, ViewModes } from '@red/domain';
|
||||
import { PermissionsService } from '@services/permissions.service';
|
||||
import { combineLatest, firstValueFrom, from, of, pairwise } from 'rxjs';
|
||||
import { UserPreferenceService } from '@services/user-preference.service';
|
||||
import { byId, byPage, download, handleFilterDelta } from '../../utils';
|
||||
import { byId, byPage, download, handleFilterDelta, hasChanges } from '../../utils';
|
||||
import { FilesService } from '@services/files/files.service';
|
||||
import { FileManagementService } from '@services/files/file-management.service';
|
||||
import { catchError, filter, map, startWith, switchMap, tap } from 'rxjs/operators';
|
||||
@ -368,11 +369,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
tap(annotations => this.deleteAnnotations(...annotations)),
|
||||
);
|
||||
const currentPageAnnotations$ = combineLatest([this.pdf.currentPage$, annotations$]).pipe(
|
||||
map(([, annotations]) => annotations),
|
||||
map(([oldAnnotations, newAnnotations]) => {
|
||||
const page = this.pdf.currentPage;
|
||||
return [oldAnnotations.filter(byPage(page)), newAnnotations.filter(byPage(page))] as const;
|
||||
}),
|
||||
map(
|
||||
([page, [oldAnnotations, newAnnotations]]) =>
|
||||
[oldAnnotations.filter(byPage(page)), newAnnotations.filter(byPage(page))] as const,
|
||||
),
|
||||
);
|
||||
|
||||
let start;
|
||||
@ -390,16 +390,9 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
deleteAnnotations(oldAnnotations: AnnotationWrapper[], newAnnotations: AnnotationWrapper[]) {
|
||||
const annotationsToDelete = oldAnnotations.filter(oldAnnotation => {
|
||||
const newAnnotation = newAnnotations.find(byId(oldAnnotation.id));
|
||||
if (!newAnnotation) {
|
||||
return true;
|
||||
}
|
||||
return JSON.stringify(oldAnnotation) !== JSON.stringify(newAnnotation);
|
||||
return newAnnotation ? hasChanges(oldAnnotation, newAnnotation) : true;
|
||||
});
|
||||
|
||||
if (annotationsToDelete.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._logger.info('[ANNOTATIONS] To delete: ', annotationsToDelete);
|
||||
this._annotationManager.delete(annotationsToDelete);
|
||||
}
|
||||
@ -407,11 +400,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
async drawChangedAnnotations(oldAnnotations: AnnotationWrapper[], newAnnotations: AnnotationWrapper[]) {
|
||||
const annotationsToDraw = this.#getAnnotationsToDraw(oldAnnotations, newAnnotations);
|
||||
this._logger.info('[ANNOTATIONS] To draw: ', annotationsToDraw);
|
||||
|
||||
if (annotationsToDraw.length === 0) {
|
||||
return [oldAnnotations, newAnnotations];
|
||||
}
|
||||
|
||||
this._annotationManager.delete(annotationsToDraw);
|
||||
await this._cleanupAndRedrawAnnotations(annotationsToDraw);
|
||||
return [oldAnnotations, newAnnotations];
|
||||
@ -427,12 +415,12 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
}
|
||||
|
||||
#getAnnotationsToDraw(oldAnnotations: AnnotationWrapper[], newAnnotations: AnnotationWrapper[]) {
|
||||
const annotations = this._annotationManager.annotations;
|
||||
const ann = annotations.map(a => oldAnnotations.some(byId(a.Id)));
|
||||
const hasAnnotations = ann.filter(a => !!a).length > 0;
|
||||
const currentPage = this.pdf.currentPage;
|
||||
const currentPageAnnotations = this._annotationManager.get(a => a.getPageNumber() === currentPage);
|
||||
const existingAnnotations = currentPageAnnotations.map(a => oldAnnotations.find(byId(a.Id))).filter(a => !!a);
|
||||
|
||||
if (hasAnnotations) {
|
||||
return this.#findAnnotationsToDraw(newAnnotations, oldAnnotations);
|
||||
if (existingAnnotations.length > 0) {
|
||||
return this.#findAnnotationsToDraw(newAnnotations, oldAnnotations, existingAnnotations);
|
||||
}
|
||||
return newAnnotations;
|
||||
}
|
||||
@ -471,19 +459,30 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
this._changeDetectorRef.markForCheck();
|
||||
}
|
||||
|
||||
#findAnnotationsToDraw(newAnnotations: AnnotationWrapper[], oldAnnotations: AnnotationWrapper[]) {
|
||||
#findAnnotationsToDraw(
|
||||
newAnnotations: AnnotationWrapper[],
|
||||
oldAnnotations: AnnotationWrapper[],
|
||||
existingAnnotations: AnnotationWrapper[],
|
||||
) {
|
||||
function selectToDrawIfDoesNotExist(newAnnotation: AnnotationWrapper) {
|
||||
return !existingAnnotations.some(byId(newAnnotation.id));
|
||||
}
|
||||
|
||||
return newAnnotations.filter(newAnnotation => {
|
||||
const oldAnnotation = oldAnnotations.find(byId(newAnnotation.id));
|
||||
if (!oldAnnotation) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const changed = JSON.stringify(oldAnnotation) !== JSON.stringify(newAnnotation);
|
||||
if (changed && this.userPreferenceService.areDevFeaturesEnabled) {
|
||||
if (!hasChanges(oldAnnotation, newAnnotation)) {
|
||||
return selectToDrawIfDoesNotExist(newAnnotation);
|
||||
}
|
||||
|
||||
if (this.userPreferenceService.areDevFeaturesEnabled) {
|
||||
this.#logDiff(oldAnnotation, newAnnotation);
|
||||
}
|
||||
|
||||
return changed;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@ -586,7 +585,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
this._errorService.set(error);
|
||||
}
|
||||
|
||||
private async _cleanupAndRedrawAnnotations(newAnnotations: readonly AnnotationWrapper[]) {
|
||||
private async _cleanupAndRedrawAnnotations(newAnnotations: List<AnnotationWrapper>) {
|
||||
if (!newAnnotations.length) {
|
||||
return;
|
||||
}
|
||||
const currentFilters = this._filterService.getGroup('primaryFilters')?.filters || [];
|
||||
this.#rebuildFilters();
|
||||
|
||||
|
||||
@ -42,6 +42,9 @@ export class REDAnnotationManager {
|
||||
|
||||
delete(annotations?: List | List<AnnotationWrapper> | string | AnnotationWrapper) {
|
||||
const items = isStringOrWrapper(annotations) ? [this.get(annotations)] : this.get(annotations);
|
||||
if (!items.length) {
|
||||
return;
|
||||
}
|
||||
const options: DeleteAnnotationsOptions = { force: true };
|
||||
this.#manager.deleteAnnotations(items, options);
|
||||
}
|
||||
|
||||
@ -96,3 +96,7 @@ export function getLast<T>(list: List<T>) {
|
||||
}
|
||||
|
||||
export const dateWithoutTime = (date: Dayjs) => date.set('h', 0).set('m', 0).set('s', 0).set('ms', 0);
|
||||
|
||||
export function hasChanges<T>(left: T, right: T) {
|
||||
return JSON.stringify(left) !== JSON.stringify(right);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user