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

{% 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 %}
{{block.super}}

{% 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 %}
{{block.super}}

{% if not specific_diff_requested %}
{% localtime off %}
<script type="text/javascript">
  $(document).ready(function() {
	  /* Listen for updates to this review request. */
	  RB.registerForUpdates("{{last_activity_time|date:"c"}}", "diff");
  });
</script>
{% endlocaltime %}
{% 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" %}
<div class="actions-container">
 {% star review_request %}
 <ul class="actions">
{% include "reviews/review_request_actions_secondary.html" %}
{% diffviewer_action_hooks %}
{% 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>

<div class="main">
{% include "reviews/review_request_box.html" %}

<div id="diff-details" class="content">
<a name="index_header"></a>
{% with latest_diffset.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 %}
{%   if 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>
{%   endif %}
{%  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 %}

{%  if 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>
{% endif %}

 <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="{% static "rb/images/expand.png" %}" width="14" height="14" border="0" alt="" /> {% trans "Expand changes" %}</a></li>
{% else %}
 <li><a href=".?collapse=1"><img src="{% static "rb/images/collapse.png" %}" 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="{% static "rb/images/collapse.png" %}" width="14" height="14" border="0" alt="" /> {% trans "Hide Extra Whitespace" %}</a></li>
 <li  class="ew"><a href="#" class="toggleExtraWhitespaceButton"><img src="{% static "rb/images/expand.png" %}" width="14" height="14" border="0" alt="" /> {% trans "Show Extra Whitespace" %}</a></li>
{% endif %}
 <li class="ws"><a href="#" class="toggleWhitespaceButton"><img src="{% static "rb/images/collapse.png" %}" 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="{% static "rb/images/expand.png" %}" 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() {
  RB.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 %}
