# HG changeset patch # User Mads Kiilerich # Date 1453250831 -3600 # Node ID 7834f845505aec3086f525600c81209a40b495ef # Parent b3ddd87f214f27df6ca9eb0888dce925a6ff4361 comments: use inline comment infrastructure for general comments too diff -r b3ddd87f214f -r 7834f845505a kallithea/controllers/changeset.py --- a/kallithea/controllers/changeset.py Wed Jan 20 01:47:11 2016 +0100 +++ b/kallithea/controllers/changeset.py Wed Jan 20 01:47:11 2016 +0100 @@ -175,6 +175,9 @@ # Could perhaps be nice to have in the model but is too high level ... def create_comment(text, status, f_path, line_no, revision=None, pull_request_id=None, closing_pr=None): """Comment functionality shared between changesets and pullrequests""" + f_path = f_path or None + line_no = line_no or None + comment = ChangesetCommentsModel().create( text=text, repo=c.db_repo.repo_id, @@ -202,6 +205,7 @@ c.user_groups_array = repo_model.get_user_groups_js() def _index(self, revision, method): + c.pull_request = None c.anchor_url = anchor_url c.ignorews_url = _ignorews_url c.context_url = _context_url @@ -365,6 +369,8 @@ 'repository.admin') @jsonify def comment(self, repo_name, revision): + assert request.environ.get('HTTP_X_PARTIAL_XHR') + status = request.POST.get('changeset_status') text = request.POST.get('text', '').strip() @@ -379,9 +385,7 @@ # get status if set ! if status: # if latest status was from pull request and it's closed - # disallow changing status ! - # dont_allow_on_closed_pull_request = True ! - + # disallow changing status ! RLY? try: ChangesetStatusModel().set_status( c.db_repo.repo_id, @@ -389,25 +393,18 @@ c.authuser.user_id, c.comment, revision=revision, - dont_allow_on_closed_pull_request=True + dont_allow_on_closed_pull_request=True, ) except StatusChangeOnClosedPullRequestError: - log.debug(traceback.format_exc()) - msg = _('Changing status on a changeset associated with ' - 'a closed pull request is not allowed') - h.flash(msg, category='warning') - raise HTTPFound(location=h.url('changeset_home', repo_name=repo_name, - revision=revision)) + log.debug('cannot change status on %s with closed pull request', revision) + raise HTTPBadRequest() + action_logger(self.authuser, 'user_commented_revision:%s' % revision, c.db_repo, self.ip_addr, self.sa) Session().commit() - if not request.environ.get('HTTP_X_PARTIAL_XHR'): - raise HTTPFound(location=h.url('changeset_home', repo_name=repo_name, - revision=revision)) - #only ajax below data = { 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))), } diff -r b3ddd87f214f -r 7834f845505a kallithea/public/css/style.css --- a/kallithea/public/css/style.css Wed Jan 20 01:47:11 2016 +0100 +++ b/kallithea/public/css/style.css Wed Jan 20 01:47:11 2016 +0100 @@ -208,6 +208,10 @@ color: #B9B9B9; } +.inline-comments-general.show-general-status .hidden.general-only { + display: block !important; +} + .truncate { white-space: nowrap; overflow: hidden; diff -r b3ddd87f214f -r 7834f845505a kallithea/public/js/base.js --- a/kallithea/public/js/base.js Wed Jan 20 01:47:11 2016 +0100 +++ b/kallithea/public/js/base.js Wed Jan 20 01:47:11 2016 +0100 @@ -673,12 +673,16 @@ // append an Add button to $comment_div and hook it up to show form function _comment_div_append_add($comment_div, f_path, line_no) { - var addlabel = TRANSLATION_MAP['Add Another Comment']; - var $add = $('
{0}
'.format(addlabel)); - $comment_div.append($add); - $add.children('.add-button').click(function(e) { + if (f_path && line_no) { + var addlabel = TRANSLATION_MAP['Add Another Comment']; + var $add = $('
{0}
'.format(addlabel)); + $comment_div.append($add); + $add.children('.add-button').click(function(e) { + comment_div_state($comment_div, f_path, line_no, true); + }); + } else { comment_div_state($comment_div, f_path, line_no, true); - }); + } } // append a comment form to $comment_div @@ -695,22 +699,28 @@ e.preventDefault(); var text = $textarea.val(); - if (!text){ - return; + var review_status = $form.find('input:radio[name=changeset_status]:checked').val(); + var pr_close = $form.find('input:checkbox[name=save_close]:checked').length ? 'on' : ''; + + if (!text && !review_status && !pr_close) { + alert("Please provide a comment"); + return false; } $form.find('.submitting-overlay').show(); + var postData = { + 'text': text, + 'f_path': f_path, + 'line': line_no, + 'changeset_status': review_status, + 'save_close': pr_close + }; var success = function(json_data) { $comment_div.append(json_data['rendered_text']); comment_div_state($comment_div, f_path, line_no, false); linkInlineComments($('.firstlink'), $('.comment:first-child')); }; - var postData = { - 'text': text, - 'f_path': f_path, - 'line': line_no - }; ajaxPOST(AJAX_COMMENT_URL, postData, success); }); diff -r b3ddd87f214f -r 7834f845505a kallithea/templates/changeset/changeset.html --- a/kallithea/templates/changeset/changeset.html Wed Jan 20 01:47:11 2016 +0100 +++ b/kallithea/templates/changeset/changeset.html Wed Jan 20 01:47:11 2016 +0100 @@ -203,8 +203,7 @@ ${comment.generate_comments()} ## main comment form and it status - ${comment.comments(h.url('changeset_comment', repo_name=c.repo_name, revision=c.changeset.raw_id), - h.changeset_status(c.db_repo, c.changeset.raw_id))} + ${comment.comments()} ## FORM FOR MAKING JS ACTION AS CHANGESET COMMENTS diff -r b3ddd87f214f -r 7834f845505a kallithea/templates/pullrequests/pullrequest_show.html --- a/kallithea/templates/pullrequests/pullrequest_show.html Wed Jan 20 01:47:11 2016 +0100 +++ b/kallithea/templates/pullrequests/pullrequest_show.html Wed Jan 20 01:47:11 2016 +0100 @@ -369,10 +369,7 @@ ${comment.generate_comments()} ## main comment 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_voting_result, - is_pr=True, change_status=c.allowed_to_change_status)} + ${comment.comments(change_status=c.allowed_to_change_status)}