[PATCH 7 of 8 v2] frontend: change comment workflow

Jan Heylen heyleke at gmail.com
Sat May 16 08:02:32 EDT 2015


# HG changeset patch
# User Jan Heylen <heyleke at gmail.com>
# Date 1431758388 -7200
#      Sat May 16 08:39:48 2015 +0200
# Node ID f119d10ce90f342131b52a3751e697236523f413
# Parent  c2694f3dbb9202e979bc342ca5e60ae83e7c0591
frontend: change comment workflow

This changes the workflow from one-comment-at-a-time to giving-draft-comments-and-a-final-judgement.
Only after the final judgement, the drafts are changed into comments and an email notification is send.
The internal notification model is untouched.

diff -r c2694f3dbb92 -r f119d10ce90f kallithea/config/routing.py
--- a/kallithea/config/routing.py	Thu May 07 20:29:15 2015 +0200
+++ b/kallithea/config/routing.py	Sat May 16 08:39:48 2015 +0200
@@ -662,6 +662,16 @@
                 controller='changeset', action='preview_comment',
                 conditions=dict(function=check_repo, method=["POST"]))
 
+    rmap.connect('changeset_comment_draft',
+                 '/{repo_name:.*?}/changeset-comment-draft/{revision}',
+                controller='changeset', revision='tip', action='draft',
+                conditions=dict(function=check_repo, method=["POST"]))
+
+    rmap.connect('pullrequest_comment_draft',
+                 '/{repo_name:.*?}/pullrequest-comment-draft/{pull_request_id}',
+                controller='changeset', action='draft',
+                conditions=dict(function=check_repo, method=["POST"]))
+
     rmap.connect('changeset_comment_delete',
                  '/{repo_name:.*?}/changeset-comment-delete/{comment_id}',
                 controller='changeset', action='delete_comment',
diff -r c2694f3dbb92 -r f119d10ce90f kallithea/public/js/base.js
--- a/kallithea/public/js/base.js	Thu May 07 20:29:15 2015 +0200
+++ b/kallithea/public/js/base.js	Sat May 16 08:39:48 2015 +0200
@@ -705,6 +705,7 @@
         $('#edit-btn_'+lineno).show();
         $('#preview-container_'+lineno).show();
         $('#preview-btn_'+lineno).hide();
+        $('#draft-btn_'+lineno).hide();
 
         var url = pyroutes.url('changeset_comment_preview', {'repo_name': REPO_NAME});
         var post_data = {'text': text};
@@ -713,11 +714,37 @@
             $('#preview-box_'+lineno).removeClass('unloaded');
         })
     })
+    $('#draft-btn_'+lineno).click(function(e){
+        var text = $('#text_'+lineno).val();
+        if(!text){
+            return
+        }
+        $('#preview-box_'+lineno).addClass('unloaded');
+        $('#preview-box_'+lineno).html(_TM['Loading ...']);
+        $('#edit-container_'+lineno).hide();
+        $('#edit-btn_'+lineno).show();
+        $('#preview-container_'+lineno).show();
+        $('#draft-btn_'+lineno).hide();
+        $('#preview-btn_'+lineno).hide();
+
+        var url = AJAX_DRAFT_URL;
+        var post_data = {
+                'text': text,
+                'f_path': f_path,
+                'line': lineno
+        };
+        ajaxPOST(url, post_data, function(json_data){
+            $tr.removeClass('form-open');
+            $form.remove();
+            _renderInlineComment(json_data);
+        })
+    })
     $('#edit-btn_'+lineno).click(function(e){
         $('#edit-container_'+lineno).show();
         $('#edit-btn_'+lineno).hide();
         $('#preview-container_'+lineno).hide();
         $('#preview-btn_'+lineno).show();
+        $('#draft-btn_'+lineno).show();
     })
 
     setTimeout(function(){
diff -r c2694f3dbb92 -r f119d10ce90f kallithea/templates/changeset/changeset.html
--- a/kallithea/templates/changeset/changeset.html	Thu May 07 20:29:15 2015 +0200
+++ b/kallithea/templates/changeset/changeset.html	Sat May 16 08:39:48 2015 +0200
@@ -28,6 +28,7 @@
     var _GROUPS_AC_DATA = ${c.user_groups_array|n};
     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__')}";
+    AJAX_DRAFT_URL = "${url('changeset_comment_draft',repo_name=c.repo_name,revision=c.changeset.raw_id)}";
     </script>
     <div class="table">
         <div class="diffblock">
diff -r c2694f3dbb92 -r f119d10ce90f kallithea/templates/changeset/changeset_file_comment.html
--- a/kallithea/templates/changeset/changeset_file_comment.html	Thu May 07 20:29:15 2015 +0200
+++ b/kallithea/templates/changeset/changeset_file_comment.html	Sat May 16 08:39:48 2015 +0200
@@ -17,10 +17,18 @@
           <span>
               ${h.age(co.modified_at)}
               %if co.pull_request:
-                ${_('on pull request')}
+                %if co.draft:
+                  ${_('draft comment on pull request')}
+                %else:
+                  ${_('on pull request')}
+                %endif
                 <a href="${co.pull_request.url()}">"${co.pull_request.title or _("No title")}"</a>
               %else:
-                ${_('on this changeset')}
+                %if co.draft:
+                  ${_('draft comment on this changeset')}
+                %else:
+                  ${_('on this changeset')}
+                %endif
               %endif
               <a class="permalink" href="#comment-${co.comment_id}">¶</a>
           </span>
@@ -74,8 +82,9 @@
         <div class="submitting-overlay">${_('Submitting ...')}</div>
         <input type="hidden" name="f_path" value="{0}">
         <input type="hidden" name="line" value="{1}">
-        ${h.submit('save', _('Comment'), class_='btn btn-small save-inline-form')}
+        <!-- ${h.submit('save', _('Comment'), class_='btn btn-small save-inline-form')} -->
         ${h.reset('hide-inline-form', _('Cancel'), class_='btn btn-small hide-inline-form')}
+        <div id="draft-btn_{1}" class="draft-btn btn btn-small">${_('Save')}</div>
         <div id="preview-btn_{1}" class="preview-btn btn btn-small">${_('Preview')}</div>
         <div id="edit-btn_{1}" class="edit-btn btn btn-small" style="display:none">${_('Edit')}</div>
       </div>
@@ -121,6 +130,16 @@
             </div>
         %endfor
     %endfor
+    %for path, lines in c.drafts:
+        % 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)}
+            %endfor
+            </div>
+        %endfor
+    %endfor
+
 
 </%def>
 
@@ -133,7 +152,11 @@
     </div>
 
     %for co in c.comments:
+        %if co.draft:
+        <div id="draft-tr-${co.comment_id}">
+        %else:
         <div id="comment-tr-${co.comment_id}">
+        %endif
           ${comment_block(co)}
         </div>
     %endfor
@@ -191,7 +214,7 @@
         </div>
 
         <div class="comment-button">
-            ${h.submit('save', _('Comment'), class_="btn")}
+            ${h.submit('save', _('Commit All Comments'), class_="btn")}
             <div id="preview-btn" class="preview-btn btn">${_('Preview')}</div>
             <div id="edit-btn" class="edit-btn btn" style="display:none">${_('Edit')}</div>
         </div>
diff -r c2694f3dbb92 -r f119d10ce90f kallithea/templates/pullrequests/pullrequest_show.html
--- a/kallithea/templates/pullrequests/pullrequest_show.html	Thu May 07 20:29:15 2015 +0200
+++ b/kallithea/templates/pullrequests/pullrequest_show.html	Sat May 16 08:39:48 2015 +0200
@@ -22,7 +22,11 @@
   <div class="title">
     ${self.breadcrumbs()}
   </div>
-
+    <script>
+    AJAX_COMMENT_URL = "${url('changeset_comment',repo_name=c.repo_name,pull_request=c.pull_request.pull_request_id)}";
+    AJAX_COMMENT_DELETE_URL = "${url('changeset_comment_delete',repo_name=c.repo_name,comment_id='__COMMENT_ID__')}";
+    AJAX_DRAFT_URL = "${url('pullrequest_comment_draft',repo_name=c.repo_name,pull_request_id=c.pull_request.pull_request_id)}";
+    </script>
   ${h.form(url('pullrequest_post', repo_name=c.repo_name, pull_request_id=c.pull_request.pull_request_id), method='post', id='pull_request_form')}
     <div class="form pr-box" style="float: left">
       <div class="pr-details-title ${'closed' if c.pull_request.is_closed() else ''}">


More information about the kallithea-general mailing list