Skip to content
Snippets Groups Projects
Commit 252fc32d authored by Glen Robson's avatar Glen Robson
Browse files

Fixing layout in test issues

parent 400c58c5
Branches
Tags
No related merge requests found
/*
* 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
* - mirador requires an endpoint variable in the annotation pointing to this class.
*
......@@ -15,9 +15,6 @@
* create(oaAnnotation, returnSuccess, returnError)
* update(oaAnnotation, returnSuccess, returnError)
* 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 ($){
......@@ -30,8 +27,10 @@
uri: null,
url: options.url,
dfd: null,
annotationsList: [], //OA list for Mirador use
idMapper: {} // internal list for module use to map id to URI
// OA list for Mirador use
annotationsList: [],
// internal list for module use to map id to URI
idMapper: {}
}, options);
this.init();
......@@ -60,44 +59,44 @@
this.annotationsList = []; // clear out current list
jQuery.ajax({
url: _this.url + "/search", // this.prefix+
url: _this.url + '/search', // this.prefix+
cache: false,
type: 'GET',
dataType: 'json',
headers: {
//"x-annotator-auth-token": this.token
// 'x-annotator-auth-token': this.token
},
data: {
uri: options.uri,
APIKey: _this.APIKey,
media: "image",
media: 'image',
limit: 10000
},
contentType: "application/json; charset=utf-8",
contentType: 'application/json; charset=utf-8',
success: function(data) {
_this.annotationsList = data; // gmr
this.annotationsList = data; // gmr
jQuery.each(_this.annotationsList, function(index, value) {
// Swap out URI of anno to shorter ID
value.fullId = value["@id"];
value["@id"] = $.genUUID();
_this.idMapper[value["@id"]] = value.fullId;
value.fullId = value['@id'];
value['@id'] = $.genUUID();
_this.idMapper[value['@id']] = value.fullId;
value.endpoint = _this;
// Ensure on is an array
_this.fixOn(value);
});
if (typeof successCallback === "function") {
if (typeof successCallback === 'function') {
successCallback(data);
} else {
_this.dfd.resolve(true);
}
},
error: function(xhr, statusText, err) {
if (typeof errorCallback === "function") {
if (typeof errorCallback === 'function') {
errorCallback();
} else {
_this.dfd.reject();
console.log("The request for annotations has caused an error for endpoint: "+ options.uri + " due to " + statusText);
console.log('The request for annotations has caused an error for endpoint: ' + options.uri + ' due to ' + statusText);
}
}
......@@ -105,7 +104,8 @@
},
fixOn: function (annotation) {
if (annotation.on && !jQuery.isArray(annotation.on) && annotation.on.selector && annotation.on.selector.default) {
var oldOn;
if (annotation && annotation.on && !jQuery.isArray(annotation.on) && annotation.on.selector && annotation.on.selector.default) {
oldOn = annotation.on;
annotation.on = [oldOn];
}
......@@ -114,26 +114,26 @@
deleteAnnotation: function (annotationID, returnSuccess, returnError) {
var _this = this;
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',
dataType: 'json',
headers: {
//"x-annotator-auth-token": this.token
// 'x-annotator-auth-token': this.token
},
data: {
uri: annotationID,
},
contentType: "application/json; charset=utf-8",
contentType: 'application/json; charset=utf-8',
success: function(data) {
if (typeof returnSuccess === "function") {
if (typeof returnSuccess === 'function') {
returnSuccess();
}
},
error: function(xhr, statusText, err) {
if (typeof returnError === "function") {
if (typeof returnError === 'function') {
returnError();
} else {
console.log('Failed to delete annotation ' + annotationID + " due to " + statusText);
console.log('Failed to delete annotation ' + annotationID + ' due to ' + statusText);
}
}
......@@ -141,72 +141,72 @@
},
update: function (oaAnnotation, returnSuccess, returnError) {
var annotation = oaAnnotation,
_this = this;
var annotation = oaAnnotation;
var _this = this;
// 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.
shortId = annotation["@id"];
annotation["@id"] = annotation.fullId;
annotationID = annotation.fullId;//annotation["@id"];
var shortId = annotation['@id'];
var annotationID = annotation.fullId;// annotation['@id'];
annotation['@id'] = annotation.fullId;
delete annotation.fullId;
delete annotation.endpoint;
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',
dataType: 'json',
headers: {
//"x-annotator-auth-token": this.token
// 'x-annotator-auth-token': this.token
},
data: JSON.stringify(annotation),
contentType: "application/json; charset=utf-8",
contentType: 'application/json; charset=utf-8',
success: function(data) {
_this.fixOn(data);
if (typeof returnSuccess === "function") {
if (typeof returnSuccess === 'function') {
returnSuccess(data);
}
},
error: function(xhr, statusText, err) {
if (typeof returnError === "function") {
if (typeof returnError === 'function') {
returnError();
} else {
console.log('Failed to update annotation: ' + oaAnnotation["@id"] + " due to " + statusText);
console.log('Failed to update annotation: ' + oaAnnotation['@id'] + ' due to ' + statusText);
}
}
});
// this is what updates the viewer
annotation.endpoint = _this;
annotation.fullId = annotation["@id"];
annotation["@id"] = shortId;
annotation.fullId = annotation['@id'];
annotation['@id'] = shortId;
},
create: function (oaAnnotation, returnSuccess, returnError) {
var annotation = oaAnnotation,
_this = this;
var annotation = oaAnnotation;
var _this = this;
jQuery.ajax({
url: _this.url + "/create?APIKey=" + _this.APIKey, //this.prefix+
url: _this.url + '/create?APIKey=' + _this.APIKey, // this.prefix+
type: 'POST',
dataType: 'json',
headers: {
//"x-annotator-auth-token": this.token
// 'x-annotator-auth-token': this.token
},
data: JSON.stringify(annotation),
contentType: "application/json; charset=utf-8",
contentType: 'application/json; charset=utf-8',
success: function(data) {
data.fullId = data["@id"];
data["@id"] = $.genUUID();
data.fullId = data['@id'];
data['@id'] = $.genUUID();
data.endpoint = _this;
_this.idMapper[data["@id"]] = data.fullId;
_this.idMapper[data['@id']] = data.fullId;
_this.fixOn(data);
if (typeof returnSuccess === "function") {
if (typeof returnSuccess === 'function') {
returnSuccess(data);
}
},
error: function(xhr, statusText, err) {
if (typeof returnError === "function") {
if (typeof returnError === 'function') {
returnError();
} else {
console.log('Failed to create annotation: ' + oaAnnotation["@id"] + " due to " + statusText);
console.log('Failed to create annotation: ' + oaAnnotation['@id'] + ' due to ' + statusText);
}
}
});
......
......@@ -75,7 +75,7 @@ describe('SimpleASEndpoint', function() {
subject.search({uri: "http://sas.example.net"});
expect(successCallback).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() {
ajaxSuccess = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment