Skip to content
Draft
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
86 changes: 13 additions & 73 deletions app/api/AnnotationAPI.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,4 @@
export default class AnnotationAPI {
/* ------------ BASIC ANNOTATION CRUD (USER/PROJECT AGNOSTIC)--------------------*/

static saveAnnotation = (annotation, callback) => {
let url = _config.ANNOTATION_API_BASE + "/annotation";
let method = "POST";
if (annotation.id) {
url += "/" + annotation.id;
method = "PUT";
}
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
if (callback) {
callback(JSON.parse(xhr.responseText));
}
} else {
if (callback) {
callback(null);
}
}
}
};
xhr.open(method, url);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify(annotation));
};

static getAnnotation = (annotationId, callback) => {
if (annotationId) {
const url = _config.ANNOTATION_API_BASE + "/annotation/" + annotationId;
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
callback(JSON.parse(xhr.responseText));
} else {
callback(null);
}
}
};
xhr.open("GET", url);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send();
}
};

//TODO remove and user deleteUserAnnotation instead
static deleteAnnotation = (annotation, callback) => {
if (annotation.id) {
if (annotation.motivation === "bookmarking") {
alert("will not delete a bookmark group annotation!");
return;
}
const url = _config.ANNOTATION_API_BASE + "/annotation/" + annotation.id;
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
callback(JSON.parse(xhr.responseText), annotation);
} else {
callback(null);
}
}
};
xhr.open("DELETE", url);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send();
}
};

/* ------------ ANNOTATION SEARCH --------------------------------------*/

static getFilteredAnnotations = (
Expand Down Expand Up @@ -202,9 +131,20 @@ export default class AnnotationAPI {

/* ------------ DELETE USER ANNOTATIONS (PROJECT AGNOSTIC)--------------------*/

static deleteUserAnnotations = (userId, deletionList, callback) => {
static deleteUserAnnotations = (
projectId,
userId,
deletionList,
callback
) => {
console.debug("DELETING USER ANNOTATIONS", deletionList);
const url =
_config.ANNOTATION_API_BASE + "/user/" + userId + "/annotations";
_config.ANNOTATION_API_BASE +
"/user/" +
userId +
"/project/" +
projectId +
"/annotations";
const params = {
toDelete: deletionList,
};
Expand Down
3 changes: 3 additions & 0 deletions app/workspace/projects/ProjectViewWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const ProjectViewWrapper = ({
if (!proj) {
proj = project;
}
if (!userId) {
userId = user ? user.id : undefined;
}
AnnotationAPI.getAnnotationCounts(userId, proj.id, (counts) => {
if (counts) {
SessionStorageHandler.set(KEYS.bookmarkCount, counts.bookmarkCount);
Expand Down
1 change: 1 addition & 0 deletions app/workspace/projects/annotation/AnnotationTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class AnnotationTable extends React.PureComponent {

//now delete all the annotations with a single call to the annotation API
AnnotationAPI.deleteUserAnnotations(
this.props.project.id,
this.props.user.id,
deletionList,
(success) => {
Expand Down
1 change: 1 addition & 0 deletions app/workspace/projects/bookmark/BookmarkTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ class BookmarkTable extends React.PureComponent {

//now delete the whole selection in a single call to the API
AnnotationAPI.deleteUserAnnotations(
this.props.project.id,
this.props.user.id,
deletionList,
(success) => {
Expand Down