Skip to content

Commit

Permalink
execute annotation creation and loading of next image in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
timonegk committed Mar 30, 2021
1 parent e853c1f commit badf574
Showing 1 changed file with 54 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,11 @@ function calculateImageScale() {
}

/**
* Create an annotation using the form data from the current page.
* If an annotation is currently edited, an update is triggered instead.
*
* Check whether the current state allows to create an annotation (i.e. a valid selection was made)
* @param markForRestore if the annotation should be saved to be reused for the next image
* @return the valid vector or null
*/
async function createAnnotation(markForRestore) {
function getValidAnnotation(markForRestore) {
let annotationTypeId = parseInt($('#annotation_type_id').val());
let vector = null;

Expand Down Expand Up @@ -189,14 +188,26 @@ function calculateImageScale() {
globals.restoreSelectionNodeCount = node_count;
}

let action = 'create';
let body = {
let annotation = {
annotation_type_id: annotationTypeId,
image_id: gImageId,
vector: vector,
concealed: concealed,
blurred: blurred
};
return annotation;
}

/**
* Create an annotation using the form data from the current page.
* If an annotation is currently edited, an update is triggered instead.
*
* @param annotation the annotation to be created, as returned by getValidAnnotation
*/
async function createAnnotation(annotation) {

let action = 'create';
let body = annotation;
let editing = false;
if (gEditAnnotationId !== undefined) {
// edit instead of create
Expand Down Expand Up @@ -1165,40 +1176,59 @@ function calculateImageScale() {
$('#cancel_edit_button').click(function() {
resetSelection();
});
$('#save_button').click(function (event) {
$('#save_button').click(async function (event) {
event.preventDefault();
createAnnotation();
try {
let annotation = getValidAnnotation()
await createAnnotation(annotation);
} catch (e) {
console.log(e);
}
});
$('#reset_button').click(function() {
resetSelection();
});
$('#last_button').click(async function(event) {
await createAnnotation(true);
if (tool instanceof BoundingBoxes) {
tool.cancelSelection();
$('#last_button').click(async function (event) {
try {
let annotation = getValidAnnotation(true);
let annotationPromise = createAnnotation(annotation);
let imagePromise = loadImageList().then(r => {
if (tool instanceof BoundingBoxes) {
tool.cancelSelection();
}
return loadAdjacentImage(-1);
})
await Promise.all([annotationPromise, imagePromise]);
} catch (e) {
console.log(e);
}
await loadImageList();
await loadAdjacentImage(-1);
});
$('#back_button').click(async function(event) {
$('#back_button').click(async function (event) {
if (tool instanceof BoundingBoxes) {
tool.cancelSelection();
tool.cancelSelection();
}
await loadAdjacentImage(-1);
});
$('#skip_button').click(async function(event) {
$('#skip_button').click(async function (event) {
if (tool instanceof BoundingBoxes) {
tool.cancelSelection();
tool.cancelSelection();
}
await loadAdjacentImage(1)
});
$('#next_button').click(async function(event) {
await createAnnotation(true);
if (tool instanceof BoundingBoxes) {
tool.cancelSelection();
$('#next_button').click(async function (event) {
try {
let annotation = getValidAnnotation(true);
let annotationPromise = createAnnotation(annotation);
let imagePromise = loadImageList().then(r => {
if (tool instanceof BoundingBoxes) {
tool.cancelSelection();
}
return loadAdjacentImage(1);
})
await Promise.all([annotationPromise, imagePromise]);
} catch (e) {
console.log(e);
}
await loadImageList();
await loadAdjacentImage(1);
});
$('.js_feedback').mouseover(function() {
$(this).addClass('hidden');
Expand Down

0 comments on commit badf574

Please sign in to comment.