Pull request #322: added annotation sorting on changes

Merge in RED/ui from RED-2741 to master

* commit '59078d8868e92d5b7bfc10c6063ddb69d933e56a':
  added annotation sorting on changes
This commit is contained in:
Eduard Cziszter 2021-12-10 18:54:30 +01:00 committed by Dan Percic
commit bc493743d8

View File

@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, TemplateRef } from '@angular/core';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, TemplateRef } from '@angular/core';
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { HelpModeService, IqserEventTarget } from '@iqser/common-ui';
import { File } from '@red/domain';
@ -10,7 +10,7 @@ import { MultiSelectService } from '../../services/multi-select.service';
styleUrls: ['./annotations-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AnnotationsListComponent {
export class AnnotationsListComponent implements OnChanges {
@Input() file: File;
@Input() annotations: AnnotationWrapper[];
@Input() selectedAnnotations: AnnotationWrapper[];
@ -24,6 +24,12 @@ export class AnnotationsListComponent {
constructor(readonly multiSelectService: MultiSelectService, readonly helpModeService: HelpModeService) {}
ngOnChanges(changes: SimpleChanges): void {
if (changes.annotations && this.annotations) {
this.annotations = this.annotations.sort(this.annotationsPositionCompare);
}
}
annotationClicked(annotation: AnnotationWrapper, $event: MouseEvent): void {
if (($event.target as IqserEventTarget).localName === 'input') {
return;
@ -42,4 +48,14 @@ export class AnnotationsListComponent {
isSelected(annotationId: string): boolean {
return !!this.selectedAnnotations?.find(a => a?.annotationId === annotationId);
}
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.y ? -1 : 1;
}
}
}