MozReview: replace diff_file_fragment (Bug 1248008) r?smacleod draft
authorPiotr Zalewa <pzalewa@mozilla.com>
Tue, 20 Sep 2016 11:46:57 +0200
changeset 139 3fef28bc63158b71e51c058b0993979af4b86af8
parent 138 e167fb6b273425b384dd0051f465e89f22f13127
child 140 45c0e8dbf0cf6378e2870f42f1e889d2bf1c1018
child 141 5479a8ba5937945c3a285dba8b4606b027a7b136
child 142 d79cb1b58f2c733e7838cf4a806cf982d38c81e3
push idunknown
push userunknown
push dateunknown
reviewerssmacleod
bugs1248008
MozReview: replace diff_file_fragment (Bug 1248008) r?smacleod MozReview-Commit-ID: DooNQcDtHRl
reviewboard/reviewboard/diffviewer/renderers.py
reviewboard/reviewboard/diffviewer/views.py
reviewboard/reviewboard/templates/diffviewer/diff_file_fragment_mozreview.html
--- a/reviewboard/reviewboard/diffviewer/renderers.py
+++ b/reviewboard/reviewboard/diffviewer/renderers.py
@@ -26,17 +26,17 @@ class DiffRenderer(object):
     The diff_file (from get_diff_files) is the only required parameter.
     The renderer may modify the contents of this, and should make a copy if
     it needs to be left untouched.
 
     Note that any of the render functions are meant to be called only once per
     DiffRenderer. It will alter the state of the renderer, possibly
     disrupting future render calls.
     """
-    default_template_name = 'diffviewer/diff_file_fragment.html'
+    default_template_name = 'diffviewer/diff_file_fragment_mozreview.html'
 
     def __init__(self, diff_file, chunk_index=None, highlighting=False,
                  collapse_all=True, lines_of_context=None, extra_context=None,
                  allow_caching=True, template_name=default_template_name):
         self.diff_file = diff_file
         self.chunk_index = chunk_index
         self.highlighting = highlighting
         self.collapse_all = collapse_all
--- a/reviewboard/reviewboard/diffviewer/views.py
+++ b/reviewboard/reviewboard/diffviewer/views.py
@@ -229,17 +229,17 @@ class DiffFragmentView(View):
     so must be passed either in the URL or in a subclass's definition of
     that method.
 
     The caller may also pass ``?lines-of-context=`` as a query parameter to
     the URL to indicate how many lines of context should be provided around
     the chunk.
     """
 
-    template_name = 'diffviewer/diff_file_fragment.html'
+    template_name = 'diffviewer/diff_file_fragment_mozreview.html'
     error_template_name = 'diffviewer/diff_fragment_error.html'
 
     def get(self, request, *args, **kwargs):
         """Handles GET requests for this view.
 
         This will create the renderer for the diff fragment, render it, and
         return it.
 
new file mode 100644
--- /dev/null
+++ b/reviewboard/reviewboard/templates/diffviewer/diff_file_fragment_mozreview.html
@@ -0,0 +1,255 @@
+{% load difftags i18n djblets_deco djblets_utils reviewtags static %}
+
+{% if standalone and error %}
+{{error}}
+{% endif %}
+
+{% definevar 'line_fmt' %}
+  <tr line="%(linenum_row)s"%(row_class_attr)s>
+{%  if not file.is_new_file %}
+   <th>%(anchor_html)s%(linenum1)s</th>
+   <td%(cell_1_class_attr)s>
+    %(moved_to_html)s
+    %(begin_collapse_html)s
+    <pre>%(line1)s</pre>
+    %(end_collapse_html)s
+   </td>
+{%  endif %}
+   <th>%(linenum2)s</th>
+   <td%(cell_2_class_attr)s>
+    %(moved_from_html)s
+    <pre>%(line2)s</pre>
+   </td>
+  </tr>
+{% enddefinevar %}
+
+{% definevar 'anchor_fmt' %}
+ <a name="%(anchor)s" class="chunk-anchor"></a>
+{% enddefinevar %}
+
+{% definevar 'begin_collapse_fmt' %}
+ <div class="collapse-floater">
+  <div class="diff-collapse-btn" title="{% trans "Collapse lines" %}"
+       data-chunk-index="%(chunk_index)s" data-lines-of-context="0">
+   <div class="rb-icon rb-icon-diff-collapse-chunk"></div>
+  </div>
+{% enddefinevar %}
+
+{% definevar 'end_collapse_fmt' %}
+</div>
+{% enddefinevar %}
+
+{% definevar 'moved_fmt' %}
+ <a href="#" class="%(class)s" data-line="%(line)s" target="%(target)s">%(text)s</a>
+{% enddefinevar %}
+
+{% if not standalone %}
+<table id="file{{file.filediff.id}}" class="{% spaceless %}
+  sidebyside
+  {% if file.is_new_file %}newfile{% endif %}
+  {% if file.binary %}diff-binary{% endif %}
+  {% if file.deleted %}diff-deleted{% endif %}
+  {% endspaceless %}"
+      data-lines-equal="{{equal_lines}}">
+ <colgroup>
+{%  if not file.is_new_file %}
+  <col class="line" />
+  <col class="left" />
+{%  endif %}
+  <col class="line" />
+  <col class="right" />
+ </colgroup>
+ <thead>
+  <tr class="filename-row">
+{%  if file.dest_filename == file.depot_filename %}
+   <th colspan="4">
+    <a name="{{file.index}}" class="file-anchor"></a>
+{%   if file.binary %}
+{%    if modified_diff_file_attachment %}
+    <img class="header-file-icon" src="{{modified_diff_file_attachment.icon_url}}" />
+{%    elif orig_diff_file_attachment %}
+    <img class="header-file-icon" src="{{orig_diff_file_attachment.icon_url}}" />
+{%    endif %}
+{%   endif %}
+    {{file.depot_filename}}
+  </th>
+{%  else %}
+{%   if not file.is_new_file %}
+   <th colspan="2"><a name="{{file.index}}" class="file-anchor"></a>{{ file.depot_filename }}</th>
+{%   endif %}
+   <th colspan="2">
+{%   if file.is_new_file %}
+    <a name="{{file.index}}" class="file-anchor"></a>
+{%   endif %}
+    {{file.dest_filename}}{% if file.moved %}{% trans " (moved)" %}{% elif file.copied %}{% trans " (copied)" %}{% endif %}</th>
+{%  endif %}{# file.dest_filename == file.depot_filename #}
+  </tr>
+  <tr class="revision-row">
+{%  if file.moved_or_copied and file.num_changes == 0 %}
+   <th colspan="4"></th>
+{%  else %}
+{%   if not file.is_new_file %}
+   <th></th>
+   <th class="revision-col">
+{%    if download_orig_url %}
+    <a class="rb-icon rb-icon-download download-link" href="{{download_orig_url}}" alt="{% trans 'Download' %}" title="{% trans 'Download' %}"></a>
+{%    endif %}
+    {{file.revision}}
+    </th>
+{%   endif %}
+   <th></th>
+{%   if not file.deleted %}
+   <th class="revision-col">
+{%    if download_modified_url %}
+    <a class="rb-icon rb-icon-download download-link" href="{{download_modified_url}}" alt="{% trans 'Download' %}" title="{% trans 'Download' %}"></a>
+{%    endif %}
+    {{file.dest_revision}}
+   </th>
+{%   else %}
+   <th></th>
+{%   endif %}
+{%  endif %}{# num_changes and moved #}
+  </tr>
+ </thead>
+{% endif %}{# not standalone #}
+
+{% if file.binary %}
+ <tbody class="binary" data-file-id="{{modified_diff_file_attachment.id}}">
+{%  if orig_diff_file_attachment or modified_diff_file_attachment %}
+  <tr class="inline-actions-header">
+{%   if file.moved_or_copied and file.num_changes == 0 or file.newfile and not orig_diff_file_attachment %}
+   <td colspan="4">
+{%   else %}
+   <td colspan="2">
+    <div class="inline-actions-container clearfix">
+     <ul class="actions inline-actions-left">
+     </ul>
+    </div>
+   </td>
+   <td colspan="2">
+{%   endif %}
+    <div class="inline-actions-container clearfix">
+     <ul class="actions inline-actions-right">
+{%   if modified_diff_file_attachment %}
+{%    if not modified_attachment_review_ui_html and not diff_attachment_review_ui_html %}
+{%     if modified_diff_file_attachment.review_ui %}
+      <li class="file-review"><a href="{% url 'file-attachment' modified_diff_file_attachment.get_review_request.display_id modified_diff_file_attachment.pk %}">{% trans "Review" %}</a></li>
+{%     else %}
+      <li class="file-add-comment"><a href="#">{% trans "New Comment" %}</a></li>
+{%     endif %}
+{%    endif %}
+{%   endif %}
+     </ul>
+    </div>
+  </tr>
+{%  endif %}
+  <tr class="inline-files-container">
+{%  if diff_attachment_review_ui_html %}
+  <td colspan="4" class="diff-review-ui">{{diff_attachment_review_ui_html}}</td>
+{%  else %}
+{%   if file.moved_or_copied and file.num_changes == 0 or file.newfile and not orig_diff_file_attachment %}
+   <td colspan="4">
+{%   else %}
+   <td colspan="2">
+{%    if not orig_diff_file_attachment %}
+{%     trans "This is a binary file. The content cannot be displayed." %}
+{%    elif orig_attachment_review_ui_html %}
+{{     orig_attachment_review_ui_html}}
+{%    elif orig_diff_file_attachment.thumbnail %}
+    <div class="file-thumbnail-container">{{orig_diff_file_attachment.thumbnail}}</div>
+{%    else %}
+{%     trans "No preview available." %}
+{%    endif %}
+   </td>
+   <td colspan="2">
+{%   endif %}
+{%   if not modified_diff_file_attachment %}
+{%    trans "This is a binary file. The content cannot be displayed." %}
+{%   elif modified_attachment_review_ui_html %}
+{{    modified_attachment_review_ui_html}}
+{%   elif modified_diff_file_attachment.thumbnail %}
+    <div class="file-thumbnail-container">{{modified_diff_file_attachment.thumbnail}}</div>
+{%   else %}
+{%    trans "No preview available." %}
+{%   endif %}
+{%  endif %}
+   </td>
+  </tr>
+ </tbody>
+{% elif file.moved_or_copied and file.num_changes == 0 %}
+ <tbody class="no-changes">
+  <tr>
+   <td colspan="4">{% trans "No changes were made to this file." %}</td>
+  </tr>
+ </tbody>
+{% elif file.newfile and file.num_chunks == 0 %}
+ <tbody class="new-empty-file">
+  <tr>
+   <td colspan="4">{% trans "This is an empty file." %}</td>
+  </tr>
+ </tbody>
+{% elif file.deleted %}
+ <tbody class="deleted">
+  <tr>
+   <td colspan="4">
+{%  if file.num_changes == 0 %}
+{%   trans "This empty file was deleted. The content cannot be displayed." %}
+{%  else %}
+{%   trans "This file was deleted. The content cannot be displayed." %}
+{%  endif %}
+   </td>
+  </tr>
+ </tbody>
+{% else %}
+{%  if file.whitespace_only %}
+ <tbody class="whitespace-file">
+  <tr>
+   <td colspan="4">{% trans "This file contains only whitespace changes." %}</td>
+  </tr>
+ </tbody>
+{%  endif %}
+{%  for chunk in file.chunks %}
+{%   if not chunk.collapsable or not collapseall %}
+ <tbody id="chunk{{file.index}}.{{chunk.index}}"{% attr "class" %}{% if chunk.change != "equal" %}{{chunk.change}}{% if chunk.meta.whitespace_chunk%} whitespace-chunk{% endif %}{% else %}{% if chunk.collapsable %} collapsable{% endif %}{% endif %}{% if standalone %} loaded{% endif %}{% endattr %}>
+{%    diff_lines file.index chunk standalone line_fmt anchor_fmt begin_collapse_fmt end_collapse_fmt moved_fmt %}
+ </tbody>
+{%   else %}
+ <tbody class="diff-header" id="collapsed-chunk{{file.index}}.{{chunk.index}}">
+  <tr>
+   <th>
+{%    if chunk.index != 0 %}
+    {% diff_expand_link 'above' _('Show 20 more lines above') 20 0 %}
+{%    endif %}
+   </th>
+   <td colspan="3">
+    {% definevar 'expand_text' %}{% blocktrans count lines=chunk.numlines %}{{lines}} line{% plural %}{{lines}} lines{% endblocktrans %}{% enddefinevar %}
+    {% diff_expand_link 'all' _('Show all lines') 0 0 expand_text %}
+   </td>
+  </tr>
+{%    if chunk.index|add:1 != file.num_chunks %}
+  <tr>
+   <th>{% diff_expand_link 'below' _('Show 20 more lines below') 0 20 %}</th>
+{%     if chunk.meta.headers and chunk.meta.headers.0 %}
+{%      if chunk.meta.headers.0.text == chunk.meta.headers.1.text %}
+   <td colspan="3">{% diff_chunk_header chunk.meta.headers.0 %}</td>
+{%      else %}
+   <td>{% diff_chunk_header chunk.meta.headers.0 %}</td>
+   <td colspan="2">
+{%       if chunk.meta.headers.1 %}
+{%        diff_chunk_header chunk.meta.headers.1 %}
+{%       endif %}
+   </td>
+{%      endif %}
+{%     else %}
+   <td colspan="3"></td>
+{%     endif %}
+  </tr>
+{%    endif %}
+ </tbody>
+{%   endif %}
+{%  endfor %}{# chunks #}
+{% endif %}{# file deleted, binary and whitespace_only #}
+
+{% if not standalone %}
+</table>
+{%  endif %}