Skip to content

Commit 86a1bf8

Browse files
authored
Merge pull request #2 from Submitty/multiple-graders
Multiple graders
2 parents 5b58611 + 0333b74 commit 86a1bf8

20 files changed

+166
-119
lines changed

dist/pdf-annotate.js

Lines changed: 89 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pdf-annotate.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pdf-annotate.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pdf-annotate.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PDFJSAnnotate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default {
7878
* @param {String} pageNumber The page number
7979
* @return {Promise}
8080
*/
81-
getAnnotations(documentId, pageNumber) {
81+
getAnnotations(documentId, userId, pageNumber) {
8282
return this.getStoreAdapter().getAnnotations(...arguments);
8383
},
8484

src/UI/arrow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ function handleDocumentMousedown(e) {
3333
}
3434

3535
let svg = findSVGContainer(target);
36-
let { documentId } = getMetadata(svg);
36+
let { documentId, userId } = getMetadata(svg);
3737
let annotationId = target.getAttribute('data-pdf-annotate-id');
3838

3939
let event = e;
40-
PDFJSAnnotate.getStoreAdapter().getAnnotation(documentId, annotationId).then((annotation) => {
40+
PDFJSAnnotate.getStoreAdapter().getAnnotation(documentId, userId, annotationId).then((annotation) => {
4141
if (annotation) {
4242
path = null;
4343
lines = [];

src/UI/circle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ function saveCircle(svg, type, pt, radius, color) {
5959
r: radius
6060
};
6161

62-
let { documentId, pageNumber } = getMetadata(svg);
62+
let { documentId, userId, pageNumber } = getMetadata(svg);
6363

6464
// Add the annotation
65-
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
65+
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, userId, pageNumber, annotation)
6666
.then((annotation) => {
6767
appendChild(svg, annotation);
6868
});

src/UI/edit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ function handleDocumentMouseup(e) {
225225
let target = document.querySelectorAll(`[data-pdf-annotate-id="${annotationId}"]`);
226226
let type = target[0].getAttribute('data-pdf-annotate-type');
227227
let svg = overlay.parentNode.querySelector(config.annotationSvgQuery());
228-
let { documentId } = getMetadata(svg);
228+
let { documentId, userId } = getMetadata(svg);
229229

230230
overlay.querySelector('a').style.display = '';
231231

232-
PDFJSAnnotate.getStoreAdapter().getAnnotation(documentId, annotationId).then((annotation) => {
232+
PDFJSAnnotate.getStoreAdapter().getAnnotation(documentId, userId, annotationId).then((annotation) => {
233233
let attribX = 'x';
234234
let attribY = 'y';
235235
if (['circle', 'fillcircle', 'emptycircle'].indexOf(type) > -1) {

src/UI/eraser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function handleDocumentMouseMove(e){
1919
let target = findAnnotationAtPoint(e.clientX, e.clientY);
2020
if(target){
2121
console.log(target);
22-
let annotationId = target.getAttribute('data-pdf-annotate-id');
22+
// let annotationId = target.getAttribute('data-pdf-annotate-id');
2323
// let nodes = document.querySelectorAll(`[data-pdf-annotate-id="${annotationId}"]`);
2424
// let svg = overlay.parentNode.querySelector(config.annotationSvgQuery());
2525
// let { documentId } = getMetadata(svg);

src/UI/page.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function createPage(pageNumber) {
4848
export function renderPage(pageNumber, renderOptions) {
4949
let {
5050
documentId,
51+
userId,
5152
pdfDocument,
5253
scale,
5354
rotate
@@ -56,7 +57,7 @@ export function renderPage(pageNumber, renderOptions) {
5657
// Load the page and annotations
5758
return Promise.all([
5859
pdfDocument.getPage(pageNumber),
59-
PDFJSAnnotate.getAnnotations(documentId, pageNumber)
60+
PDFJSAnnotate.getAnnotations(documentId, userId, pageNumber)
6061
]).then(([pdfPage, annotations]) => {
6162
let page = document.getElementById(`pageContainer${pageNumber}`);
6263
let svg = page.querySelector(config.annotationClassQuery());

src/UI/pen.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ function saveToStorage(x, y){
4141
_candraw = false;
4242
let svg;
4343
if (lines.length > 1 && (svg = findSVGAtPoint(x, y))) {
44-
let { documentId, pageNumber } = getMetadata(svg);
45-
46-
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, {
44+
let { documentId, userId, pageNumber } = getMetadata(svg);
45+
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, userId, pageNumber, {
4746
type: 'drawing',
4847
width: _penSize,
4948
color: _penColor,

src/UI/point.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function savePoint() {
7070
}
7171

7272
let rect = svg.getBoundingClientRect();
73-
let { documentId, pageNumber } = getMetadata(svg);
73+
let { documentId, userId, pageNumber } = getMetadata(svg);
7474
let annotation = Object.assign({
7575
type: 'point'
7676
}, scaleDown(svg, {
@@ -79,7 +79,7 @@ function savePoint() {
7979
})
8080
);
8181

82-
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
82+
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, userId, pageNumber, annotation)
8383
.then((annotation) => {
8484
PDFJSAnnotate.getStoreAdapter().addComment(
8585
documentId,

src/UI/rect.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ function saveRect(type, rects, color) {
195195
annotation.height = rect.height;
196196
}
197197

198-
let { documentId, pageNumber } = getMetadata(svg);
198+
let { documentId, userId, pageNumber } = getMetadata(svg);
199199

200200
// Add the annotation
201-
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
201+
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, userId, pageNumber, annotation)
202202
.then((annotation) => {
203203
appendChild(svg, annotation);
204204
});

src/UI/text.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function saveText() {
7171
return;
7272
}
7373
let height = _textSize;
74-
let { documentId, pageNumber, viewport } = getMetadata(svg);
74+
let { documentId, userId, pageNumber, viewport } = getMetadata(svg);
7575
let scale = 1 / viewport.scale;
7676
let rect = svg.getBoundingClientRect();
7777
let pt = convertToSvgPoint([
@@ -87,7 +87,7 @@ function saveText() {
8787
rotation: -viewport.rotation
8888
}
8989

90-
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
90+
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, userId, pageNumber, annotation)
9191
.then((annotation) => {
9292
appendChild(svg, annotation);
9393
});

src/UI/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ export function enableUserSelect() {
264264
export function getMetadata(svg) {
265265
return {
266266
documentId: svg.getAttribute('data-pdf-annotate-document'),
267+
userId: svg.getAttribute('data-pdf-annotate-user'),
267268
pageNumber: parseInt(svg.getAttribute('data-pdf-annotate-page'), 10),
268269
viewport: JSON.parse(svg.getAttribute('data-pdf-annotate-viewport'))
269270
};

src/a11y/initEventHandlers.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import PDFJSAnnotate from '../PDFJSAnnotate';
99
* Initialize the event handlers for keeping screen reader hints synced with data
1010
*/
1111
export default function initEventHandlers() {
12-
addEventListener('annotation:add', (documentId, pageNumber, annotation) => {
13-
reorderAnnotationsByType(documentId, pageNumber, annotation.type);
12+
addEventListener('annotation:add', (documentId, userId, pageNumber, annotation) => {
13+
reorderAnnotationsByType(documentId, userId, pageNumber, annotation.type);
1414
});
15-
addEventListener('annotation:edit', (documentId, annotationId, annotation) => {
16-
reorderAnnotationsByType(documentId, annotation.page, annotation.type);
15+
addEventListener('annotation:edit', (documentId, userId, annotationId, annotation) => {
16+
reorderAnnotationsByType(documentId, userId, annotation.page, annotation.type);
1717
});
1818
addEventListener('annotation:delete', removeAnnotation);
1919
addEventListener('comment:add', insertComment);
@@ -24,11 +24,12 @@ export default function initEventHandlers() {
2424
* Reorder the annotation numbers by annotation type
2525
*
2626
* @param {String} documentId The ID of the document
27+
* @param {String} userId The ID of the user
2728
* @param {Number} pageNumber The page number of the annotations
2829
* @param {Strig} type The annotation type
2930
*/
30-
function reorderAnnotationsByType(documentId, pageNumber, type) {
31-
PDFJSAnnotate.getStoreAdapter().getAnnotations(documentId, pageNumber)
31+
function reorderAnnotationsByType(documentId, userId, pageNumber, type) {
32+
PDFJSAnnotate.getStoreAdapter().getAnnotations(documentId, userId, pageNumber)
3233
.then((annotations) => {
3334
return annotations.annotations.filter((a) => {
3435
return a.type === type;

src/adapter/LocalStoreAdapter.js

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,71 @@ import StoreAdapter from './StoreAdapter';
66
export default class LocalStoreAdapter extends StoreAdapter {
77
constructor() {
88
super({
9-
getAnnotations(documentId, pageNumber) {
9+
getAnnotations(documentId, userId, 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

1515
resolve({
1616
documentId,
17+
userId,
1718
pageNumber,
1819
annotations
1920
});
2021
});
2122
},
2223

23-
getAnnotation(documentId, annotationId) {
24-
return Promise.resolve(getAnnotations(documentId)[findAnnotation(documentId, annotationId)]);
24+
getAnnotation(documentId, userId, annotationId) {
25+
return Promise.resolve(getAnnotations(documentId, userId)[findAnnotation(documentId, userId, annotationId)]);
2526
},
2627

27-
addAnnotation(documentId, pageNumber, annotation) {
28+
addAnnotation(documentId, userId, pageNumber, annotation) {
2829
return new Promise((resolve, reject) => {
2930
annotation.class = 'Annotation';
3031
annotation.uuid = uuid();
3132
annotation.page = pageNumber;
3233

33-
let annotations = getAnnotations(documentId);
34+
let annotations = getAnnotations(documentId, userId);
3435
annotations.push(annotation);
35-
updateAnnotations(documentId, annotations);
36+
updateAnnotations(documentId, userId, annotations);
3637

3738
resolve(annotation);
3839
});
3940
},
4041

41-
editAnnotation(documentId, annotationId, annotation) {
42+
editAnnotation(documentId, userId, annotationId, annotation) {
4243
return new Promise((resolve, reject) => {
43-
let annotations = getAnnotations(documentId);
44-
annotations[findAnnotation(documentId, annotationId)] = annotation;
45-
updateAnnotations(documentId, annotations);
44+
let annotations = getAnnotations(documentId, userId);
45+
annotations[findAnnotation(documentId, userId, annotationId)] = annotation;
46+
updateAnnotations(documentId, userId, annotations);
4647

4748
resolve(annotation);
4849
});
4950
},
5051

51-
deleteAnnotation(documentId, annotationId) {
52+
deleteAnnotation(documentId, userId, annotationId) {
5253
return new Promise((resolve, reject) => {
53-
let index = findAnnotation(documentId, annotationId);
54+
let index = findAnnotation(documentId, userId, annotationId);
5455
if (index > -1) {
55-
let annotations = getAnnotations(documentId);
56+
let annotations = getAnnotations(documentId, userId);
5657
annotations.splice(index, 1);
57-
updateAnnotations(documentId, annotations);
58+
updateAnnotations(documentId, userId, annotations);
5859
}
5960

6061
resolve(true);
6162
});
6263
},
6364

64-
getComments(documentId, annotationId) {
65+
getComments(documentId, userId, annotationId) {
6566
return new Promise((resolve, reject) => {
66-
resolve(getAnnotations(documentId).filter((i) => {
67+
resolve(getAnnotations(documentId, userId).filter((i) => {
6768
return i.class === 'Comment' && i.annotation === annotationId;
6869
}));
6970
});
7071
},
7172

72-
addComment(documentId, annotationId, content) {
73+
addComment(documentId, userId, annotationId, content) {
7374
return new Promise((resolve, reject) => {
7475
let comment = {
7576
class: 'Comment',
@@ -78,19 +79,19 @@ export default class LocalStoreAdapter extends StoreAdapter {
7879
content: content
7980
};
8081

81-
let annotations = getAnnotations(documentId);
82+
let annotations = getAnnotations(documentId, userId);
8283
annotations.push(comment);
83-
updateAnnotations(documentId, annotations);
84+
updateAnnotations(documentId, userId, annotations);
8485

8586
resolve(comment);
8687
});
8788
},
8889

89-
deleteComment(documentId, commentId) {
90+
deleteComment(documentId, userId, commentId) {
9091
return new Promise((resolve, reject) => {
91-
getAnnotations(documentId);
92+
getAnnotations(documentId, userId);
9293
let index = -1;
93-
let annotations = getAnnotations(documentId);
94+
let annotations = getAnnotations(documentId, userId);
9495
for (let i=0, l=annotations.length; i<l; i++) {
9596
if (annotations[i].uuid === commentId) {
9697
index = i;
@@ -100,7 +101,7 @@ export default class LocalStoreAdapter extends StoreAdapter {
100101

101102
if (index > -1) {
102103
annotations.splice(index, 1);
103-
updateAnnotations(documentId, annotations);
104+
updateAnnotations(documentId, userId, annotations);
104105
}
105106

106107
resolve(true);
@@ -110,17 +111,23 @@ export default class LocalStoreAdapter extends StoreAdapter {
110111
}
111112
}
112113

113-
function getAnnotations(documentId) {
114-
return JSON.parse(localStorage.getItem(`${documentId}/annotations`)) || [];
114+
function getAnnotations(documentId, userId) {
115+
let all_annotations = [];
116+
for(let i = 0 ; i < localStorage.length; i++){
117+
if(localStorage.key(i).includes('annotations')){
118+
all_annotations.push(...JSON.parse(localStorage.getItem(localStorage.key(i))));
119+
}
120+
}
121+
return all_annotations;
115122
}
116123

117-
function updateAnnotations(documentId, annotations) {
118-
localStorage.setItem(`${documentId}/annotations`, JSON.stringify(annotations));
124+
function updateAnnotations(documentId, userId, annotations) {
125+
localStorage.setItem(`${documentId}/${userId}/annotations`, JSON.stringify(annotations));
119126
}
120127

121-
function findAnnotation(documentId, annotationId) {
128+
function findAnnotation(documentId, userId, annotationId) {
122129
let index = -1;
123-
let annotations = getAnnotations(documentId);
130+
let annotations = getAnnotations(documentId, userId);
124131
for (let i=0, l=annotations.length; i<l; i++) {
125132
if (annotations[i].uuid === annotationId) {
126133
index = i;

src/adapter/StoreAdapter.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ export default class StoreAdapter {
2222
* Get all the annotations for a given document and page number.
2323
*
2424
* @param {String} documentId The ID for the document the annotations belong to
25+
* @param {String} userId The user makeing changes to this document
2526
* @param {Number} pageNumber The number of the page the annotations belong to
2627
* @return {Promise}
2728
*/
28-
__getAnnotations(documentId, pageNumber) { abstractFunction('getAnnotations'); }
29+
__getAnnotations(documentId, userId, pageNumber) { abstractFunction('getAnnotations'); }
2930
get getAnnotations() { return this.__getAnnotations; }
3031
set getAnnotations(fn) {
31-
this.__getAnnotations = function getAnnotations(documentId, pageNumber) {
32+
this.__getAnnotations = function getAnnotations(documentId, userId, pageNumber) {
3233
return fn(...arguments).then((annotations) => {
3334
// TODO may be best to have this happen on the server
3435
if (annotations.annotations) {
@@ -58,12 +59,12 @@ export default class StoreAdapter {
5859
* @param {Object} annotation The definition for the new annotation
5960
* @return {Promise}
6061
*/
61-
__addAnnotation(documentId, pageNumber, annotation) { abstractFunction('addAnnotation'); }
62+
__addAnnotation(documentId, userId, pageNumber, annotation) { abstractFunction('addAnnotation'); }
6263
get addAnnotation() { return this.__addAnnotation; }
6364
set addAnnotation(fn) {
64-
this.__addAnnotation = function addAnnotation(documentId, pageNumber, annotation) {
65+
this.__addAnnotation = function addAnnotation(documentId, userId, pageNumber, annotation) {
6566
return fn(...arguments).then((annotation) => {
66-
fireEvent('annotation:add', documentId, pageNumber, annotation);
67+
fireEvent('annotation:add', documentId, userId, pageNumber, annotation);
6768
return annotation;
6869
});
6970
};

src/render/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function render(svg, viewport, data) {
2828
}
2929

3030
svg.setAttribute('data-pdf-annotate-document', data.documentId);
31+
svg.setAttribute('data-pdf-annotate-user', data.userId);
3132
svg.setAttribute('data-pdf-annotate-page', data.pageNumber);
3233

3334
// Make sure annotations is an array

web/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const documentId = 'example.pdf';
77
let PAGE_HEIGHT;
88
let RENDER_OPTIONS = {
99
documentId,
10+
userId: 'aphacker',
1011
pdfDocument: null,
1112
scale: parseFloat(localStorage.getItem(`${documentId}/scale`), 10) || 1.33,
1213
rotate: parseInt(localStorage.getItem(`${documentId}/rotate`), 10) || 0
@@ -383,7 +384,7 @@ render();
383384
document.querySelector(`div#pageContainer${i+1} svg.annotationLayer`).innerHTML = '';
384385
}
385386

386-
localStorage.removeItem(`${RENDER_OPTIONS.documentId}/annotations`);
387+
localStorage.removeItem(`${RENDER_OPTIONS.documentId}/${RENDER_OPTIONS.userId}/annotations`);
387388
}
388389
}
389390
document.querySelector('a.clear').addEventListener('click', handleClearClick);

0 commit comments

Comments
 (0)