1
1
const DEFAULT_COMMENTED_LINE_COLOR = '#fab3b0' ;
2
+ const STUDENT_COMMENTED_LINE_COLOR = '#a9f6f9' ;
2
3
const FLAKE_COMMENTED_LINE_COLOR = '#fac4c3' ;
3
4
const HOVER_LINE_STYLE = '1px solid #0d0d0f' ;
4
5
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 ; }
8
9
target . style . background = color ;
9
10
}
10
11
@@ -45,7 +46,7 @@ function formatCommentData(commentData) {
45
46
function addCommentToLine ( line , commentData ) {
46
47
const commentElement = document . querySelector ( `.line[data-line="${ line } "]` ) ;
47
48
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>` ;
49
50
let existingPopover = bootstrap . Popover . getInstance ( commentElement ) ;
50
51
if ( existingPopover !== null ) {
51
52
const existingContent = `${ existingPopover . config . content } <hr>` ;
@@ -65,13 +66,18 @@ function addCommentToLine(line, commentData) {
65
66
if ( commentData . is_auto ) {
66
67
markLine ( commentElement , FLAKE_COMMENTED_LINE_COLOR ) ;
67
68
} else {
68
- markLine ( commentElement , DEFAULT_COMMENTED_LINE_COLOR ) ;
69
+ const lineColor = window . getLineColorByRole ( commentData . author_role ) ;
70
+ markLine ( commentElement , lineColor , true ) ;
69
71
commentElement . dataset . marked = true ;
70
72
}
71
73
72
74
return existingPopover ;
73
75
}
74
76
77
+ function getLineColorByRole ( authorRole ) {
78
+ return authorRole === 1 ? STUDENT_COMMENTED_LINE_COLOR : DEFAULT_COMMENTED_LINE_COLOR ;
79
+ }
80
+
75
81
function treatComments ( comments ) {
76
82
if ( comments === undefined ) {
77
83
console . error ( 'Probably bad xhr request' ) ;
@@ -143,6 +149,7 @@ window.markLink = markLine;
143
149
window . hoverLine = hoverLine ;
144
150
window . addCommentToLine = addCommentToLine ;
145
151
window . isUserGrader = isUserGrader ;
152
+ window . getLineColorByRole = getLineColorByRole ;
146
153
window . addEventListener ( 'load' , ( ) => {
147
154
const codeElementData = document . getElementById ( 'code-view' ) . dataset ;
148
155
window . solutionId = codeElementData . id ;
0 commit comments