changeset 4361:348ecbd25577

pull requests: show links to next/previous comment - don't get lost navigating huge PRs
author Mads Kiilerich <madski@unity3d.com>
date Fri, 18 Jul 2014 18:47:02 +0200
parents 05af189da2ae
children 79eb3211cda1
files kallithea/public/css/style.css kallithea/public/js/base.js kallithea/templates/changeset/changeset.html kallithea/templates/changeset/changeset_file_comment.html kallithea/templates/pullrequests/pullrequest_show.html kallithea/tests/functional/test_changeset_comments.py
diffstat 6 files changed, 54 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/public/css/style.css	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/public/css/style.css	Fri Jul 18 18:47:02 2014 +0200
@@ -4450,7 +4450,9 @@
     margin: 0.5em 0px !important;
 }
 
-.comments .comments-number {
+.comments .comments-number,
+.pr-comments-number {
+    margin: 5px;
     padding: 0px 0px 10px 0px;
     font-weight: bold;
     color: #666;
@@ -5082,6 +5084,13 @@
     margin: -2px;
 }
 
+div.prev-next-comment div.prev-comment,
+div.prev-next-comment div.next-comment {
+    display: inline-block;
+    min-width: 150px;
+    margin: 3px 6px;
+}
+
 #help_kb {
     display: none;
 }
--- a/kallithea/public/js/base.js	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/public/js/base.js	Fri Jul 18 18:47:02 2014 +0200
@@ -814,7 +814,9 @@
         $after_tr = $after_tr.next();
     }
     // put in the comment at the bottom
-    $after_tr.after(_table_tr('inline-comments', html));
+    var $tr = _table_tr('inline-comments', html)
+    $tr.find('div.comment').addClass('inline-comment');
+    $after_tr.after($tr);
 
     // scan nodes, and attach add button to last one
     _placeAddButton($line_tr);
@@ -862,6 +864,36 @@
     }
 }
 
+/**
+ * Double link comments
+ */
+var linkInlineComments = function(firstlinks, comments){
+    var $comments = $(comments);
+    if ($comments.length > 0) {
+        $(firstlinks).html('<a href="#{0}">First comment</a>'.format($comments.attr('id')));
+    }
+    if ($comments.length <= 1) {
+        return;
+    }
+
+    $comments.each(function(i, e){
+            var prev = '';
+            if (i > 0){
+                var prev_anchor = YUD.getAttribute(comments.item(i-1),'id');
+                prev = '<a href="#{0}">Previous comment</a>'.format(prev_anchor);
+            }
+            var next = '';
+            if (i+1 < comments.length){
+                var next_anchor = YUD.getAttribute(comments.item(i+1),'id');
+                next = '<a href="#{0}">Next comment</a>'.format(next_anchor);
+            }
+            var $div = $(('<div class="prev-next-comment">'+
+                          '<div class="prev-comment">{0}</div>'+
+                          '<div class="next-comment">{1}</div>').format(prev, next));
+            $div.prependTo(this);
+        });
+}
+
 /* activate files.html stuff */
 var fileBrowserListeners = function(current_url, node_list_url, url_base){
     var current_url_branch = "?branch=__BRANCH__";
--- a/kallithea/templates/changeset/changeset.html	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/templates/changeset/changeset.html	Fri Jul 18 18:47:02 2014 +0200
@@ -64,7 +64,7 @@
                   ${c.ignorews_url(request.GET)}
                   ${c.context_url(request.GET)}
                 </div>
-                <div class="comments-number" style="float:right;padding-right:5px">${ungettext("%d comment", "%d comments", len(c.comments)) % len(c.comments)} ${ungettext("(%d inline)", "(%d inline)", c.inline_cnt) % c.inline_cnt}</div>
+                <div class="comments-number" style="float:right;padding-right:5px">${ungettext("%d comment", "%d comments", len(c.comments)) % len(c.comments)} ${ungettext("(%d inline)", "(%d inline)", c.inline_cnt) % c.inline_cnt} <span class="firstlink"></span> </div>
             </div>
         </div>
         <div id="changeset_content">
@@ -197,6 +197,8 @@
           var file_comments = YUQ('.inline-comment-placeholder');
           renderInlineComments(file_comments);
 
+          linkInlineComments(document.getElementsByClassName('firstlink'), document.getElementsByClassName("inline-comment"));
+
           pyroutes.register('changeset_home',
                             "${h.url('changeset_home', repo_name='%(repo_name)s', revision='%(revision)s')}",
                             ['repo_name', 'revision']);
--- a/kallithea/templates/changeset/changeset_file_comment.html	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/templates/changeset/changeset_file_comment.html	Fri Jul 18 18:47:02 2014 +0200
@@ -108,7 +108,7 @@
 
 ## 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>
+    <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} <span class="firstlink"></span> </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))}">
--- a/kallithea/templates/pullrequests/pullrequest_show.html	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/templates/pullrequests/pullrequest_show.html	Fri Jul 18 18:47:02 2014 +0200
@@ -255,6 +255,7 @@
                     </div>
                 %endfor
               </div>
+              <div class="comments-number pr-comments-number">${ungettext("%d comment", "%d comments", len(c.comments)) % len(c.comments)} ${ungettext("(%d inline)", "(%d inline)", c.inline_cnt) % c.inline_cnt} <span class="firstlink"></span> </div>
               % if c.limited_diff:
                 <h5>${_('Changeset was too big and was cut off...')} <a href="${h.url.current(fulldiff=1, **request.GET.mixed())}">${_('Show full diff anyway')}</a></h5>
               % endif
@@ -329,6 +330,8 @@
           var file_comments = YUQ('.inline-comment-placeholder');
           renderInlineComments(file_comments);
 
+          linkInlineComments(document.getElementsByClassName('firstlink'), document.getElementsByClassName("inline-comment"));
+
           YUE.on(YUD.get('update_pull_request'),'click',function(e){
               updateReviewers(undefined, "${c.repo_name}", "${c.pull_request.pull_request_id}");
           })
--- a/kallithea/tests/functional/test_changeset_comments.py	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/tests/functional/test_changeset_comments.py	Fri Jul 18 18:47:02 2014 +0200
@@ -42,7 +42,7 @@
         # test DB
         self.assertEqual(ChangesetComment.query().count(), 1)
         response.mustcontain('''<div class="comments-number">%s comment '''
-                             '''(0 inline)</div>''' % 1)
+                             '''(0 inline)''' % 1)
 
         self.assertEqual(Notification.query().count(), 1)
         self.assertEqual(ChangesetComment.query().count(), 1)
@@ -78,7 +78,7 @@
         self.assertEqual(ChangesetComment.query().count(), 1)
         response.mustcontain(
             '''<div class="comments-number">0 comments'''
-            ''' (%s inline)</div>''' % 1
+            ''' (%s inline)''' % 1
         )
         response.mustcontain(
             '''<div style="display:none" class="inline-comment-placeholder" '''
@@ -117,7 +117,7 @@
         # test DB
         self.assertEqual(ChangesetComment.query().count(), 1)
         response.mustcontain('''<div class="comments-number">%s '''
-                             '''comment (0 inline)</div>''' % 1)
+                             '''comment (0 inline)''' % 1)
 
         self.assertEqual(Notification.query().count(), 2)
         users = [x.user.username for x in UserNotification.query().all()]
@@ -150,4 +150,4 @@
         response = self.app.get(url(controller='changeset', action='index',
                                 repo_name=HG_REPO, revision=rev))
         response.mustcontain('''<div class="comments-number">0 comments'''
-                             ''' (0 inline)</div>''')
+                             ''' (0 inline)''')