diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -463,6 +463,11 @@ def make_map(config): action='comment', conditions=dict(function=check_repo, method=["POST"])) + rmap.connect('pullrequest_comment_delete', + '/{repo_name:.*}/pull-request-comment/{comment_id}/delete', + controller='pullrequests', action='delete_comment', + conditions=dict(function=check_repo, method=["DELETE"])) + rmap.connect('summary_home', '/{repo_name:.*}/summary', controller='summary', conditions=dict(function=check_repo)) diff --git a/rhodecode/controllers/pullrequests.py b/rhodecode/controllers/pullrequests.py --- a/rhodecode/controllers/pullrequests.py +++ b/rhodecode/controllers/pullrequests.py @@ -25,7 +25,7 @@ import logging import traceback -from webob.exc import HTTPNotFound +from webob.exc import HTTPNotFound, HTTPForbidden from collections import defaultdict from itertools import groupby @@ -39,7 +39,8 @@ from rhodecode.lib.auth import LoginRequ from rhodecode.lib import helpers as h from rhodecode.lib import diffs from rhodecode.lib.utils import action_logger -from rhodecode.model.db import User, PullRequest, ChangesetStatus +from rhodecode.model.db import User, PullRequest, ChangesetStatus,\ + ChangesetComment from rhodecode.model.pull_request import PullRequestModel from rhodecode.model.meta import Session from rhodecode.model.repo import RepoModel @@ -189,7 +190,8 @@ class PullrequestsController(BaseRepoCon for f in _parsed: fid = h.FID('', f['filename']) c.files.append([fid, f['operation'], f['filename'], f['stats']]) - diff = diff_processor.as_html(enable_comments=False, diff_lines=[f]) + diff = diff_processor.as_html(enable_comments=True, + diff_lines=[f]) c.changes[fid] = [f['operation'], f['filename'], diff] def show(self, repo_name, pull_request_id): @@ -295,3 +297,14 @@ class PullrequestsController(BaseRepoCon render('changeset/changeset_comment_block.html')}) return data + + @jsonify + def delete_comment(self, repo_name, comment_id): + co = ChangesetComment.get(comment_id) + owner = lambda: co.author.user_id == c.rhodecode_user.user_id + if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner: + ChangesetCommentsModel().delete(comment=co) + Session.commit() + return True + else: + raise HTTPForbidden() \ No newline at end of file diff --git a/rhodecode/templates/changeset/changeset.html b/rhodecode/templates/changeset/changeset.html --- a/rhodecode/templates/changeset/changeset.html +++ b/rhodecode/templates/changeset/changeset.html @@ -125,6 +125,8 @@ <script> var _USERS_AC_DATA = ${c.users_array|n}; var _GROUPS_AC_DATA = ${c.users_groups_array|n}; + AJAX_COMMENT_URL = "${url('changeset_comment',repo_name=c.repo_name,revision=c.changeset.raw_id)}"; + AJAX_COMMENT_DELETE_URL = "${url('changeset_comment_delete',repo_name=c.repo_name,comment_id='__COMMENT_ID__')}"; </script> ## diff block <%namespace name="diff_block" file="/changeset/diff_block.html"/> @@ -132,16 +134,15 @@ ## template for inline comment form <%namespace name="comment" file="/changeset/changeset_file_comment.html"/> - ${comment.comment_inline_form(c.changeset)} + ${comment.comment_inline_form()} ## render comments main comments form and it status ${comment.comments(h.url('changeset_comment', repo_name=c.repo_name, revision=c.changeset.raw_id), h.changeset_status(c.rhodecode_db_repo, c.changeset.raw_id))} + ## FORM FOR MAKING JS ACTION AS CHANGESET COMMENTS <script type="text/javascript"> YUE.onDOMReady(function(){ - AJAX_COMMENT_URL = "${url('changeset_comment',repo_name=c.repo_name,revision=c.changeset.raw_id)}"; - AJAX_COMMENT_DELETE_URL = "${url('changeset_comment_delete',repo_name=c.repo_name,comment_id='__COMMENT_ID__')}" YUE.on(YUQ('.show-inline-comments'),'change',function(e){ var show = 'none'; var target = e.currentTarget; @@ -167,7 +168,6 @@ // inject comments into they proper positions var file_comments = YUQ('.inline-comment-placeholder'); renderInlineComments(file_comments); - }) </script> diff --git a/rhodecode/templates/changeset/changeset_file_comment.html b/rhodecode/templates/changeset/changeset_file_comment.html --- a/rhodecode/templates/changeset/changeset_file_comment.html +++ b/rhodecode/templates/changeset/changeset_file_comment.html @@ -35,12 +35,12 @@ </%def> -<%def name="comment_inline_form(changeset)"> +<%def name="comment_inline_form()"> <div id='comment-inline-form-template' style="display:none"> <div class="comment-inline-form ac"> %if c.rhodecode_user.username != 'default': <div class="overlay"><div class="overlay-text">${_('Submitting...')}</div></div> - ${h.form(h.url('changeset_comment', repo_name=c.repo_name, revision=changeset.raw_id),class_='inline-form')} + ${h.form('#', class_='inline-form')} <div class="clearfix"> <div class="comment-help">${_('Commenting on line {1}.')} ${(_('Comments parsed using %s syntax with %s support.') % ( diff --git a/rhodecode/templates/pullrequests/pullrequest_show.html b/rhodecode/templates/pullrequests/pullrequest_show.html --- a/rhodecode/templates/pullrequests/pullrequest_show.html +++ b/rhodecode/templates/pullrequests/pullrequest_show.html @@ -83,6 +83,8 @@ <script> var _USERS_AC_DATA = ${c.users_array|n}; var _GROUPS_AC_DATA = ${c.users_groups_array|n}; + AJAX_COMMENT_URL = "${url('pullrequest_comment',repo_name=c.repo_name,pull_request_id=c.pull_request.pull_request_id)}"; + AJAX_COMMENT_DELETE_URL = "${url('pullrequest_comment_delete',repo_name=c.repo_name,comment_id='__COMMENT_ID__')}"; </script> ## diff block @@ -93,12 +95,46 @@ ## template for inline comment form <%namespace name="comment" file="/changeset/changeset_file_comment.html"/> - ##${comment.comment_inline_form(c.changeset)} + ${comment.comment_inline_form()} ## render comments main comments form and it status ${comment.comments(h.url('pullrequest_comment', repo_name=c.repo_name, pull_request_id=c.pull_request.pull_request_id), c.current_changeset_status)} + + <script type="text/javascript"> + YUE.onDOMReady(function(){ + + YUE.on(YUQ('.show-inline-comments'),'change',function(e){ + var show = 'none'; + var target = e.currentTarget; + if(target.checked){ + var show = '' + } + var boxid = YUD.getAttribute(target,'id_for'); + var comments = YUQ('#{0} .inline-comments'.format(boxid)); + for(c in comments){ + YUD.setStyle(comments[c],'display',show); + } + var btns = YUQ('#{0} .inline-comments-button'.format(boxid)); + for(c in btns){ + YUD.setStyle(btns[c],'display',show); + } + }) + + YUE.on(YUQ('.line'),'click',function(e){ + var tr = e.currentTarget; + injectInlineForm(tr); + }); + + // inject comments into they proper positions + var file_comments = YUQ('.inline-comment-placeholder'); + renderInlineComments(file_comments); + }) + + </script> + + </div> </%def>