Skip to content
Snippets Groups Projects
Commit c377c881 authored by aeschylus's avatar aeschylus Committed by GitHub
Browse files

Merge pull request #1494 from glenrobson/mirador214-sas-fixes

Mirador214 sas fixes
parents 8637c136 bae2a664
Branches
Tags
No related merge requests found
...@@ -109,6 +109,8 @@ ...@@ -109,6 +109,8 @@
if (shapeArray.length > 0) { if (shapeArray.length > 0) {
_this.svgOverlay.restoreLastView(shapeArray); _this.svgOverlay.restoreLastView(shapeArray);
_this.annotationsToShapesMap[annotation['@id']] = shapeArray; _this.annotationsToShapesMap[annotation['@id']] = shapeArray;
} else {
console.log("ERROR couldn't find a strategy for " + annotation["@id"]);
} }
} catch(e) { } catch(e) {
console.log('ERROR OsdRegionDrawTool#render anno:', annotation, 'error:', e); console.log('ERROR OsdRegionDrawTool#render anno:', annotation, 'error:', e);
......
/* /*
* Edited version of https://github.com/IIIF/mirador/blob/9e3c6bbb894e044d01ad51aae1b70309939de5a9/js/src/annotations/catchEndpoint.js * Edited version of https://github.com/IIIF/mirador/blob/9e3c6bbb894e044d01ad51aae1b70309939de5a9/js/src/annotations/catchEndpoint.js
* This module tries to store the annotation as is in a RDF store but some fiddeling is required. Fidles are: * This module tries to store the annotation as is in a RDF store but some fiddeling is required.
* * Fidles are:
* - delete annotation fails if id has a / in it so have to send sanatised ids to mirador * - delete annotation fails if id has a / in it so have to send sanatised ids to mirador
* - mirador requires an endpoint variable in the annotation pointing to this class. * - mirador requires an endpoint variable in the annotation pointing to this class.
* *
...@@ -15,9 +15,6 @@ ...@@ -15,9 +15,6 @@
* create(oaAnnotation, returnSuccess, returnError) * create(oaAnnotation, returnSuccess, returnError)
* update(oaAnnotation, returnSuccess, returnError) * update(oaAnnotation, returnSuccess, returnError)
* deleteAnnotation(annotationID, returnSuccess, returnError) (delete is a reserved word) * deleteAnnotation(annotationID, returnSuccess, returnError) (delete is a reserved word)
* TODO:
* There is a bug in that if you create an annotation and then delete it (without moving pages) then click either the write annotation button
* or try to create a new annotation the deleted annotation re-appears. Changing pages fixes the issue as the annoation is delete from the annotation store
* *
*/ */
(function ($){ (function ($){
...@@ -30,8 +27,10 @@ ...@@ -30,8 +27,10 @@
uri: null, uri: null,
url: options.url, url: options.url,
dfd: null, dfd: null,
annotationsList: [], //OA list for Mirador use // OA list for Mirador use
idMapper: {} // internal list for module use to map id to URI annotationsList: [],
// internal list for module use to map id to URI
idMapper: {}
}, options); }, options);
this.init(); this.init();
...@@ -60,125 +59,155 @@ ...@@ -60,125 +59,155 @@
this.annotationsList = []; // clear out current list this.annotationsList = []; // clear out current list
jQuery.ajax({ jQuery.ajax({
url: _this.url + "/search", // this.prefix+ url: _this.url + '/search', // this.prefix+
cache: false, cache: false,
type: 'GET', type: 'GET',
dataType: 'json', dataType: 'json',
headers: { headers: {
//"x-annotator-auth-token": this.token // 'x-annotator-auth-token': this.token
}, },
data: { data: {
uri: options.uri, uri: options.uri,
APIKey: _this.APIKey, APIKey: _this.APIKey,
media: "image", media: 'image',
limit: 10000 limit: 10000
}, },
contentType: "application/json; charset=utf-8", contentType: 'application/json; charset=utf-8',
success: function(data) { success: function(data) {
if (typeof successCallback === "function") {
successCallback(data);
} else {
_this.annotationsList = data; // gmr _this.annotationsList = data; // gmr
jQuery.each(_this.annotationsList, function(index, value) { jQuery.each(_this.annotationsList, function(index, value) {
value.fullId = value["@id"]; // Swap out URI of anno to shorter ID
value["@id"] = $.genUUID(); value.fullId = value['@id'];
_this.idMapper[value["@id"]] = value.fullId; value['@id'] = $.genUUID();
_this.idMapper[value['@id']] = value.fullId;
value.endpoint = _this; value.endpoint = _this;
// Ensure on is an array
_this.fixOn(value);
}); });
_this.dfd.resolve(false); if (typeof successCallback === 'function') {
successCallback(data);
} else {
_this.dfd.resolve(true);
} }
}, },
error: function() { error: function(xhr, statusText, err) {
if (typeof errorCallback === "function") { if (typeof errorCallback === 'function') {
errorCallback(); errorCallback();
} else { } else {
console.log("The request for annotations has caused an error for endpoint: "+ options.uri); _this.dfd.reject();
console.log('The request for annotations has caused an error for endpoint: ' + options.uri + ' due to ' + statusText);
} }
} }
}); });
}, },
fixOn: function (annotation) {
var oldOn;
if (annotation && annotation.on && !jQuery.isArray(annotation.on) && annotation.on.selector && annotation.on.selector.default) {
oldOn = annotation.on;
annotation.on = [oldOn];
}
},
deleteAnnotation: function (annotationID, returnSuccess, returnError) { deleteAnnotation: function (annotationID, returnSuccess, returnError) {
var _this = this; var _this = this;
jQuery.ajax({ jQuery.ajax({
url: _this.url + "/destroy?uri=" + encodeURIComponent(_this.idMapper[annotationID]) + "&APIKey=" + _this.APIKey, // this.prefix+ url: _this.url + '/destroy?uri=' + encodeURIComponent(_this.idMapper[annotationID]) + '&APIKey=' + _this.APIKey, // this.prefix+
type: 'DELETE', type: 'DELETE',
dataType: 'json', dataType: 'json',
headers: { headers: {
//"x-annotator-auth-token": this.token // 'x-annotator-auth-token': this.token
}, },
data: { data: {
uri: annotationID, uri: annotationID,
}, },
contentType: "application/json; charset=utf-8", contentType: 'application/json; charset=utf-8',
success: function(data) { success: function(data) {
if (typeof returnSuccess === 'function') {
returnSuccess(); returnSuccess();
}
}, },
error: function() { error: function(xhr, statusText, err) {
if (typeof returnError === 'function') {
returnError(); returnError();
} else {
console.log('Failed to delete annotation ' + annotationID + ' due to ' + statusText);
}
} }
}); });
}, },
update: function (oaAnnotation, returnSuccess, returnError) { update: function (oaAnnotation, returnSuccess, returnError) {
var annotation = oaAnnotation, var annotation = oaAnnotation;
_this = this; var _this = this;
// slashes don't work in JQuery.find which is used for delete // slashes don't work in JQuery.find which is used for delete
// so need to switch http:// id to full id and back again for delete. // so need to switch http:// id to full id and back again for delete.
shortId = annotation["@id"]; var shortId = annotation['@id'];
annotation["@id"] = annotation.fullId; var annotationID = annotation.fullId;// annotation['@id'];
annotationID = annotation.fullId;//annotation["@id"]; annotation['@id'] = annotation.fullId;
delete annotation.fullId; delete annotation.fullId;
delete annotation.endpoint; delete annotation.endpoint;
jQuery.ajax({ jQuery.ajax({
url: _this.url + "/update/"+encodeURIComponent(annotationID) + "?APIKey=" + _this.APIKey, //this.prefix+ url: _this.url + '/update/' + encodeURIComponent(annotationID) + '?APIKey=' + _this.APIKey, // this.prefix+
type: 'POST', type: 'POST',
dataType: 'json', dataType: 'json',
headers: { headers: {
//"x-annotator-auth-token": this.token // 'x-annotator-auth-token': this.token
}, },
data: JSON.stringify(annotation), data: JSON.stringify(annotation),
contentType: "application/json; charset=utf-8", contentType: 'application/json; charset=utf-8',
success: function(data) { success: function(data) {
/* this returned data doesn't seem to be used anywhere */ _this.fixOn(data);
returnSuccess(); if (typeof returnSuccess === 'function') {
returnSuccess(data);
}
}, },
error: function() { error: function(xhr, statusText, err) {
if (typeof returnError === 'function') {
returnError(); returnError();
} else {
console.log('Failed to update annotation: ' + oaAnnotation['@id'] + ' due to ' + statusText);
}
} }
}); });
// this is what updates the viewer // this is what updates the viewer
annotation.endpoint = _this; annotation.endpoint = _this;
annotation.fullId = annotation["@id"]; annotation.fullId = annotation['@id'];
annotation["@id"] = shortId; annotation['@id'] = shortId;
}, },
create: function (oaAnnotation, returnSuccess, returnError) { create: function (oaAnnotation, returnSuccess, returnError) {
var annotation = oaAnnotation, var annotation = oaAnnotation;
_this = this; var _this = this;
jQuery.ajax({ jQuery.ajax({
url: _this.url + "/create?APIKey=" + _this.APIKey, //this.prefix+ url: _this.url + '/create?APIKey=' + _this.APIKey, // this.prefix+
type: 'POST', type: 'POST',
dataType: 'json', dataType: 'json',
headers: { headers: {
//"x-annotator-auth-token": this.token // 'x-annotator-auth-token': this.token
}, },
data: JSON.stringify(annotation), data: JSON.stringify(annotation),
contentType: "application/json; charset=utf-8", contentType: 'application/json; charset=utf-8',
success: function(data) { success: function(data) {
data.fullId = data["@id"]; data.fullId = data['@id'];
data["@id"] = $.genUUID(); data['@id'] = $.genUUID();
data.endpoint = _this; data.endpoint = _this;
_this.idMapper[data["@id"]] = data.fullId; _this.idMapper[data['@id']] = data.fullId;
_this.fixOn(data);
if (typeof returnSuccess === 'function') {
returnSuccess(data); returnSuccess(data);
}
}, },
error: function() { error: function(xhr, statusText, err) {
if (typeof returnError === 'function') {
returnError(); returnError();
} else {
console.log('Failed to create annotation: ' + oaAnnotation['@id'] + ' due to ' + statusText);
}
} }
}); });
}, },
......
...@@ -75,7 +75,7 @@ describe('SimpleASEndpoint', function() { ...@@ -75,7 +75,7 @@ describe('SimpleASEndpoint', function() {
subject.search({uri: "http://sas.example.net"}); subject.search({uri: "http://sas.example.net"});
expect(successCallback).not.toHaveBeenCalled(); expect(successCallback).not.toHaveBeenCalled();
expect(errorCallback).not.toHaveBeenCalled(); expect(errorCallback).not.toHaveBeenCalled();
expect(console.log).toHaveBeenCalledWith("The request for annotations has caused an error for endpoint: http://sas.example.net"); expect(console.log).toHaveBeenCalledWith("The request for annotations has caused an error for endpoint: http://sas.example.net due to undefined");
}); });
it('should run callback on failure if provided', function() { it('should run callback on failure if provided', function() {
ajaxSuccess = false; ajaxSuccess = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment