RED-4027: Fixed annotations sorting

This commit is contained in:
Adina Țeudan 2022-05-12 21:45:58 +03:00
parent 5523a2a815
commit 6b3f117745
3 changed files with 10 additions and 23 deletions

View File

@ -205,15 +205,17 @@ export class AnnotationProcessingService {
private _checkByFilterKey = (filter: NestedFilter | IFilter, annotation: AnnotationWrapper) => filter.id === annotation.filterKey;
private _sortAnnotations(annotations: AnnotationWrapper[]): AnnotationWrapper[] {
return annotations.sort((ann1, ann2) => {
if (ann1.pageNumber === ann2.pageNumber) {
if (ann1.y === ann2.y) {
return ann1.x < ann2.x ? 1 : -1;
return annotations.sort((first, second) => {
if (first.pageNumber === second.pageNumber) {
if (first.y > second.y) {
return -1;
} else if (first.y < second.y) {
return 1;
} else {
return ann1.y < ann2.y ? 1 : -1;
return first.x < second.x ? -1 : 1;
}
}
return ann1.pageNumber < ann2.pageNumber ? -1 : 1;
return first.pageNumber < second.pageNumber ? -1 : 1;
});
}
}

View File

@ -7,7 +7,6 @@ import {
Input,
OnChanges,
Output,
SimpleChanges,
TemplateRef,
} from '@angular/core';
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
@ -49,11 +48,7 @@ export class AnnotationsListComponent extends HasScrollbarDirective implements O
super(_elementRef, _changeDetector);
}
ngOnChanges(changes?: SimpleChanges): void {
if (changes.annotations && this.annotations && !this._viewModeService.isTextHighlights) {
this.annotations = this.annotations.sort(this.annotationsPositionCompare);
}
ngOnChanges(): void {
if (this._viewModeService.isTextHighlights) {
this._updateHighlightGroups();
}
@ -92,16 +87,6 @@ export class AnnotationsListComponent extends HasScrollbarDirective implements O
}
}
annotationsPositionCompare(first: AnnotationWrapper, second: AnnotationWrapper): number {
if (first.y > second.y) {
return -1;
} else if (first.y < second.y) {
return 1;
} else {
return first.x < second.x ? -1 : 1;
}
}
showHighlightGroup(idx: number): TextHighlightsGroup {
return this._viewModeService.isTextHighlights && this.highlightGroups$.value.find(h => h.startIdx === idx);
}

View File

@ -383,7 +383,7 @@ export class FileWorkloadComponent {
} else {
this.displayedPages = this.#allPages;
}
this.displayedPages = this.displayedPages.sort((a, b) => a - b);
this.displayedPages.sort((a, b) => a - b);
return this.displayedAnnotations;
}