f841259cc87e

Move the individual line comment forms into comments.js.

This *massively* improves performance on large diffs.  For example, the review
page for the changeset where I added CherryPy as a bundled app was 38.7mb
before this changeset.  With this change it is now 13.2mb.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 27 Mar 2010 13:03:00 -0400
parents 048ef4889301
children 45cd1e619896
branches/tags (none)
files review/web_media/comments.js review/web_media/style.css review/web_templates/changeset.html

Changes

--- a/review/web_media/comments.js	Sat Mar 27 12:22:04 2010 -0400
+++ b/review/web_media/comments.js	Sat Mar 27 13:03:00 2010 -0400
@@ -11,7 +11,28 @@
     
     $("tr.rem.commentable,tr.add.commentable,tr.con.commentable").click(function(event) {
         $(event.target).closest("tr").addClass("comment-line-selected");
-        $(event.target).closest("tr").nextAll("tr.comment-line").first().fadeIn("fast");
+        var filename = $(event.target).closest("tr").find(".line-data").children(".filename").first().text();
+        var linenumber = $(event.target).closest("tr").find(".line-data").children(".linenumber").first().html();
+        
+        var comment_form = '<tr class="comment-line">\n\
+                <td>\n\
+                    <form id="comment-line-form" method="post" action="">\n\
+                        <div class="field">\n\
+                            <label for="body">Add a comment on this line:</label>\n\
+                            <textarea cols="60" rows="6" name="new-comment-body"></textarea>\n\
+                        </div>\n\
+                        <div class="buttons">\n\
+                            <input type="submit" class="button" value="Submit" />\n\
+                        </div>\n\
+                        <input type="hidden" name="filename" value="<<<FILENAME>>>" />\n\
+                        <input type="hidden" name="lines" value="<<<LINENUMBER>>>" />\n\
+                    </form>\n\
+                </td>\n\
+            </tr>';
+        comment_form = comment_form.replace('<<<FILENAME>>>', filename);
+        comment_form = comment_form.replace('<<<LINENUMBER>>>', linenumber);
+        
+        $(event.target).closest("tr").after(comment_form);
         return false;
     });
 
--- a/review/web_media/style.css	Sat Mar 27 12:22:04 2010 -0400
+++ b/review/web_media/style.css	Sat Mar 27 13:03:00 2010 -0400
@@ -163,15 +163,18 @@
 div.diff table tr.comment-line {
     white-space: normal;
 }
-table tr.add {
+div.diff table tr.add {
     background: #DBF3D1;
 }
-table tr.rem {
+div.diff table tr.rem {
     background: #FBDBDA;
 }
-table tr.skipped {
+div.diff table tr.skipped {
     background: #ccc;
 }
+div.diff table tr td.diff-line div.line-data {
+    display: none;
+}
 div.diff .comment {
     margin-bottom: 0em;
-}
\ No newline at end of file
+}
--- a/review/web_templates/changeset.html	Sat Mar 27 12:22:04 2010 -0400
+++ b/review/web_templates/changeset.html	Sat Mar 27 13:03:00 2010 -0400
@@ -125,7 +125,7 @@
                                     {% endfor %}
                                 {% else %}
                                     <tr class="{{ utils['line_type'](line['content']) }}{% if not read_only %} commentable {% endif %}">
-                                        <td class="diff-line"><code>{{ line['number'] }}: {{ line['content'][1:]|escape }}</code></td>
+                                        <td class="diff-line"><div class="line-data"><span class="linenumber">{{ line['number'] }}</span><span class="filename">{{ filename }}</span></div><code>{{ line['number'] }}: {{ line['content'][1:]|escape }}</code></td>
                                         {% for comment in line['comments'] %}
                                             <tr><td class="comment">
                                                 {{ macros.gravatar(comment, utils) }}
@@ -140,20 +140,6 @@
                                                 </div>
                                             </td></tr>
                                         {% endfor %}
-                                    </tr><tr class="comment-line">
-                                        <td>
-                                            <form id="comment-line-form" method="post" action="">
-                                                <div class="field">
-                                                    <label for="body">Add a comment on this line:</label>
-                                                    <textarea cols="60" rows="6" name="new-comment-body"></textarea>
-                                                </div>
-                                                <div class="buttons">
-                                                    <input type="submit" class="button" value="Submit" />
-                                                </div>
-                                                <input type="hidden" name="filename" value="{{ filename }}" />
-                                                <input type="hidden" name="lines" value="{{ line['number'] }}" />
-                                            </form>
-                                        </td>
                                     </tr>
                                 {% endif %}
                             {% endfor %}