Skip to content

Commit

Permalink
better error handling when creating an annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
timonegk committed Apr 1, 2021
1 parent a0bce56 commit a7c23e0
Showing 1 changed file with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ function calculateImageScale() {
* If an annotation is currently edited, an update is triggered instead.
*
* @param annotation the annotation to be created, as returned by getValidAnnotation
* @return whether the annotation was successfully created
*/
async function createAnnotation(annotation) {

Expand All @@ -194,6 +195,8 @@ function calculateImageScale() {
editing = true;
}

let success = true;

$('.js_feedback').stop().addClass('hidden');
$('.annotate_button').prop('disabled', true);
try {
Expand All @@ -209,11 +212,13 @@ function calculateImageScale() {
if (data.detail === 'similar annotation exists.') {
displayFeedback($('#feedback_annotation_exists_deleted'));
$('#annotation_edit_button_' + gEditAnnotationId).parent().parent().fadeOut().remove();
success = false;
} else {
displayFeedback($('#feedback_annotation_updated'));
}
} else {
displayFeedback($('#feedback_annotation_exists'));
success = false;
}
} else if (response.status === 201) {
displayFeedback($('#feedback_annotation_created'));
Expand All @@ -227,9 +232,11 @@ function calculateImageScale() {
} catch (e) {
console.log(e);
displayFeedback($('#feedback_connection_error'));
success = false;
} finally {
$('.annotate_button').prop('disabled', false);
}
return success;
}

async function loadAnnotationTypeList() {
Expand Down Expand Up @@ -1173,9 +1180,15 @@ function calculateImageScale() {
$('#last_button').click(async function (event) {
try {
let annotation = getValidAnnotation(true);
await createAnnotation(annotation);
let imageId = await loadAdjacentImage(-1);
await changeImage(imageId, annotation);
if (await createAnnotation(annotation)) {
let imageId = await loadAdjacentImage(-1);
await changeImage(imageId, annotation);
} else {
tool.clear();
resetSelection();
tool.drawExistingAnnotations(globals.currentAnnotationsOfSelectedType);
displayExistingAnnotations(gCurrentAnnotations);
}
} catch (e) {
console.log(e);
}
Expand All @@ -1191,9 +1204,15 @@ function calculateImageScale() {
$('#next_button').click(async function (event) {
try {
let annotation = getValidAnnotation(true);
await createAnnotation(annotation);
let imageId = await loadAdjacentImage(1);
await changeImage(imageId, annotation);
if (await createAnnotation(annotation)) {
let imageId = await loadAdjacentImage(1);
await changeImage(imageId, annotation);
} else {
tool.clear();
resetSelection();
tool.drawExistingAnnotations(globals.currentAnnotationsOfSelectedType);
displayExistingAnnotations(gCurrentAnnotations);
}
} catch (e) {
console.log(e);
}
Expand Down

0 comments on commit a7c23e0

Please sign in to comment.