Skip to content

Commit d9457d9

Browse files
author
Victor Nazzaro
committed
changed multiple graders by passing in grader into localstrore adaptor
1 parent c0fe847 commit d9457d9

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/adapter/LocalStoreAdapter.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import StoreAdapter from './StoreAdapter';
44
// StoreAdapter for working with localStorage
55
// This is ideal for testing, examples, and prototyping
66
export default class LocalStoreAdapter extends StoreAdapter {
7-
constructor() {
7+
constructor(userId = "user") {
88
super({
99
getAnnotations(documentId, pageNumber) {
1010
return new Promise((resolve, reject) => {
11-
let annotations = getAnnotations(documentId).filter((i) => {
11+
let annotations = getAnnotations(documentId, userId).filter((i) => {
1212
return i.page === pageNumber && i.class === 'Annotation';
1313
});
1414

@@ -21,7 +21,7 @@ export default class LocalStoreAdapter extends StoreAdapter {
2121
},
2222

2323
getAnnotation(documentId, annotationId) {
24-
return Promise.resolve(getAnnotations(documentId)[findAnnotation(documentId, annotationId)]);
24+
return Promise.resolve(getAnnotations(documentId, userId)[findAnnotation(documentId, annotationId)]);
2525
},
2626

2727
addAnnotation(documentId, pageNumber, annotation) {
@@ -30,19 +30,19 @@ export default class LocalStoreAdapter extends StoreAdapter {
3030
annotation.uuid = uuid();
3131
annotation.page = pageNumber;
3232

33-
let annotations = getAnnotations(documentId);
33+
let annotations = getAnnotations(documentId, userId);
3434
annotations.push(annotation);
35-
updateAnnotations(documentId, annotations);
35+
updateAnnotations(documentId, userId, annotations);
3636

3737
resolve(annotation);
3838
});
3939
},
4040

4141
editAnnotation(documentId, annotationId, annotation) {
4242
return new Promise((resolve, reject) => {
43-
let annotations = getAnnotations(documentId);
43+
let annotations = getAnnotations(documentId, userId);
4444
annotations[findAnnotation(documentId, annotationId)] = annotation;
45-
updateAnnotations(documentId, annotations);
45+
updateAnnotations(documentId, userId, annotations);
4646

4747
resolve(annotation);
4848
});
@@ -52,9 +52,9 @@ export default class LocalStoreAdapter extends StoreAdapter {
5252
return new Promise((resolve, reject) => {
5353
let index = findAnnotation(documentId, annotationId);
5454
if (index > -1) {
55-
let annotations = getAnnotations(documentId);
55+
let annotations = getAnnotations(documentId, userId);
5656
annotations.splice(index, 1);
57-
updateAnnotations(documentId, annotations);
57+
updateAnnotations(documentId, userId, annotations);
5858
}
5959

6060
resolve(true);
@@ -63,7 +63,7 @@ export default class LocalStoreAdapter extends StoreAdapter {
6363

6464
getComments(documentId, annotationId) {
6565
return new Promise((resolve, reject) => {
66-
resolve(getAnnotations(documentId).filter((i) => {
66+
resolve(getAnnotations(documentId, userId).filter((i) => {
6767
return i.class === 'Comment' && i.annotation === annotationId;
6868
}));
6969
});
@@ -78,19 +78,19 @@ export default class LocalStoreAdapter extends StoreAdapter {
7878
content: content
7979
};
8080

81-
let annotations = getAnnotations(documentId);
81+
let annotations = getAnnotations(documentId, userId);
8282
annotations.push(comment);
83-
updateAnnotations(documentId, annotations);
83+
updateAnnotations(documentId, userId, annotations);
8484

8585
resolve(comment);
8686
});
8787
},
8888

8989
deleteComment(documentId, commentId) {
9090
return new Promise((resolve, reject) => {
91-
getAnnotations(documentId);
91+
getAnnotations(documentId, userId);
9292
let index = -1;
93-
let annotations = getAnnotations(documentId);
93+
let annotations = getAnnotations(documentId, userId);
9494
for (let i=0, l=annotations.length; i<l; i++) {
9595
if (annotations[i].uuid === commentId) {
9696
index = i;
@@ -100,7 +100,7 @@ export default class LocalStoreAdapter extends StoreAdapter {
100100

101101
if (index > -1) {
102102
annotations.splice(index, 1);
103-
updateAnnotations(documentId, annotations);
103+
updateAnnotations(documentId, userId, annotations);
104104
}
105105

106106
resolve(true);
@@ -110,12 +110,12 @@ export default class LocalStoreAdapter extends StoreAdapter {
110110
}
111111
}
112112

113-
function getAnnotations(documentId) {
114-
return JSON.parse(localStorage.getItem(`${documentId}/annotations`)) || [];
113+
function getAnnotations(documentId, userId) {
114+
return JSON.parse(localStorage.getItem(`${documentId}/${userId}/annotations`)) || [];
115115
}
116116

117-
function updateAnnotations(documentId, annotations) {
118-
localStorage.setItem(`${documentId}/annotations`, JSON.stringify(annotations));
117+
function updateAnnotations(documentId, userId, annotations) {
118+
localStorage.setItem(`${documentId}/${userId}/annotations`, JSON.stringify(annotations));
119119
}
120120

121121
function findAnnotation(documentId, annotationId) {

web/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import initColorPicker from './shared/initColorPicker';
44

55
const { UI } = PDFJSAnnotate;
66
const documentId = 'example.pdf';
7+
const userId = 'instructor';
78
let PAGE_HEIGHT;
89
let RENDER_OPTIONS = {
910
documentId,
@@ -12,7 +13,7 @@ let RENDER_OPTIONS = {
1213
rotate: parseInt(localStorage.getItem(`${documentId}/rotate`), 10) || 0
1314
};
1415

15-
PDFJSAnnotate.setStoreAdapter(new PDFJSAnnotate.LocalStoreAdapter());
16+
PDFJSAnnotate.setStoreAdapter(new PDFJSAnnotate.LocalStoreAdapter(userId));
1617
PDFJS.workerSrc = './shared/pdf.worker.js';
1718

1819
// Render stuff

0 commit comments

Comments
 (0)