Skip to content

Commit 2c31f38

Browse files
authored
fix: New default -- semi-hide Flake8 issues (#372)
1 parent 23f61e2 commit 2c31f38

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lms/static/comments.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
const AUTO_CHECKER_ROLE = 2;
12
const DEFAULT_COMMENTED_LINE_COLOR = '#fab3b0';
23
const STUDENT_COMMENTED_LINE_COLOR = '#a9f6f9';
34
const FLAKE_COMMENTED_LINE_COLOR = '#fac4c3';
45
const HOVER_LINE_STYLE = '1px solid #0d0d0f';
56

7+
8+
function removeMark(lineElement) {
9+
lineElement.classList.remove('marked');
10+
lineElement.style.background = 'none';
11+
}
12+
13+
614
function markLine(target, color, deletion = false) {
715
if (target.dataset && target.dataset.marked === 'true' && !deletion) {return;}
816
if (target.dataset && target.dataset.vimbackground === 'true' && !deletion) {return;}
17+
target.classList.add('marked');
918
target.style.background = color;
1019
}
1120

@@ -72,6 +81,19 @@ function getCommentsContainer(line) {
7281
return commentsContainer;
7382
}
7483

84+
85+
function createToggledComment(lineElement, commentsContainer, authorRole) {
86+
if (lineElement.classList.contains('marked')) { return; }
87+
88+
markLine(lineElement, getLineColorByRole(authorRole));
89+
90+
commentsContainer.classList.add('d-none');
91+
lineElement.addEventListener('click', () => {
92+
commentsContainer.classList.toggle('d-none');
93+
});
94+
}
95+
96+
7597
function addCommentToLine(line, commentData) {
7698
const commentedLine = document.querySelector(`.line-container[data-line="${line}"]`);
7799
if (commentedLine === null) {
@@ -84,13 +106,23 @@ function addCommentToLine(line, commentData) {
84106
commentsContainer.appendChild(commentLine);
85107
Prism.highlightAllUnder(commentLine);
86108

109+
if (commentData.author_role === AUTO_CHECKER_ROLE) {
110+
createToggledComment(commentedLine, commentsContainer, commentData.author_role);
111+
}
87112
commentedLine.dataset.comment = 'true';
88113

89114
return commentLine;
90115
}
91116

92117
function getLineColorByRole(authorRole) {
93-
return authorRole === 1 ? STUDENT_COMMENTED_LINE_COLOR : DEFAULT_COMMENTED_LINE_COLOR;
118+
switch (authorRole) {
119+
case 1:
120+
return STUDENT_COMMENTED_LINE_COLOR;
121+
case 2:
122+
return FLAKE_COMMENTED_LINE_COLOR;
123+
default:
124+
return DEFAULT_COMMENTED_LINE_COLOR;
125+
}
94126
}
95127

96128
function treatComments(comments) {
@@ -260,6 +292,7 @@ function configureMarkdownParser() {
260292
}
261293

262294
window.markLine = markLine;
295+
window.removeMark = removeMark;
263296
window.hoverLine = hoverLine;
264297
window.addCommentToLine = addCommentToLine;
265298
window.getLineColorByRole = getLineColorByRole;

lms/static/grader.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ function sendComment(kind, fileId, line, commentData) {
2828
function visuallyRemoveComment(commentId) {
2929
const commentElement = document.querySelector(`comment-line[data-comment-id='${commentId}']`);
3030
const commentsContainer = commentElement.parentElement;
31+
const lineNumber = commentsContainer.dataset.line;
3132
commentElement.remove();
3233
if (commentsContainer.children.length === 0) {
3334
commentsContainer.remove();
35+
const lineContainer = document.querySelector(`.line-container[data-line='${lineNumber}']`);
36+
removeMark(lineContainer);
3437
}
3538
}
3639

0 commit comments

Comments
 (0)