1
+ const AUTO_CHECKER_ROLE = 2 ;
1
2
const DEFAULT_COMMENTED_LINE_COLOR = '#fab3b0' ;
2
3
const STUDENT_COMMENTED_LINE_COLOR = '#a9f6f9' ;
3
4
const FLAKE_COMMENTED_LINE_COLOR = '#fac4c3' ;
4
5
const HOVER_LINE_STYLE = '1px solid #0d0d0f' ;
5
6
7
+
8
+ function removeMark ( lineElement ) {
9
+ lineElement . classList . remove ( 'marked' ) ;
10
+ lineElement . style . background = 'none' ;
11
+ }
12
+
13
+
6
14
function markLine ( target , color , deletion = false ) {
7
15
if ( target . dataset && target . dataset . marked === 'true' && ! deletion ) { return ; }
8
16
if ( target . dataset && target . dataset . vimbackground === 'true' && ! deletion ) { return ; }
17
+ target . classList . add ( 'marked' ) ;
9
18
target . style . background = color ;
10
19
}
11
20
@@ -72,6 +81,19 @@ function getCommentsContainer(line) {
72
81
return commentsContainer ;
73
82
}
74
83
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
+
75
97
function addCommentToLine ( line , commentData ) {
76
98
const commentedLine = document . querySelector ( `.line-container[data-line="${ line } "]` ) ;
77
99
if ( commentedLine === null ) {
@@ -84,13 +106,23 @@ function addCommentToLine(line, commentData) {
84
106
commentsContainer . appendChild ( commentLine ) ;
85
107
Prism . highlightAllUnder ( commentLine ) ;
86
108
109
+ if ( commentData . author_role === AUTO_CHECKER_ROLE ) {
110
+ createToggledComment ( commentedLine , commentsContainer , commentData . author_role ) ;
111
+ }
87
112
commentedLine . dataset . comment = 'true' ;
88
113
89
114
return commentLine ;
90
115
}
91
116
92
117
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
+ }
94
126
}
95
127
96
128
function treatComments ( comments ) {
@@ -260,6 +292,7 @@ function configureMarkdownParser() {
260
292
}
261
293
262
294
window . markLine = markLine ;
295
+ window . removeMark = removeMark ;
263
296
window . hoverLine = hoverLine ;
264
297
window . addCommentToLine = addCommentToLine ;
265
298
window . getLineColorByRole = getLineColorByRole ;
0 commit comments