85b4ae69ded2 webpy-sucks

Use the new annotated diff functionality to fix the changeset web UI.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 03 Mar 2010 19:32:03 -0500
parents ddea94e8e138
children 12301b2a5461
branches/tags webpy-sucks
files review/web_templates/changeset.html

Changes

--- a/review/web_templates/changeset.html	Wed Mar 03 18:55:40 2010 -0500
+++ b/review/web_templates/changeset.html	Wed Mar 03 19:32:03 2010 -0500
@@ -38,7 +38,7 @@
 
     <h2>Files</h2>
     
-    {% for filename, diff in rcset.diffs().iteritems() %}
+    {% for filename in rcset.files() %}
         <div class="file-review">
             <div class="filename-header">
                 <a class="fold-file" href="">&nbsp;&nbsp;&nbsp;&darr;</a>
@@ -77,97 +77,69 @@
                     </form>
                 </div>
                 
+                
                 <div class="diff">
                     <table>
-                        {% set max_line = diff['max'] %}
-                        {% set content = diff['content'] %}
-                        {% set line_level_comments = rcset.line_level_comments(filename) %}
-                        {% set previous_n = -1 %}
+                        {% set annotated_diff = rcset.annotated_diff(filename) %}
+                        {# We need to ignore the first item from this generator, because
+                           we don't care about providing a line-number prefix (for now!). #}
+                        {% set ignore_this_variable = annotated_diff.next() %}
                         
-                        {% for n, line in content %}
-                            {% if n - 1 < previous_n %}
-                                {% set skipped_count = n - previous_n %}
-                                {% if previous_n == -1 %}
-                                    {% set skipped_count = skipped_count - 1 %}
-                                {% endif %}
+                        {% for line in annotated_diff %}
+                            {% if line['skipped'] %}
                                 <tr class="skipped">
-                                    <td><code>&hellip; skipped {{ skipped_count }} lines &hellip;</code></td>
+                                    <td><code>&hellip; skipped {{ line['skipped'] }} lines &hellip;</code></td>
+                                </tr>
+                                {% for comment in line['comments'] %}
+                                    <tr><td class="comment">
+                                        <div class="avatar"><img height="52" width="52" src="{{ utils['comment_gravatar'](comment) }}?s=52"/></div>
+                                        <div>
+                                            <div class="author">
+                                                <a href="mailto:{{ utils['email'](comment.author) }}">
+                                                    {{ utils['templatefilters'].person(comment.author) }}
+                                                </a>
+                                                said (on a skipped line):
+                                            </div>
+                                            <div class="message">{{ comment.message|escape }}</div>
+                                        </div>
+                                    </td></tr>
+                                {% endfor %}
+                            {% else %}
+                                <tr class="{{ utils['line_type'](line['content']) }}">
+                                    <td class="diff-line"><code>{{ line['content'][1:]|escape }}</code></td>
+                                    {% for comment in line['comments'] %}
+                                        <tr><td class="comment">
+                                            <div class="avatar"><img height="52" width="52" src="{{ utils['comment_gravatar'](comment) }}?s=52"/></div>
+                                            <div>
+                                                <div class="author">
+                                                    <a href="mailto:{{ utils['email'](comment.author) }}">
+                                                        {{ utils['templatefilters'].person(comment.author) }}
+                                                    </a>
+                                                    said:
+                                                </div>
+                                                <div class="message">{{ comment.message }}</div>
+                                            </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="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 %}
-                            
-                            {% for comment in utils['skipped_comments'](n, previous_n, line_level_comments) %}
-                                <tr><td class="comment">
-                                    <div class="avatar"><img height="52" width="52" src="{{ utils['comment_gravatar'](comment) }}?s=52"/></div>
-                                    <div>
-                                        <div class="author">
-                                            <a href="mailto:{{ utils['email'](comment.author) }}">
-                                                {{ utils['templatefilters'].person(comment.author) }}
-                                            </a>
-                                            said (on a skipped line):
-                                        </div>
-                                        <div class="message">{{ comment.message }}</div>
-                                    </div>
-                                </td></tr>
-                            {% endfor %}
-                            
-                            <tr class="{{ utils['line_type'](line) }}">
-                                <td class="diff-line"><code>{{ line[1:] }}</code></td>
-                            </tr>
-                            
-                            {% for comment in utils['line_comments'](n, line_level_comments) %}
-                                <tr><td class="comment">
-                                    <div class="avatar"><img height="52" width="52" src="{{ utils['comment_gravatar'](comment) }}?s=52"/></div>
-                                    <div>
-                                        <div class="author">
-                                            <a href="mailto:{{ utils['email'](comment.author) }}">
-                                                {{ utils['templatefilters'].person(comment.author) }}
-                                            </a>
-                                            said:
-                                        </div>
-                                        <div class="message">{{ comment.message }}</div>
-                                    </div>
-                                </td></tr>
-                            {% endfor %}
-                            
-                            <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="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="{{ n }}" />
-                                    </form>
-                                </td>
-                            </tr>
-                            
-                            {% set previous_n = n %}
                         {% endfor %}
-                        
-                        {% if previous_n < max_line %}
-                            <tr class="skipped">
-                                <td><code>&hellip; skipped {{ max_line - previous_n }} lines &hellip;</code></td>
-                            </tr>
-                            
-                            {% for comment in utils['skipped_comments_end'](previous_n, max_line, line_level_comments) %}
-                                <tr><td class="comment">
-                                    <div class="avatar"><img height="52" width="52" src="{{ utils['comment_gravatar'](comment) }}?s=52"/></div>
-                                    <div>
-                                        <div class="author">
-                                            <a href="mailto:{{ utils['email'](comment.author) }}">
-                                                {{ utils['templatefilters'].person(comment.author) }}
-                                            </a>
-                                            said (on a skipped line):
-                                        </div>
-                                        <div class="message">{{ comment.message }}</div>
-                                    </div>
-                                </td></tr>
-                            {% endfor %}
-                        {% endif %}
                     </table>
                 </div>
             </div>