{% extends "reviews/reviewable_base.html" %}
{% load difftags %}
{% load djblets_deco %}
{% load djblets_utils %}
{% load i18n %}
{% load reviewtags %}

{% block title %}{{review_request_details.summary}} | {% trans "Diff Viewer" %}{% endblock %}

{% block jsconsts %}
{{block.super}}
{% include "reviews/review_flags.js" %}
  var gRevision = '{{diffset.revision}}';
{% if interdiffset %}
  var gInterdiffRevision = '{{interdiffset.revision}}';
{% else %}
  var gInterdiffRevision = null;
{% endif %}
{% endblock %}

{% block css %}
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/diffviewer.css?{{MEDIA_SERIAL}}" />
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/reviews.css?{{MEDIA_SERIAL}}" />
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/syntax.css?{{MEDIA_SERIAL}}" />
{% if siteconfig.settings.diffviewer_show_trailing_whitespace|default_if_none:1 %}
<style type="text/css">
  #diffs.ewhl table.sidebyside .ew { background: #ee3434; }
</style>
{% endif %}
{% endblock %}

{% block scripts-post %}
<script type="text/javascript" src="{{MEDIA_URL}}rb/js/diffviewer.js?{{MEDIA_SERIAL}}"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/js/reviews.js?{{MEDIA_SERIAL}}"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/js/jquery.form.js?{{MEDIA_SERIAL}}"></script>

{% if not specific_diff_requested %}
<script type="text/javascript">
  $(document).ready(function() {
	  /* Listen for updates to this review request. */
	  registerForUpdates("{{last_activity_time|date:"Y-m-d H:i:s"}}", "diff");
  });
</script>
{% endif %}
{% endblock %}

{% block content %}
{% if error %}
{%  errorbox %}
<p>{{error}}</p>
{%   if trace %}<pre>{{trace|escape}}</pre>{% endif %}
{%  enderrorbox %}
{% else %}{# !error #}

{% include "reviews/trophy_box.html" %}
{% include "reviews/review_header.html" %}

{% box "review-request" %}
<ul class="actions">
{% include "reviews/review_request_actions_secondary.html" %}
{% if not interdiffset %}
 <li class="primary"><a href="raw/">{% trans "Download Diff" %}</a></li>
{% endif %}
{% include "reviews/review_request_actions_primary.html" %}
 <li class="primary"><a href="{{review_request.get_absolute_url}}">{% trans "View Reviews" %}</a></li>
</ul>
<div class="main">
{% include "reviews/review_request_box.html" %}

<div id="diff-details">
<a name="index_header"></a>
{% with review_request.diffset_history.diffsets.latest.revision as latest_revision %}
{% with diffset.revision as revision %}
<div class="main">
{%  if interdiffset %}
{#   We're showing an interdiff, so indicate the revision range. #}
 <h1>{% blocktrans with interdiffset.revision as interdiff_revision %}Changes between revision {{revision}} and {{interdiff_revision}}{% endblocktrans %}</h1>
{%  else %}
{%   ifequal diffset.revision latest_revision %}
 <h1>{% blocktrans %}Diff revision {{revision}} (Latest){% endblocktrans %}</h1>
{%   else %}
{#    This is not the most recent diff. See if we're showing a draft. #}
{%    if is_draft_diff %}
 <h1>{% trans "Draft diff" %}</h1>
 <p>
{%     blocktrans %}
  This diff is part of your current draft. Other users will not see this
  diff until you publish your draft.
{%     endblocktrans %}
{%    else %}
{#     This is not a draft. Tell the user this is not the most recent. #}
 <h1>{% blocktrans %}Diff revision {{revision}}{% endblocktrans %}</h1>
 <p>
{%     blocktrans with diffset.revision as revision and review_request.get_absolute_url as review_request_url%}
  This is not the most recent revision of the diff. The
  <a href="{{review_request_url}}diff/">latest diff</a> is revision
  {{latest_revision}}.
  <a href="{{review_request_url}}diff/{{revision}}-{{latest_revision}}/">See what's changed.</a>
{%     endblocktrans %}
{%    endif %}
 </p>
{%   endifequal %}
{%  endif %}

{#  Notify the user if they have unpublished comments in other diffs. #}
{%  if review|has_comments_in_diffsets_excluding:diffset_pair %}
{%   box "important" %}
 <h1>{% trans "You have unpublished comments on other revisions" %}</h1>
 <p>
  {% trans "Your review consists of comments on the following revisions:" %}
 </p>
 <ul>
{%    for diffset_info in review|diffsets_with_comments:diffset_pair %}
{%     if diffset_info.is_current %}
  <li><b>Revision {{diffset_info.diffset.revision}}</b></li>
{%     else %}
  <li><a href="{{review_request.get_absolute_url}}diff/{{diffset_info.diffset.revision}}/#index_header">Revision {{diffset_info.diffset.revision}}</a></li>
{%     endif %}
{%    endfor %}
{%    for pair in review|interdiffs_with_comments:diffset_pair %}
{%     if pair.is_current %}
  <li><b>Interdiff revision {{pair.diffset.revision}} - {{pair.interdiff.revision}}</b></li>
{%     else %}
  <li><a href="{{review_request.get_absolute_url}}diff/{{pair.diffset.revision}}-{{pair.interdiff.revision}}/">Interdiff revision {{pair.diffset.revision}} - {{pair.interdiff.revision}}</a></li>
{%     endif %}
{%    endfor %}
 </ul>
 {%  endbox %}
{%  endif %}

{%  ifnotequal num_diffs 1 %}
{#   Show a revision selector for jumping between revisions. #}
 <table class="revision-selector">
  <tr>
   <th><label for="jump_to_revision">{% trans "Jump to revision:" %}<label></th>
   <td>
    <div id="jump_to_revision" class="revisions">
{%  for item in review_request.diffset_history|revision_link_list:diffset_pair %}
{%   if item.is_current %}
     <span class="current">{{item.revision}}</span>
{%   else %}
     <a href="{{review_request.get_absolute_url}}diff/{{item.revision}}/#index_header">{{item.revision}}</a>
{%   endif %}
{%  endfor %}
{%  if draft and draft.diffset %}
{#   There's a draft diff, so display it in the list. #}
{%   if is_draft_diff %}
     <span class="current">{{draft.diffset.revision}}</span>
{%   else %}
     <a href="{{review_request.get_absolute_url}}diff/{{draft.diffset.revision}}/#index_header">{{draft.diffset.revision}}</a>
{%   endif %}
{%  endif %}
    </div>
   </td>
  </tr>
  <tr>
   <th><label for="show_interdiff">{% blocktrans %}Changes between r{{revision}} and:{% endblocktrans %}</label></th>
   <td>
    <div id="show_interdiff" class="revisions">
{%  for item in review_request.diffset_history|interdiff_link_list:diffset_pair %}
{%   if item.is_current %}
     <span class="current">{{item.revision}}</span>
{%   else %}
     <a href="{{review_request.get_absolute_url}}diff/{{item.path}}/#index_header">{{item.revision}}</a>
{%   endif %}
{%  endfor %}
{%  if draft and draft.diffset %}
{#   There's a draft diff, so display it in the list. #}
{%   if is_draft_diff or is_draft_interdiff %}
     <span class="current">{{draft.diffset.revision}}</span>
{%   else %}
     <a href="{{review_request.get_absolute_url}}diff/{{diffset_pair.0}}-{{diffset_pair.1}}/#index_header">{{draft.diffset.revision}}</a>
{%   endif %}
{%  endif %}
    </div>
   </td>
  </tr>
 </table>
{% endifnotequal %}

 <p><label>{% trans "Files Changed:" %}</label></p>
{% include "diffviewer/changeindex.html" %}
  </div>
 </div>
</div>

<ul class="controls">
{% if collapseall %}
 <li><a href=".?expand=1"><img src="{{MEDIA_URL}}rb/images/expand.png?{{MEDIA_SERIAL}}" width="14" height="14" border="0" alt="" /> {% trans "Expand changes" %}</a></li>
{% else %}
 <li><a href=".?collapse=1"><img src="{{MEDIA_URL}}rb/images/collapse.png?{{MEDIA_SERIAL}}" width="14" height="14" border="0" alt="" /> {% trans "Collapse changes" %}</a></li>
{% endif %}
{% if siteconfig.settings.diffviewer_show_trailing_whitespace|default_if_none:1 %}
 <li class="ew" style="display:none;"><a href="#" class="toggleExtraWhitespaceButton"><img src="{{MEDIA_URL}}rb/images/collapse.png?{{MEDIA_SERIAL}}" width="14" height="14" border="0" alt="" /> {% trans "Hide Extra Whitespace" %}</a></li>
 <li  class="ew"><a href="#" class="toggleExtraWhitespaceButton"><img src="{{MEDIA_URL}}rb/images/expand.png?{{MEDIA_SERIAL}}" width="14" height="14" border="0" alt="" /> {% trans "Show Extra Whitespace" %}</a></li>
{% endif %}
 <li class="ws"><a href="#" class="toggleWhitespaceButton"><img src="{{MEDIA_URL}}rb/images/collapse.png?{{MEDIA_SERIAL}}" width="14" height="14" border="0" alt="" /> {% trans "Hide Whitespace changes" %}</a></li>
 <li  class="ws" style="display:none;"><a href="#" class="toggleWhitespaceButton"><img src="{{MEDIA_URL}}rb/images/expand.png?{{MEDIA_SERIAL}}" width="14" height="14" border="0" alt="" /> {% trans "Show Whitespace changes" %}</a></li>
</ul>
{% endwith %}
{% endwith %}
{%  endbox %}

<div id="diffs">
{% for file in files %}
{%  if file.fragment %}
{{file.fragment|safe}}
{%  else %}
<table class="sidebyside loading{% if file.newfile %} newfile{% endif %}"
       id="file_container_{{file.filediff.id}}">
 <thead>
  <tr>
   <th colspan="2">{{file.depot_filename}}</th>
  </tr>
  <tr>
   <th class="rev">{{file.revision}}</th>
   <th class="rev">{{file.dest_revision}}</th>
  </tr>
 </thead>
 <tbody>
  <tr><td colspan="2"><pre>&nbsp;</pre></td></tr>
 </tbody>
</table>
{%  endif %}
<script type="text/javascript">
  $(document).ready(function() {
  loadFileDiff("{{base_url}}", "{{file.filediff.id}}", "{{file.filediff.diffset.revision}}",
{% if file.interfilediff %}
               "{{file.interfilediff.id}}", "{{file.interfilediff.diffset.revision}}",
{% else %}
               null, null,
{% endif %}
               "{{file.index}}",
			   {% commentcounts file.filediff file.interfilediff %});
});
</script>
{% endfor %}

<a name="index_footer"></a>
{% include "diffviewer/changeindex.html" %}
</div>

{% endif %}{# !error #}
{% endblock %}
