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 56 insertions and 26 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/changeset.py
Show inline comments
 
@@ -217,16 +217,16 @@ class ChangesetController(BaseRepoContro
 
            c.statuses.extend([ChangesetStatusModel()\
 
                              .get_status(c.rhodecode_db_repo.repo_id,
 
                                          changeset.raw_id)])
 

	
 
            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:
 
                changeset_parent = changeset.parents[0]
 
            except IndexError:
 
                changeset_parent = None
 
@@ -292,13 +292,13 @@ class ChangesetController(BaseRepoContro
 
            for node in changeset.removed:
 
                c.changes[changeset.raw_id].append(
 
                    ('removed', node, None, None, None, (0, 0))
 
                )
 

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

	
 
        if len(c.cs_ranges) == 1:
 
            c.changeset = c.cs_ranges[0]
 
            c.changes = c.changes[c.changeset.raw_id]
rhodecode/model/comment.py
Show inline comments
 
@@ -132,27 +132,50 @@ class ChangesetCommentsModel(BaseModel):
 
        """
 
        comment = self.__get_changeset_comment(comment)
 
        self.sa.delete(comment)
 

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

	
 
        for co in comments:
 
            paths[co.f_path][co.line_no].append(co)
 
        return paths.items()
rhodecode/templates/changeset/changeset.html
Show inline comments
 
@@ -131,14 +131,16 @@
 
    ${diff_block.diff_block(c.changes)}
 

	
 
    ## template for inline comment form
 
    <%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)}";
 
    	  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';
 
@@ -163,20 +165,12 @@
 
          });
 

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

	
 
    </div>
 
</%def>
rhodecode/templates/changeset/changeset_file_comment.html
Show inline comments
 
@@ -74,13 +74,14 @@
 
  %endif
 
  </div>
 
</div>
 
</%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():
 
            <div style="display:none" class="inline-comment-placeholder" path="${path}" target_id="${h.safeid(h.safe_unicode(path))}">
 
            %for co in comments:
 
                ${comment_block(co)}
 
@@ -89,27 +90,28 @@
 
        %endfor
 
    %endfor
 

	
 
</%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:
 
        <div id="comment-tr-${co.comment_id}">
 
          ${comment_block(co)}
 
        </div>
 
    %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">
 
                ${(_('Comments parsed using %s syntax with %s support.') % (('<a href="%s">RST</a>' % h.url('rst_help')),
 
          		'<span style="color:#003367" class="tooltip" title="%s">@mention</span>' %
 
          		_('Use @username inside this text to send notification to this RhodeCode user')))|n}
 
@@ -117,13 +119,13 @@
 
                  <input style="vertical-align: bottom;margin-bottom:-2px" id="show_changeset_status_box" type="checkbox" name="change_changeset_status" />
 
                  </span> 
 
            </div>
 
            <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>                 
 
            <div class="mentions-container" id="mentions_container"></div>
 
             ${h.textarea('text')}
 
        </div>
 
@@ -134,9 +136,20 @@
 
    </div>
 
    %endif
 
</div>
 
<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)