Skip to content

Commit 170ccb8

Browse files
authored
feat: Colorize students comments (#218)
* feat: Colorize students comments - The last comment is the comment which going to mark the line - If someone deletes a comment - the line color will be updated accordingly
1 parent cba680f commit 170ccb8

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

lms/lmsdb/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ def _by_file(cls, file_id: int):
771771
.switch()
772772
.join(User)
773773
.where(cls.file == file_id)
774+
.order_by(cls.timestamp.asc())
774775
)
775776

776777
@classmethod

lms/static/comments.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const DEFAULT_COMMENTED_LINE_COLOR = '#fab3b0';
2+
const STUDENT_COMMENTED_LINE_COLOR = '#a9f6f9';
23
const FLAKE_COMMENTED_LINE_COLOR = '#fac4c3';
34
const HOVER_LINE_STYLE = '1px solid #0d0d0f';
45

5-
function markLine(target, color) {
6-
if (target.dataset && target.dataset.marked === 'true') { return; }
7-
if (target.dataset && target.dataset.vimbackground === 'true') { return; }
6+
function markLine(target, color, deletion = false) {
7+
if (target.dataset && target.dataset.marked === 'true' && !deletion) { return; }
8+
if (target.dataset && target.dataset.vimbackground === 'true' && !deletion) { return; }
89
target.style.background = color;
910
}
1011

@@ -45,7 +46,7 @@ function formatCommentData(commentData) {
4546
function addCommentToLine(line, commentData) {
4647
const commentElement = document.querySelector(`.line[data-line="${line}"]`);
4748
const formattedComment = formatCommentData(commentData);
48-
const commentText = `<span class="comment" data-line="${line}" data-commentid="${commentData.id}">${formattedComment}</span>`;
49+
const commentText = `<span class="comment" data-line="${line}" data-commentid="${commentData.id}" data-author-role="${commentData.author_role}">${formattedComment}</span>`;
4950
let existingPopover = bootstrap.Popover.getInstance(commentElement);
5051
if (existingPopover !== null) {
5152
const existingContent = `${existingPopover.config.content} <hr>`;
@@ -65,13 +66,18 @@ function addCommentToLine(line, commentData) {
6566
if (commentData.is_auto) {
6667
markLine(commentElement, FLAKE_COMMENTED_LINE_COLOR);
6768
} else {
68-
markLine(commentElement, DEFAULT_COMMENTED_LINE_COLOR);
69+
const lineColor = window.getLineColorByRole(commentData.author_role);
70+
markLine(commentElement, lineColor, true);
6971
commentElement.dataset.marked = true;
7072
}
7173

7274
return existingPopover;
7375
}
7476

77+
function getLineColorByRole(authorRole) {
78+
return authorRole === 1 ? STUDENT_COMMENTED_LINE_COLOR : DEFAULT_COMMENTED_LINE_COLOR;
79+
}
80+
7581
function treatComments(comments) {
7682
if (comments === undefined) {
7783
console.error('Probably bad xhr request');
@@ -143,6 +149,7 @@ window.markLink = markLine;
143149
window.hoverLine = hoverLine;
144150
window.addCommentToLine = addCommentToLine;
145151
window.isUserGrader = isUserGrader;
152+
window.getLineColorByRole = getLineColorByRole;
146153
window.addEventListener('load', () => {
147154
const codeElementData = document.getElementById('code-view').dataset;
148155
window.solutionId = codeElementData.id;

lms/static/grader.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ function visuallyRemoveComment(commentId) {
6767
removeContent = `${commentElement.outerHTML} <hr>`;
6868
}
6969
existingPopover.config.content = existingPopover.config.content.replace(removeContent, '');
70+
const commentParent = commentElement.parentNode;
7071
hr.parentNode.removeChild(hr);
71-
commentElement.parentNode.removeChild(commentElement);
72+
commentParent.removeChild(commentElement);
73+
const lastAuthorRole = commentParent.lastChild.previousElementSibling.dataset.authorRole;
74+
const newLineColor = window.getLineColorByRole(lastAuthorRole);
75+
window.markLine(lineElement, newLineColor, true);
7276
}
7377
}
7478

0 commit comments

Comments
 (0)