11const DEFAULT_COMMENTED_LINE_COLOR = '#fab3b0' ;
2+ const STUDENT_COMMENTED_LINE_COLOR = '#a9f6f9' ;
23const FLAKE_COMMENTED_LINE_COLOR = '#fac4c3' ;
34const 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) {
4546function 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+
7581function treatComments ( comments ) {
7682 if ( comments === undefined ) {
7783 console . error ( 'Probably bad xhr request' ) ;
@@ -143,6 +149,7 @@ window.markLink = markLine;
143149window . hoverLine = hoverLine ;
144150window . addCommentToLine = addCommentToLine ;
145151window . isUserGrader = isUserGrader ;
152+ window . getLineColorByRole = getLineColorByRole ;
146153window . addEventListener ( 'load' , ( ) => {
147154 const codeElementData = document . getElementById ( 'code-view' ) . dataset ;
148155 window . solutionId = codeElementData . id ;
0 commit comments