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

Metadata #110

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ globals = {
mouseDownY: undefined,
currentAnnotations: undefined,
allAnnotations: undefined,
allMetadata: undefined,
stdColor: '#CC4444',
mutColor: '#CC0000'
};
Expand All @@ -35,6 +36,7 @@ function calculateImageScale() {
const FEEDBACK_DISPLAY_TIME = 3000;
const ANNOTATE_URL = '/annotations/%s/';
const IMAGE_SET_URL = '/images/imageset/%s/';
const IMAGE_METADATA_DEL_URL = '/images/image/metadata/delete/';
const PRELOAD_BACKWARD = 2;
const PRELOAD_FORWARD = 5;
const STATIC_ROOT = '/static/';
Expand All @@ -51,6 +53,7 @@ function calculateImageScale() {
var gMousepos;
let gAnnotationType = -1;
let gAnnotationCache = {};
let gMetadataCache = {};
let gHighlightedAnnotation;

var gShiftDown;
Expand Down Expand Up @@ -259,7 +262,7 @@ function calculateImageScale() {
return e.annotation_type.id === gAnnotationType;
});
gAnnotationCache[gImageId] = globals.allAnnotations;

gMetadataCache[gImageId] = globals.allMetadata;
tool.drawExistingAnnotations(globals.currentAnnotations);

globals.editedAnnotationsId = undefined;
Expand Down Expand Up @@ -365,6 +368,53 @@ function calculateImageScale() {
});
}

function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

/**
* Display metadata on current page.
*
* @param annotations
*/
function displayImageMetadata(data, imageId) {
if (data != undefined) {
let table = $('#metadata > tbody');
table.empty();
let csrftoken = getCookie('csrftoken');
for (k in data) {
table.append(
'<tr>' +
'<td>' +
'<form id="del-metadata-' + k + '" action="' + IMAGE_METADATA_DEL_URL + imageId + '/" method="POST">' +
'<input type="hidden" name="csrfmiddlewaretoken" value="' + csrftoken + '">' +
'<input type="hidden" name="key" value="' + k + '"/>' +
'<button type="submit" class="btn btn-danger">' +
'<span class="glyphicon glyphicon-trash" aria-hidden="true" style="padding-right: 3px;"></span>' +
'</button>' +
'</form>' +
'</td>' +
'<td>' + k + '</td>' +
'<td>' + data[k] + '</td>' +
'</tr>'
);
}
}

}

/**
* Display existing annotations on current page.
*
Expand Down Expand Up @@ -881,6 +931,7 @@ function calculateImageScale() {
$('#annotation_type_id').val(gAnnotationType);

displayImage(imageId);
displayImageMetadata(gMetadataCache[imageId], imageId);
if (!$('#keep_selection').prop('checked')) {
$('#concealed').prop('checked', false);
$('#blurred').prop('checked', false);
Expand Down Expand Up @@ -1028,6 +1079,7 @@ function calculateImageScale() {
success: function(data) {
// save the current annotations to the cache
gAnnotationCache[imageId] = data.annotations;
gMetadataCache[imageId] = data.metadata;
console.log("Saving annotations for", imageId);
},
error: function() {
Expand Down Expand Up @@ -1100,6 +1152,12 @@ function calculateImageScale() {
delete gAnnotationCache[imageId];
}
}
for (var imageId in gMetadataCache) {
imageId = parseInt(imageId);
if (gMetadataCache[imageId] !== undefined && keep.indexOf(imageId) === -1) {
delete gMetadataCache[imageId];
}
}
}

/**
Expand Down
Loading