Mercurial > kallithea
changeset 2439:ad19dfcdb1cc codereview
Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 10 Jun 2012 16:44:06 +0200 |
parents | 471ac5256400 |
children | 1bc579bcd67a |
files | rhodecode/controllers/changeset.py rhodecode/model/comment.py rhodecode/templates/changeset/changeset.html rhodecode/templates/changeset/changeset_file_comment.html |
diffstat | 4 files changed, 57 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/controllers/changeset.py Sun Jun 10 16:39:52 2012 +0200 +++ b/rhodecode/controllers/changeset.py Sun Jun 10 16:44:06 2012 +0200 @@ -220,10 +220,10 @@ c.comments.extend(ChangesetCommentsModel()\ .get_comments(c.rhodecode_db_repo.repo_id, - changeset.raw_id)) + revision=changeset.raw_id)) inlines = ChangesetCommentsModel()\ .get_inline_comments(c.rhodecode_db_repo.repo_id, - changeset.raw_id) + revision=changeset.raw_id) c.inline_comments.extend(inlines) c.changes[changeset.raw_id] = [] try: @@ -295,7 +295,7 @@ ) # count inline comments - for path, lines in c.inline_comments: + for _, lines in c.inline_comments: for comments in lines.values(): c.inline_cnt += len(comments)
--- a/rhodecode/model/comment.py Sun Jun 10 16:39:52 2012 +0200 +++ b/rhodecode/model/comment.py Sun Jun 10 16:44:06 2012 +0200 @@ -135,21 +135,44 @@ return comment - def get_comments(self, repo_id, revision): - return ChangesetComment.query()\ + def get_comments(self, repo_id, revision=None, pull_request_id=None): + """ + Get's main comments based on revision or pull_request_id + + :param repo_id: + :type repo_id: + :param revision: + :type revision: + :param pull_request_id: + :type pull_request_id: + """ + q = ChangesetComment.query()\ .filter(ChangesetComment.repo_id == repo_id)\ - .filter(ChangesetComment.revision == revision)\ .filter(ChangesetComment.line_no == None)\ - .filter(ChangesetComment.f_path == None).all() + .filter(ChangesetComment.f_path == None) + if revision: + q = q.filter(ChangesetComment.revision == revision) + elif pull_request_id: + q = q.filter(ChangesetComment.pull_request_id == pull_request_id) + else: + raise Exception('Please specify revision or pull_request_id') + return q.all() - def get_inline_comments(self, repo_id, revision): - comments = self.sa.query(ChangesetComment)\ + def get_inline_comments(self, repo_id, revision=None, pull_request_id=None): + q = self.sa.query(ChangesetComment)\ .filter(ChangesetComment.repo_id == repo_id)\ - .filter(ChangesetComment.revision == revision)\ .filter(ChangesetComment.line_no != None)\ .filter(ChangesetComment.f_path != None)\ .order_by(ChangesetComment.comment_id.asc())\ - .all() + + if revision: + q = q.filter(ChangesetComment.revision == revision) + elif pull_request_id: + q = q.filter(ChangesetComment.pull_request_id == pull_request_id) + else: + raise Exception('Please specify revision or pull_request_id') + + comments = q.all() paths = defaultdict(lambda: defaultdict(list))
--- a/rhodecode/templates/changeset/changeset.html Sun Jun 10 16:39:52 2012 +0200 +++ b/rhodecode/templates/changeset/changeset.html Sun Jun 10 16:44:06 2012 +0200 @@ -134,8 +134,10 @@ <%namespace name="comment" file="/changeset/changeset_file_comment.html"/> ${comment.comment_inline_form(c.changeset)} - ## render comments - ${comment.comments(c.changeset)} + ## 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))} + <script type="text/javascript"> YUE.onDOMReady(function(){ AJAX_COMMENT_URL = "${url('changeset_comment',repo_name=c.repo_name,revision=c.changeset.raw_id)}"; @@ -165,15 +167,7 @@ // inject comments into they proper positions var file_comments = YUQ('.inline-comment-placeholder'); renderInlineComments(file_comments); - - YUE.on(YUD.get('show_changeset_status_box'),'change',function(e){ - if(e.currentTarget.checked){ - YUD.setStyle('status_block_container','display',''); - } - else{ - YUD.setStyle('status_block_container','display','none'); - } - }) + }) </script>
--- a/rhodecode/templates/changeset/changeset_file_comment.html Sun Jun 10 16:39:52 2012 +0200 +++ b/rhodecode/templates/changeset/changeset_file_comment.html Sun Jun 10 16:44:06 2012 +0200 @@ -77,7 +77,8 @@ </%def> -<%def name="inlines(changeset)"> +## generates inlines taken from c.comments var +<%def name="inlines()"> <div class="comments-number">${ungettext("%d comment", "%d comments", len(c.comments)) % len(c.comments)} ${ungettext("(%d inline)", "(%d inline)", c.inline_cnt) % c.inline_cnt}</div> %for path, lines in c.inline_comments: % for line,comments in lines.iteritems(): @@ -92,11 +93,12 @@ </%def> ## MAIN COMMENT FORM -<%def name="comments(changeset)"> +<%def name="comments(post_url, cur_status)"> <div class="comments"> <div id="inline-comments-container"> - ${inlines(changeset)} + ## generate inlines for this changeset + ${inlines()} </div> %for co in c.comments: @@ -106,7 +108,7 @@ %endfor %if c.rhodecode_user.username != 'default': <div class="comment-form ac"> - ${h.form(h.url('changeset_comment', repo_name=c.repo_name, revision=changeset.raw_id))} + ${h.form(post_url)} <strong>${_('Leave a comment')}</strong> <div class="clearfix"> <div class="comment-help"> @@ -120,7 +122,7 @@ <div id="status_block_container" class="status-block" style="display:none"> %for status,lbl in c.changeset_statuses: <div class=""> - <img src="${h.url('/images/icons/flag_status_%s.png' % status)}" /> <input ${'checked="checked"' if status == h.changeset_status(c.rhodecode_db_repo, c.changeset.raw_id) else ''}" type="radio" name="changeset_status" value="${status}"> <label>${lbl}</label> + <img src="${h.url('/images/icons/flag_status_%s.png' % status)}" /> <input ${'checked="checked"' if status == cur_status else ''}" type="radio" name="changeset_status" value="${status}"> <label>${lbl}</label> </div> %endfor </div> @@ -137,6 +139,17 @@ <script> YUE.onDOMReady(function () { MentionsAutoComplete('text', 'mentions_container', _USERS_AC_DATA, _GROUPS_AC_DATA); + + // changeset status box listener + YUE.on(YUD.get('show_changeset_status_box'),'change',function(e){ + if(e.currentTarget.checked){ + YUD.setStyle('status_block_container','display',''); + } + else{ + YUD.setStyle('status_block_container','display','none'); + } + }) + }); </script> </%def>