Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with unchanged label color after swap #625

Merged
merged 6 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions resources/assets/js/annotations/annotatorContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ export default {
handleDetachAnnotationLabel(annotation, annotationLabel) {
if (this.isEditor) {
if (annotation.labels.length > 1) {
AnnotationsStore.detachLabel(annotation, annotationLabel)
return AnnotationsStore.detachLabel(annotation, annotationLabel)
.catch(handleErrorResponse);
mzur marked this conversation as resolved.
Show resolved Hide resolved
} else if (confirm('Detaching the last label of an annotation deletes the whole annotation. Do you want to delete the annotation?')) {
this.handleDeleteAnnotation(annotation);
return this.handleDeleteAnnotation(annotation);
}
}
},
Expand All @@ -370,7 +370,7 @@ export default {
// Mark for deletion so the annotation is immediately removed from
// the canvas. See https://github.com/biigle/annotations/issues/70
Vue.set(annotation, 'markedForDeletion', true);
AnnotationsStore.delete(annotation)
return AnnotationsStore.delete(annotation)
.catch(function (response) {
annotation.markedForDeletion = false;
handleErrorResponse(response);
Expand Down Expand Up @@ -443,12 +443,18 @@ export default {
this.handleAttachLabel(annotation, label)
.then(() => {
if (lastLabel) {
this.handleDetachAnnotationLabel(annotation, lastLabel);
this.handleDetachAnnotationLabel(annotation, lastLabel)
.then(() => {
this.refreshAnnotation(annotation);
});
}
})
.catch(handleErrorResponse);
}
},
refreshAnnotation(annotation){
this.$refs.canvas.refreshAnnotation(annotation);
},
handleAttachAllSelected() {
this.selectedAnnotations.forEach(this.handleAttachLabel);
},
Expand Down
11 changes: 11 additions & 0 deletions resources/assets/js/annotations/components/annotationCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,17 @@ export default {
},
updateMousePosition(e) {
this.mousePosition = e.coordinate;
},
refreshAnnotation(annotation) {
let source = this.annotationSource;

let newFeature = this.createFeature(annotation);
let oldFeature = source.getFeatureById(annotation.id)

source.removeFeature(oldFeature);
source.addFeature(newFeature);


mzur marked this conversation as resolved.
Show resolved Hide resolved
},
refreshAnnotationSource(annotations, source) {
let annotationsMap = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Point from '@biigle/ol/geom/Point';
import Polygon from '@biigle/ol/geom/Polygon';
import Rectangle from '@biigle/ol/geom/Rectangle';
import {getRoundToPrecision} from '../../utils';
import Events from '../../../core/events';
mzur marked this conversation as resolved.
Show resolved Hide resolved

/**
* Mixin for the videoScreen component that contains logic for the annotation playback.
Expand Down Expand Up @@ -125,6 +126,15 @@ export default {
this.updateGeometry(feature, time);
});
},
refreshAnnotation(annotation) {
mzur marked this conversation as resolved.
Show resolved Hide resolved
let source = this.annotationSource;

let newFeature = this.createFeature(annotation);
let oldFeature = source.getFeatureById(annotation.id)

source.removeFeature(oldFeature);
source.addFeature(newFeature);
},
createFeature(annotation) {
let feature = new Feature(this.getGeometryFromPoints(annotation.shape, annotation.points[0]));

Expand Down Expand Up @@ -226,6 +236,7 @@ export default {
},
},
created() {
Events.$on('video.swap', this.refreshAnnotation);
mzur marked this conversation as resolved.
Show resolved Hide resolved
this.$on('refresh', this.refreshAnnotations);
this.$once('map-ready', () => {
this.$watch('annotationsRevision', () => {
Expand Down
8 changes: 5 additions & 3 deletions resources/assets/js/videos/videoContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ export default {
},
detachAnnotationLabel(annotation, annotationLabel) {
if (annotation.labels.length > 1) {
annotation.detachAnnotationLabel(annotationLabel)
return annotation.detachAnnotationLabel(annotationLabel)
.catch(handleErrorResponse);
} else if (confirm('Detaching the last label of an annotation deletes the whole annotation. Do you want to delete the annotation?')) {
annotation.delete()
return annotation.delete()
.then(() => this.removeAnnotation(annotation))
.catch(handleErrorResponse);
}
Expand All @@ -425,7 +425,9 @@ export default {
this.attachAnnotationLabel(annotation)
.then(() => {
if (lastLabel) {
this.detachAnnotationLabel(annotation, lastLabel);
this.detachAnnotationLabel(annotation, lastLabel)
.then(Events.$emit('video.swap', annotation));
mzur marked this conversation as resolved.
Show resolved Hide resolved
mzur marked this conversation as resolved.
Show resolved Hide resolved

}
})
.catch(handleErrorResponse);
Expand Down