emails: added reply link to comment type emails

- also added note/todo ID in display
- cleanup code for anchor resolution, and selected elements highlight
This commit is contained in:
Daniel Dourvaris 2019-11-08 13:05:34 +01:00
parent 697ce81998
commit 603a3c0545
10 changed files with 103 additions and 61 deletions

View file

@ -428,6 +428,10 @@ channelstream.history.location = %(here)s/channelstream_history
## If you use proxy-prefix the prefix should be added before /_channelstream
channelstream.proxy_path = /_channelstream
## Live chat for commits/pull requests. Requires CHANNELSTREAM to be enabled
## and configured. (EE edition only)
chat.enabled = true
###################################
## APPENLIGHT CONFIG ##

View file

@ -126,12 +126,13 @@ Check if we should use full-topic or mini-topic.
'pull_request_url': 'http://localhost/pr1',
'pr_comment_url': 'http://comment-url',
'pr_comment_reply_url': 'http://comment-url#reply',
'comment_file': None,
'comment_line': None,
'comment_type': 'note',
'comment_body': 'This is my comment body. *I like !*',
'comment_id': 2048,
'renderer_type': 'markdown',
'mention': True,
@ -153,6 +154,7 @@ Check if we should use full-topic or mini-topic.
'pull_request_url': 'http://localhost/pr1',
'pr_comment_url': 'http://comment-url',
'pr_comment_reply_url': 'http://comment-url#reply',
'comment_type': 'todo',
'comment_file': None,
@ -169,7 +171,7 @@ def db():
```
''',
'comment_id': 2048,
'renderer_type': 'markdown',
'mention': True,
@ -192,6 +194,7 @@ def db():
'pull_request_url': 'http://localhost/pr1',
'pr_comment_url': 'http://comment-url',
'pr_comment_reply_url': 'http://comment-url#reply',
'comment_file': 'rhodecode/model/db.py',
'comment_line': 'o1210',
@ -206,7 +209,7 @@ But please check this code::
This should work better !
''',
'comment_id': 2048,
'renderer_type': 'rst',
'mention': True,
@ -224,7 +227,9 @@ This should work better !
'comment_file': None,
'comment_line': None,
'commit_comment_url': 'http://comment-url',
'commit_comment_reply_url': 'http://comment-url#reply',
'comment_body': 'This is my comment body. *I like !*',
'comment_id': 2048,
'renderer_type': 'markdown',
'mention': True,
},
@ -240,6 +245,7 @@ This should work better !
'comment_file': None,
'comment_line': None,
'commit_comment_url': 'http://comment-url',
'commit_comment_reply_url': 'http://comment-url#reply',
'comment_body': '''
Hello **world**
@ -248,6 +254,7 @@ This is a multiline comment :)
- list
- list2
''',
'comment_id': 2048,
'renderer_type': 'markdown',
'mention': True,
},
@ -265,7 +272,9 @@ This is a multiline comment :)
'comment_line': 'n100',
'commit_comment_url': 'http://comment-url',
'commit_comment_reply_url': 'http://comment-url#reply',
'comment_body': 'This is my comment body. *I like !*',
'comment_id': 2048,
'renderer_type': 'markdown',
'mention': True,
},

View file

@ -339,7 +339,8 @@ class CommentsModel(BaseModel):
'comment_body': text,
'comment_file': f_path,
'comment_line': line_no,
'comment_type': comment_type or 'note'
'comment_type': comment_type or 'note',
'comment_id': comment.comment_id
}
if commit_obj:
@ -353,6 +354,9 @@ class CommentsModel(BaseModel):
recipients += [cs_author]
commit_comment_url = self.get_url(comment, request=request)
commit_comment_reply_url = self.get_url(
comment, request=request,
anchor='comment-{}/?/ReplyToComment'.format(comment.comment_id))
target_repo_url = h.link_to(
repo.repo_name,
@ -364,6 +368,7 @@ class CommentsModel(BaseModel):
'commit_message': commit_obj.message,
'commit_target_repo_url': target_repo_url,
'commit_comment_url': commit_comment_url,
'commit_comment_reply_url': commit_comment_reply_url
})
elif pull_request_obj:
@ -379,11 +384,10 @@ class CommentsModel(BaseModel):
pr_target_repo = pull_request_obj.target_repo
pr_source_repo = pull_request_obj.source_repo
pr_comment_url = h.route_url(
'pullrequest_show',
repo_name=pr_target_repo.repo_name,
pull_request_id=pull_request_obj.pull_request_id,
_anchor='comment-%s' % comment.comment_id)
pr_comment_url = self.get_url(comment, request=request)
pr_comment_reply_url = self.get_url(
comment, request=request,
anchor='comment-{}/?/ReplyToComment'.format(comment.comment_id))
pr_url = h.route_url(
'pullrequest_show',
@ -407,6 +411,7 @@ class CommentsModel(BaseModel):
'pull_request_source_repo': pr_source_repo,
'pull_request_source_repo_url': pr_source_repo_url,
'pr_comment_url': pr_comment_url,
'pr_comment_reply_url': pr_comment_reply_url,
'pr_closing': closing_pr,
})
@ -505,24 +510,27 @@ class CommentsModel(BaseModel):
q = q.order_by(ChangesetComment.created_on)
return q.all()
def get_url(self, comment, request=None, permalink=False):
def get_url(self, comment, request=None, permalink=False, anchor=None):
if not request:
request = get_current_request()
comment = self.__get_commit_comment(comment)
if anchor is None:
anchor = 'comment-{}'.format(comment.comment_id)
if comment.pull_request:
pull_request = comment.pull_request
if permalink:
return request.route_url(
'pull_requests_global',
pull_request_id=pull_request.pull_request_id,
_anchor='comment-%s' % comment.comment_id)
_anchor=anchor)
else:
return request.route_url(
'pullrequest_show',
repo_name=safe_str(pull_request.target_repo.repo_name),
pull_request_id=pull_request.pull_request_id,
_anchor='comment-%s' % comment.comment_id)
_anchor=anchor)
else:
repo = comment.repo
@ -532,13 +540,13 @@ class CommentsModel(BaseModel):
return request.route_url(
'repo_commit', repo_name=safe_str(repo.repo_id),
commit_id=commit_id,
_anchor='comment-%s' % comment.comment_id)
_anchor=anchor)
else:
return request.route_url(
'repo_commit', repo_name=safe_str(repo.repo_name),
commit_id=commit_id,
_anchor='comment-%s' % comment.comment_id)
_anchor=anchor)
def get_comments(self, repo_id, revision=None, pull_request=None):
"""

View file

@ -302,11 +302,15 @@ table.code-difftable {
// Comments
div.comment:target {
.comment-selected-hl {
border-left: 6px solid @comment-highlight-color !important;
padding-left: 3px;
margin-left: -9px;
padding-left: 3px !important;
margin-left: -7px !important;
}
div.comment:target,
div.comment-outdated:target {
.comment-selected-hl;
}
//TODO: anderson: can't get an absolute number out of anything, so had to put the

View file

@ -534,15 +534,17 @@ $(document).ready(function() {
if (location.hash) {
var result = splitDelimitedHash(location.hash);
var loc = result.loc;
var loc = result.loc;
if (loc.length > 1) {
var highlightable_line_tds = [];
// source code line format
var page_highlights = loc.substring(
loc.indexOf('#') + 1).split('L');
var page_highlights = loc.substring(loc.indexOf('#') + 1).split('L');
// multi-line HL, for files
if (page_highlights.length > 1) {
var highlight_ranges = page_highlights[1].split(",");
var h_lines = [];
@ -556,8 +558,7 @@ $(document).ready(function() {
h_lines.push(i);
}
}
}
else {
} else {
h_lines.push(parseInt(highlight_ranges[pos]));
}
}
@ -569,24 +570,45 @@ $(document).ready(function() {
}
}
// now check a direct id reference (diff page)
if ($(loc).length && $(loc).hasClass('cb-lineno')) {
// now check a direct id reference of line in diff / pull-request page)
if ($(loc).length > 0 && $(loc).hasClass('cb-lineno')) {
highlightable_line_tds.push($(loc));
}
// mark diff lines as selected
$.each(highlightable_line_tds, function (i, $td) {
$td.addClass('cb-line-selected'); // line number td
$td.prev().addClass('cb-line-selected'); // line data
$td.next().addClass('cb-line-selected'); // line content
});
if (highlightable_line_tds.length) {
if (highlightable_line_tds.length > 0) {
var $first_line_td = highlightable_line_tds[0];
scrollToElement($first_line_td);
$.Topic('/ui/plugins/code/anchor_focus').prepareOrPublish({
td: $first_line_td,
remainder: result.remainder
});
} else {
// case for direct anchor to comments
var $line = $(loc);
if ($line.hasClass('comment-general')) {
$line.show();
} else if ($line.hasClass('comment-inline')) {
$line.show();
var $cb = $line.closest('.cb');
$cb.removeClass('cb-collapsed')
}
if ($line.length > 0) {
$line.addClass('comment-selected-hl');
offsetScroll($line, 70);
}
if (!$line.hasClass('comment-outdated') && result.remainder === '/ReplyToComment') {
$line.nextAll('.cb-comment-add-button').trigger('click');
}
}
}
}
collapsableContent();

View file

@ -212,7 +212,6 @@
}
});
// next links
$('#child_link').on('click', function(e){
// fetch via ajax what is going to be the next link, if we have
@ -291,23 +290,12 @@
}
});
if (location.hash) {
var result = splitDelimitedHash(location.hash);
var line = $('html').find(result.loc);
if (line.length > 0){
offsetScroll(line, 70);
}
}
// browse tree @ revision
$('#files_link').on('click', function(e){
window.location = '${h.route_path('repo_files:default_path',repo_name=c.repo_name, commit_id=c.commit.raw_id)}';
e.preventDefault();
});
// inject comments into their proper positions
var file_comments = $('.inline-comment-placeholder');
})
</script>

View file

@ -12,6 +12,7 @@ data = {
'comment_file': comment_file,
'comment_line': comment_line,
'comment_type': comment_type,
'comment_id': comment_id,
'commit_id': h.show_id(commit),
}
@ -40,6 +41,7 @@ data = {
'comment_file': comment_file,
'comment_line': comment_line,
'comment_type': comment_type,
'comment_id': comment_id,
'commit_id': h.show_id(commit),
}
@ -78,6 +80,7 @@ data = {
'comment_file': comment_file,
'comment_line': comment_line,
'comment_type': comment_type,
'comment_id': comment_id,
'renderer_type': renderer_type or 'plain',
'repo': commit_target_repo_url,
@ -146,16 +149,22 @@ data = {
</tr>
% endif
<tr style="background-image: linear-gradient(to right, black 33%, rgba(255,255,255,0) 0%);background-position: bottom;background-size: 3px 1px;background-repeat: repeat-x;">
<tr style="border-bottom:1px solid #dbd9da;">
<td colspan="2" style="padding-right:20px;">
% if comment_type == 'todo':
${_('`TODO` comment')}:
${_('`TODO` number')} ${comment_id}:
% else:
${_('`Note` comment')}:
${_('`Note` number')} ${comment_id}:
% endif
</td>
</tr>
<td colspan="2" style="background: #F7F7F7">${h.render(comment_body, renderer=data['renderer_type'], mentions=True)}</td>
<tr>
<td colspan="2" style="background: #F7F7F7">${h.render(comment_body, renderer=data['renderer_type'], mentions=True)}</td>
</tr>
<tr>
<td><a href="${commit_comment_reply_url}">${_('Reply')}</a></td>
<td></td>
</tr>
</table>

View file

@ -12,6 +12,7 @@ data = {
'comment_file': comment_file,
'comment_line': comment_line,
'comment_type': comment_type,
'comment_id': comment_id,
'pr_title': pull_request.title,
'pr_id': pull_request.pull_request_id,
@ -41,6 +42,7 @@ data = {
'comment_file': comment_file,
'comment_line': comment_line,
'comment_type': comment_type,
'comment_id': comment_id,
'pr_title': pull_request.title,
'pr_id': pull_request.pull_request_id,
@ -91,6 +93,7 @@ data = {
'comment_file': comment_file,
'comment_line': comment_line,
'comment_type': comment_type,
'comment_id': comment_id,
'renderer_type': renderer_type or 'plain',
'pr_title': pull_request.title,
@ -176,16 +179,22 @@ data = {
</tr>
% endif
<tr style="background-image: linear-gradient(to right, black 33%, rgba(255,255,255,0) 0%);background-position: bottom;background-size: 3px 1px;background-repeat: repeat-x;">
<tr style="border-bottom:1px solid #dbd9da;">
<td colspan="2" style="padding-right:20px;">
% if comment_type == 'todo':
${_('`TODO` comment')}:
${_('`TODO` number')} ${comment_id}:
% else:
${_('`Note` comment')}:
${_('`Note` number')} ${comment_id}:
% endif
</td>
</tr>
<td colspan="2" style="background: #F7F7F7">${h.render(comment_body, renderer=data['renderer_type'], mentions=True)}</td>
<tr>
<td colspan="2" style="background: #F7F7F7">${h.render(comment_body, renderer=data['renderer_type'], mentions=True)}</td>
</tr>
<tr>
<td><a href="${pr_comment_reply_url}">${_('Reply')}</a></td>
<td></td>
</tr>
</table>

View file

@ -576,21 +576,6 @@
%endif
<script type="text/javascript">
if (location.hash) {
var result = splitDelimitedHash(location.hash);
var line = $('html').find(result.loc);
// show hidden comments if we use location.hash
if (line.hasClass('comment-general')) {
$(line).show();
} else if (line.hasClass('comment-inline')) {
$(line).show();
var $cb = $(line).closest('.cb');
$cb.removeClass('cb-collapsed')
}
if (line.length > 0){
offsetScroll(line, 70);
}
}
versionController = new VersionController();
versionController.init();
@ -796,6 +781,7 @@
ReviewerAutoComplete('#user');
})
</script>
</div>

View file

@ -115,12 +115,15 @@ def test_render_comment_subject_no_newlines(app, mention, email_type):
'comment_file': 'test-file.py',
'comment_line': 'n100',
'comment_type': 'note',
'comment_id': 2048,
'commit_comment_url': 'http://comment-url',
'commit_comment_reply_url': 'http://comment-url/#Reply',
'instance_url': 'http://rc-instance',
'comment_body': 'hello world',
'mention': mention,
'pr_comment_url': 'http://comment-url',
'pr_comment_reply_url': 'http://comment-url/#Reply',
'pull_request': pr,
'pull_request_commits': [],