Changeset - ad19dfcdb1cc
[Not reviewed]
codereview
0 4 0
Marcin Kuzminski - 13 years ago 2012-06-10 16:44:06
marcin@python-works.com
Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
4 files changed with 57 insertions and 27 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/changeset.py
Show inline comments
 
@@ -220,10 +220,10 @@ class ChangesetController(BaseRepoContro
 

	
 
            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 @@ class ChangesetController(BaseRepoContro
 
                )
 

	
 
        # 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)
 

	
rhodecode/model/comment.py
Show inline comments
 
@@ -135,21 +135,44 @@ class ChangesetCommentsModel(BaseModel):
 

	
 
        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))
 

	
rhodecode/templates/changeset/changeset.html
Show inline comments
 
@@ -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>
rhodecode/templates/changeset/changeset_file_comment.html
Show inline comments
 
@@ -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>
0 comments (0 inline, 0 general)