Skip to content

Commit e81fd6f

Browse files
authored
fix: User comments (#309)
* fix: User comments - Moved method to a new js file that only managers can use - Now users can also comment, depends on config settings of USERS_COMMENTS * Fixed unknown variable
1 parent a04bab5 commit e81fd6f

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

lms/static/checker.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function trackFinished(exerciseId, solutionId, element) {
2+
element.addEventListener('click', () => {
3+
const xhr = new XMLHttpRequest();
4+
xhr.open('POST', `/checked/${exerciseId}/${solutionId}`, true);
5+
xhr.setRequestHeader('Content-Type', 'application/json');
6+
xhr.responseType = 'json';
7+
xhr.onreadystatechange = () => {
8+
if (xhr.readyState === 4) {
9+
if (xhr.status === 200) {
10+
if (xhr.response.next !== null) {
11+
window.location.href = `/view/${xhr.response.next}`;
12+
} else {
13+
alert("Yay! That's it!");
14+
}
15+
} else {
16+
console.log(xhr.status);
17+
}
18+
}
19+
};
20+
21+
xhr.send(JSON.stringify({}));
22+
});
23+
}
24+
25+
window.addEventListener('lines-numbered', () => {
26+
trackFinished(window.exerciseId, window.solutionId, document.getElementById('save-check'));
27+
});

lms/static/comments.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ window.addEventListener('load', () => {
148148
const codeElementData = document.getElementById('code-view').dataset;
149149
window.solutionId = codeElementData.id;
150150
window.fileId = codeElementData.file;
151+
window.exerciseId = codeElementData.exercise;
151152
sessionStorage.setItem('role', codeElementData.role);
152153
sessionStorage.setItem('solver', codeElementData.solver);
153154
sessionStorage.setItem('allowedComment', codeElementData.allowedComment);

lms/static/grader.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
function trackFinished(exerciseId, solutionId, element) {
2-
element.addEventListener('click', () => {
3-
const xhr = new XMLHttpRequest();
4-
xhr.open('POST', `/checked/${exerciseId}/${solutionId}`, true);
5-
xhr.setRequestHeader('Content-Type', 'application/json');
6-
xhr.responseType = 'json';
7-
xhr.onreadystatechange = () => {
8-
if (xhr.readyState === 4) {
9-
if (xhr.status === 200) {
10-
if (xhr.response.next !== null) {
11-
window.location.href = `/view/${xhr.response.next}`;
12-
} else {
13-
alert("Yay! That's it!");
14-
}
15-
} else {
16-
console.log(xhr.status);
17-
}
18-
}
19-
};
20-
21-
xhr.send(JSON.stringify({}));
22-
});
23-
}
24-
251
function sendComment(kind, fileId, line, commentData) {
262
const xhr = new XMLHttpRequest();
273
xhr.open('POST', '/comments');
@@ -211,13 +187,11 @@ window.deleteComment = deleteComment;
211187
window.sendExistsComment = sendExistsComment;
212188
window.addEventListener('lines-numbered', () => {
213189
const codeView = document.getElementById('code-view');
214-
const exerciseId = codeView.dataset.exercise;
215190
const lineItems = codeView.getElementsByClassName('line');
216191
addNewCommentButtons(lineItems);
217192
const addCommentItems = codeView.querySelectorAll('.grader-add');
218193
trackDragAreas(lineItems, addCommentItems);
219194
trackDraggables(document.getElementsByClassName('known-comment'));
220-
trackFinished(exerciseId, window.solutionId, document.getElementById('save-check'));
221195
if (!window.isUserGrader()) {
222196
sessionStorage.setItem('role', 'grader');
223197
}

lms/templates/view.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ <h2>{{ _('הערות בודק') }}</h2>
142142
{% endif -%}
143143
{%- if is_manager %}
144144
<script src="{{ url_for('static', filename='keyboard.js') }}"></script>
145+
<script src="{{ url_for('static', filename='checker.js') }}"></script>
145146
{% endif -%}
146147
{% endif %}
147148
{% endblock %}

0 commit comments

Comments
 (0)