diff --git a/src/atlasComponents/userAnnotations/annotationList/annotationList.component.ts b/src/atlasComponents/userAnnotations/annotationList/annotationList.component.ts index cf5132c2192da11cecb1ffaa1be11c2a40302fb5..fbc8b0d6f456823085c50a072d7209a041bc36ef 100644 --- a/src/atlasComponents/userAnnotations/annotationList/annotationList.component.ts +++ b/src/atlasComponents/userAnnotations/annotationList/annotationList.component.ts @@ -14,8 +14,8 @@ export class AnnotationList { get annotationsToShow() { return this.ans.annotations - // .filter(a => this.annotationFilter === 'all' || a.templateName === this.ans.selectedTemplate) - // .filter(a => (a.type !== 'polygon' || +a.id.split('_')[1] === 0) + // .filter(a => this.annotationFilter === 'all' || a.templateName === this.ans.selectedTemplate) + // .filter(a => (a.type !== 'polygon' || +a.id.split('_')[1] === 0) // let transformed = [...this.ans.annotations] // @@ -115,4 +115,18 @@ export class AnnotationList { this.ans.saveAnnotation(annotation) } + savePolygonPosition(position, inputVal) { + position.lines.forEach(l => { + if (l.point === 2) { + const annotation = this.ans.annotations.find(a => a.id === l.id) + annotation.position2 = inputVal + this.saveAnnotation(annotation) + } else { + const annotation = this.ans.annotations.find(a => a.id === l.id) + annotation.position1 = inputVal + this.saveAnnotation(annotation) + } + }) + } + } diff --git a/src/atlasComponents/userAnnotations/annotationList/annotationList.template.html b/src/atlasComponents/userAnnotations/annotationList/annotationList.template.html index b7a72d61f951e1cc81d7ee835c333c54fe333b19..731f821a89d7d8874a133ef93cca777309bce2da 100644 --- a/src/atlasComponents/userAnnotations/annotationList/annotationList.template.html +++ b/src/atlasComponents/userAnnotations/annotationList/annotationList.template.html @@ -86,8 +86,9 @@ <div *ngFor="let position of annotation.positions" class="w-100 d-flex align-items-center justify-content-between mb-2"> <input class="w-100 font-italic d-flex align-items-center outline-none color-inherit" [value]="position?.position" - (keyup)="this.saveAnnotation(annotation)"/> - <small class="d-flex align-items-center">mm <i class="fas fa-map-marked-alt mr-2 ml-2 cursor-pointer" (click)="navigate(annotation?.position?.position)"></i></small> + #polygonPositionInput + (keyup)="this.savePolygonPosition(position, polygonPositionInput.value)"/> + <small class="d-flex align-items-center">mm <i class="fas fa-map-marked-alt mr-2 ml-2 cursor-pointer" (click)="navigate(position?.position)"></i></small> </div> </div> diff --git a/src/atlasComponents/userAnnotations/annotationService.service.ts b/src/atlasComponents/userAnnotations/annotationService.service.ts index f72f2cea3c1b2933c03b090dff33e7ff17d66477..6e361e0b11f6a1847bedb20e1d1e07cb5796b2f7 100644 --- a/src/atlasComponents/userAnnotations/annotationService.service.ts +++ b/src/atlasComponents/userAnnotations/annotationService.service.ts @@ -122,18 +122,20 @@ export class AnnotationService implements OnDestroy { } } + giveNameByType(type) { + const pointAnnotationNumber = this.annotations + .filter(a => a.name && a.name.startsWith(type) && (+a.name.split(type)[1])) + .map(a => +a.name.split(type)[1]) + + return pointAnnotationNumber && pointAnnotationNumber.length? + `${type}${Math.max(...pointAnnotationNumber) + 1}` : `${type}1` + + } + storeAnnotation(annotation) { // give names by type + number if (!annotation.name) { - const pointAnnotationNumber = this.annotations - .filter(a => a.name && a.name.startsWith(annotation.type) && (+a.name.split(annotation.type)[1])) - .map(a => +a.name.split(annotation.type)[1]) - - if (pointAnnotationNumber && pointAnnotationNumber.length) { - annotation.name = `${annotation.type}${Math.max(...pointAnnotationNumber) + 1}` - } else { - annotation.name = `${annotation.type}1` - } + annotation.name = this.giveNameByType(annotation.type) } const foundIndex = this.annotations.findIndex(x => x.id === annotation.id) @@ -198,6 +200,7 @@ export class AnnotationService implements OnDestroy { removeAnnotation(id) { this.removeAnnotationFromViewer(id) this.annotations = this.annotations.filter(a => a.id !== id) + this.displayAnnotations = this.annotations.filter(a => a.id !== id) this.storeToLocalStorage() } @@ -227,29 +230,33 @@ export class AnnotationService implements OnDestroy { const polygonAnnotations = annotations.filter(a => a.id.split('_')[0] === annotationId[0] && a.id.split('_')[1]) - const polygonPositions = polygonAnnotations.map((a, i) => { - return i+1 !== polygonAnnotations.length? { + const polygonPositions = polygonAnnotations.map((a, index) => { + return (index+1) !== polygonAnnotations.length? { position: a.position2, lines: [ {id: a.id, point: 2}, - {id: polygonAnnotations[i+1], point: 1} + {id: polygonAnnotations[index+1].id, point: 1} ] - } : polygonAnnotations[i].position2 !== polygonAnnotations[0].position1? { + } : a.position2 !== polygonAnnotations[0].position1? { position: a.position2, lines: [ {id: a.id, point: 2} ] - } : { - position: a.position2, - lines: [ - {id: a.id, point: 2}, - {id: polygonAnnotations[0].id, point: 1} - ] - } + } : null + }).filter(a => !!a) + polygonPositions.unshift({ + position: polygonAnnotations[0].position1, + lines: polygonAnnotations[0].position1 === [...polygonAnnotations].pop().position2? + [{id: polygonAnnotations[0].id, point: 1}, {id: [...polygonAnnotations].pop().id, point: 2}] + : [{id: polygonAnnotations[0].id, point: 1}] }) transformed = transformed.filter(a => a.id.split('_')[0] !== annotationId[0]) + if (!annotations[i].name) { + annotations[i].name = this.giveNameByType(annotations[i].type) + } + transformed.push({ id: annotationId[0], name: annotations[i].name, @@ -263,10 +270,15 @@ export class AnnotationService implements OnDestroy { } - this.displayAnnotations = [ - ...this.displayAnnotations, - ...transformed - ] + transformed.forEach(tr=> { + const foundIndex = this.displayAnnotations.findIndex(x => x.id === tr.id) + + if (foundIndex >= 0) { + this.displayAnnotations[foundIndex] = tr + } else { + this.displayAnnotations.push(tr) + } + }) } changeAnnotationFilter(filter) {