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 Mar 30, 2018
1 parent 83e1927 commit ad2184f
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 @@ -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
45 changes: 38 additions & 7 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,13 +111,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 @@ -133,6 +135,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 +238,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 +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 ad2184f

Please sign in to comment.