Skip to content

Commit a7c23e0

Browse files
committed
better error handling when creating an annotation
1 parent a0bce56 commit a7c23e0

File tree

1 file changed

+25
-6
lines changed
  • imagetagger/imagetagger/annotations/static/annotations/js

1 file changed

+25
-6
lines changed

imagetagger/imagetagger/annotations/static/annotations/js/annotations.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ function calculateImageScale() {
182182
* If an annotation is currently edited, an update is triggered instead.
183183
*
184184
* @param annotation the annotation to be created, as returned by getValidAnnotation
185+
* @return whether the annotation was successfully created
185186
*/
186187
async function createAnnotation(annotation) {
187188

@@ -194,6 +195,8 @@ function calculateImageScale() {
194195
editing = true;
195196
}
196197

198+
let success = true;
199+
197200
$('.js_feedback').stop().addClass('hidden');
198201
$('.annotate_button').prop('disabled', true);
199202
try {
@@ -209,11 +212,13 @@ function calculateImageScale() {
209212
if (data.detail === 'similar annotation exists.') {
210213
displayFeedback($('#feedback_annotation_exists_deleted'));
211214
$('#annotation_edit_button_' + gEditAnnotationId).parent().parent().fadeOut().remove();
215+
success = false;
212216
} else {
213217
displayFeedback($('#feedback_annotation_updated'));
214218
}
215219
} else {
216220
displayFeedback($('#feedback_annotation_exists'));
221+
success = false;
217222
}
218223
} else if (response.status === 201) {
219224
displayFeedback($('#feedback_annotation_created'));
@@ -227,9 +232,11 @@ function calculateImageScale() {
227232
} catch (e) {
228233
console.log(e);
229234
displayFeedback($('#feedback_connection_error'));
235+
success = false;
230236
} finally {
231237
$('.annotate_button').prop('disabled', false);
232238
}
239+
return success;
233240
}
234241

235242
async function loadAnnotationTypeList() {
@@ -1173,9 +1180,15 @@ function calculateImageScale() {
11731180
$('#last_button').click(async function (event) {
11741181
try {
11751182
let annotation = getValidAnnotation(true);
1176-
await createAnnotation(annotation);
1177-
let imageId = await loadAdjacentImage(-1);
1178-
await changeImage(imageId, annotation);
1183+
if (await createAnnotation(annotation)) {
1184+
let imageId = await loadAdjacentImage(-1);
1185+
await changeImage(imageId, annotation);
1186+
} else {
1187+
tool.clear();
1188+
resetSelection();
1189+
tool.drawExistingAnnotations(globals.currentAnnotationsOfSelectedType);
1190+
displayExistingAnnotations(gCurrentAnnotations);
1191+
}
11791192
} catch (e) {
11801193
console.log(e);
11811194
}
@@ -1191,9 +1204,15 @@ function calculateImageScale() {
11911204
$('#next_button').click(async function (event) {
11921205
try {
11931206
let annotation = getValidAnnotation(true);
1194-
await createAnnotation(annotation);
1195-
let imageId = await loadAdjacentImage(1);
1196-
await changeImage(imageId, annotation);
1207+
if (await createAnnotation(annotation)) {
1208+
let imageId = await loadAdjacentImage(1);
1209+
await changeImage(imageId, annotation);
1210+
} else {
1211+
tool.clear();
1212+
resetSelection();
1213+
tool.drawExistingAnnotations(globals.currentAnnotationsOfSelectedType);
1214+
displayExistingAnnotations(gCurrentAnnotations);
1215+
}
11971216
} catch (e) {
11981217
console.log(e);
11991218
}

0 commit comments

Comments
 (0)