Skip to content

Commit

Permalink
Comment is placed on line of file instead of line of diff.
Browse files Browse the repository at this point in the history
Negative line numbers are used to indicate a comment that was placed on a line of the old file.
  • Loading branch information
SebDieBln committed Aug 30, 2023
1 parent cd68ae4 commit 65e6b4f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
3 changes: 3 additions & 0 deletions code_comments/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def get_condition_str_and_corresponding_values(self, args):
elif name.endswith('__lt'):
name = name.replace('__lt', '')
conditions.append(name + ' < %s')
elif name.endswith('__ne'):
name = name.replace('__ne', '')
conditions.append(name + ' != %s')
elif name.endswith('__prefix'):
values.append(
args[name].replace('%', '\\%').replace('_', '\\_') + '%')
Expand Down
45 changes: 38 additions & 7 deletions code_comments/htdocs/code-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var underscore = _.noConflict();
return this.fetch( { data: _.extend( { line: 0 }, this.defaultFetchParams ) } );
},
fetchLineComments: function() {
return this.fetch( { data: _.extend( { line__gt: 0 }, this.defaultFetchParams ) } );
return this.fetch( { data: _.extend( { line__ne: 0 }, this.defaultFetchParams ) } );
}
});

Expand Down Expand Up @@ -112,13 +112,15 @@ var underscore = _.noConflict();
},
addOne: function(comment) {
var line = comment.get('line');
if (!this.viewPerLine[line]) {
this.viewPerLine[line] = new CommentsForALineView( { line: line } );
var file = comment.get('path');
var key = 'file_' + file + ':' + line;
if (!this.viewPerLine[key]) {
this.viewPerLine[key] = new CommentsForALineView( { file: file, line: line } );

var $tr = $( Rows.getTrByLineNumberInDiff( line ) );
$tr.after(this.viewPerLine[line].render().el).addClass('with-comments');
var $tr = $( Rows.getTrByFileAndLineNumberInFile( file, line ) );
$tr.after(this.viewPerLine[key].render().el).addClass('with-comments');
}
this.viewPerLine[line].addOne(comment);
this.viewPerLine[key].addOne(comment);
},
addAll: function() {
var view = this;
Expand All @@ -134,6 +136,7 @@ var underscore = _.noConflict();
template: _.template(CodeComments.templates.comments_for_a_line),
initialize: function(attrs) {
this.line = attrs.line;
this.file = attrs.file;
},
events: {
'click button': 'showAddCommentDialog'
Expand Down Expand Up @@ -239,7 +242,7 @@ var underscore = _.noConflict();
var callbackMouseover = function( event ) {
var row = new RowView( { el: this } ),
file = row.getFile(),
line = row.getLineNumberInDiff(),
line = row.getLineNumberInFile(),
displayLine = row.getDisplayLine();
row.replaceLineNumberCellContent( '<a title="Comment on this line" href="#L' + line + '" class="bubble"><span class="ui-icon ui-icon-comment"></span></a>' );

Expand Down Expand Up @@ -274,6 +277,34 @@ var underscore = _.noConflict();
getTrByLineNumberInDiff: function( line ) {
return this.$rows[line - 1];
},
getTrByFileAndLineNumberInFile: function ( file, line) {
var col;
var container;
if (CodeComments.page == "browser" && CodeComments.path == file) {
container = $( 'thead', 'table.code' );
col = 0;
} else {
if (line < 0) {
line = -line;
col = 0;
} else {
col = 1
}
var containers = $( 'thead', 'table.code, table.trac-diff' );
for ( var i = 0; (container = containers[i]) != null; i++ ) {
if ($(container).parents( 'li' ).find( 'h2>a:first' ).text() == file) {
break;
}
}
}
var trs = $(container).parents( 'table' ).find( 'tbody>tr' ).not('.comments');
for ( var i = 0, tr; (tr = trs[i]) != null; i++ ) {
if ($(tr).find( 'th>span' )[col].textContent == line) {
return tr;
}
}
return null;
},
wrapTHsInSpans: function() {
$( 'th', this.$rows ).each( function( i, elem ) {
elem.innerHTML = '<span>' + elem.innerHTML + '</span>';
Expand Down

0 comments on commit 65e6b4f

Please sign in to comment.