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
  • Loading branch information
SebDieBln committed Jan 13, 2018
1 parent 83e1927 commit 0b6ee53
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions code_comments/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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('_', '\\_') + '%')
name = name.replace('__prefix', '')
Expand Down
31 changes: 27 additions & 4 deletions code_comments/htdocs/code-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 @@ -111,10 +111,11 @@ var underscore = _.noConflict();
},
addOne: function(comment) {
var line = comment.get('line');
var file = comment.get('path');
if (!this.viewPerLine[line]) {
this.viewPerLine[line] = new CommentsForALineView( { line: line } );
this.viewPerLine[line] = new CommentsForALineView( { file: file, line: line } );

var $tr = $( Rows.getTrByLineNumberInDiff( line ) );
var $tr = $( Rows.getTrByFileAndLineNumberInFile( file, line ) );
$tr.after(this.viewPerLine[line].render().el).addClass('with-comments');
}
this.viewPerLine[line].addOne(comment);
Expand All @@ -133,6 +134,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 @@ -235,7 +237,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.getLineNumberInFile(),
displayLineText = displayLine;
if (displayLine < 0) {
Expand Down Expand Up @@ -274,6 +276,27 @@ var underscore = _.noConflict();
getTrByLineNumberInDiff: function( line ) {
return this.$rows[line - 1];
},
getTrByFileAndLineNumberInFile: function ( file, line) {
var containers = $( 'thead', 'table.code, table.trac-diff' );
var container;
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');
var col = 1;
if (line < 0) {
line = -line;
col = 0;
}
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 0b6ee53

Please sign in to comment.