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 ## If you use proxy-prefix the prefix should be added before /_channelstream
channelstream.proxy_path = /_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 ## ## APPENLIGHT CONFIG ##

View file

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

View file

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

View file

@ -302,11 +302,15 @@ table.code-difftable {
// Comments // Comments
.comment-selected-hl {
div.comment:target {
border-left: 6px solid @comment-highlight-color !important; border-left: 6px solid @comment-highlight-color !important;
padding-left: 3px; padding-left: 3px !important;
margin-left: -9px; 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 //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) { if (location.hash) {
var result = splitDelimitedHash(location.hash); var result = splitDelimitedHash(location.hash);
var loc = result.loc;
var loc = result.loc;
if (loc.length > 1) { if (loc.length > 1) {
var highlightable_line_tds = []; var highlightable_line_tds = [];
// source code line format // source code line format
var page_highlights = loc.substring( var page_highlights = loc.substring(loc.indexOf('#') + 1).split('L');
loc.indexOf('#') + 1).split('L');
// multi-line HL, for files
if (page_highlights.length > 1) { if (page_highlights.length > 1) {
var highlight_ranges = page_highlights[1].split(","); var highlight_ranges = page_highlights[1].split(",");
var h_lines = []; var h_lines = [];
@ -556,8 +558,7 @@ $(document).ready(function() {
h_lines.push(i); h_lines.push(i);
} }
} }
} } else {
else {
h_lines.push(parseInt(highlight_ranges[pos])); h_lines.push(parseInt(highlight_ranges[pos]));
} }
} }
@ -569,24 +570,45 @@ $(document).ready(function() {
} }
} }
// now check a direct id reference (diff page) // now check a direct id reference of line in diff / pull-request page)
if ($(loc).length && $(loc).hasClass('cb-lineno')) { if ($(loc).length > 0 && $(loc).hasClass('cb-lineno')) {
highlightable_line_tds.push($(loc)); highlightable_line_tds.push($(loc));
} }
// mark diff lines as selected
$.each(highlightable_line_tds, function (i, $td) { $.each(highlightable_line_tds, function (i, $td) {
$td.addClass('cb-line-selected'); // line number td $td.addClass('cb-line-selected'); // line number td
$td.prev().addClass('cb-line-selected'); // line data $td.prev().addClass('cb-line-selected'); // line data
$td.next().addClass('cb-line-selected'); // line content $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]; var $first_line_td = highlightable_line_tds[0];
scrollToElement($first_line_td); scrollToElement($first_line_td);
$.Topic('/ui/plugins/code/anchor_focus').prepareOrPublish({ $.Topic('/ui/plugins/code/anchor_focus').prepareOrPublish({
td: $first_line_td, td: $first_line_td,
remainder: result.remainder 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(); collapsableContent();

View file

@ -212,7 +212,6 @@
} }
}); });
// next links // next links
$('#child_link').on('click', function(e){ $('#child_link').on('click', function(e){
// fetch via ajax what is going to be the next link, if we have // 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 // browse tree @ revision
$('#files_link').on('click', function(e){ $('#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)}'; window.location = '${h.route_path('repo_files:default_path',repo_name=c.repo_name, commit_id=c.commit.raw_id)}';
e.preventDefault(); e.preventDefault();
}); });
// inject comments into their proper positions
var file_comments = $('.inline-comment-placeholder');
}) })
</script> </script>

View file

@ -12,6 +12,7 @@ data = {
'comment_file': comment_file, 'comment_file': comment_file,
'comment_line': comment_line, 'comment_line': comment_line,
'comment_type': comment_type, 'comment_type': comment_type,
'comment_id': comment_id,
'commit_id': h.show_id(commit), 'commit_id': h.show_id(commit),
} }
@ -40,6 +41,7 @@ data = {
'comment_file': comment_file, 'comment_file': comment_file,
'comment_line': comment_line, 'comment_line': comment_line,
'comment_type': comment_type, 'comment_type': comment_type,
'comment_id': comment_id,
'commit_id': h.show_id(commit), 'commit_id': h.show_id(commit),
} }
@ -78,6 +80,7 @@ data = {
'comment_file': comment_file, 'comment_file': comment_file,
'comment_line': comment_line, 'comment_line': comment_line,
'comment_type': comment_type, 'comment_type': comment_type,
'comment_id': comment_id,
'renderer_type': renderer_type or 'plain', 'renderer_type': renderer_type or 'plain',
'repo': commit_target_repo_url, 'repo': commit_target_repo_url,
@ -146,16 +149,22 @@ data = {
</tr> </tr>
% endif % 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;"> <td colspan="2" style="padding-right:20px;">
% if comment_type == 'todo': % if comment_type == 'todo':
${_('`TODO` comment')}: ${_('`TODO` number')} ${comment_id}:
% else: % else:
${_('`Note` comment')}: ${_('`Note` number')} ${comment_id}:
% endif % endif
</td> </td>
</tr> </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> </tr>
</table> </table>

View file

@ -12,6 +12,7 @@ data = {
'comment_file': comment_file, 'comment_file': comment_file,
'comment_line': comment_line, 'comment_line': comment_line,
'comment_type': comment_type, 'comment_type': comment_type,
'comment_id': comment_id,
'pr_title': pull_request.title, 'pr_title': pull_request.title,
'pr_id': pull_request.pull_request_id, 'pr_id': pull_request.pull_request_id,
@ -41,6 +42,7 @@ data = {
'comment_file': comment_file, 'comment_file': comment_file,
'comment_line': comment_line, 'comment_line': comment_line,
'comment_type': comment_type, 'comment_type': comment_type,
'comment_id': comment_id,
'pr_title': pull_request.title, 'pr_title': pull_request.title,
'pr_id': pull_request.pull_request_id, 'pr_id': pull_request.pull_request_id,
@ -91,6 +93,7 @@ data = {
'comment_file': comment_file, 'comment_file': comment_file,
'comment_line': comment_line, 'comment_line': comment_line,
'comment_type': comment_type, 'comment_type': comment_type,
'comment_id': comment_id,
'renderer_type': renderer_type or 'plain', 'renderer_type': renderer_type or 'plain',
'pr_title': pull_request.title, 'pr_title': pull_request.title,
@ -176,16 +179,22 @@ data = {
</tr> </tr>
% endif % 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;"> <td colspan="2" style="padding-right:20px;">
% if comment_type == 'todo': % if comment_type == 'todo':
${_('`TODO` comment')}: ${_('`TODO` number')} ${comment_id}:
% else: % else:
${_('`Note` comment')}: ${_('`Note` number')} ${comment_id}:
% endif % endif
</td> </td>
</tr> </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> </tr>
</table> </table>

View file

@ -576,21 +576,6 @@
%endif %endif
<script type="text/javascript"> <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 = new VersionController();
versionController.init(); versionController.init();
@ -796,6 +781,7 @@
ReviewerAutoComplete('#user'); ReviewerAutoComplete('#user');
}) })
</script> </script>
</div> </div>

View file

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