{% comment %}
Copyright (C) 2017-2019  The Software Heritage developers
See the AUTHORS file at the top-level directory of this distribution
License: GNU Affero General Public License version 3, or any later version
See top-level LICENSE file for more information
{% endcomment %}

{% load swh_templatetags %}

{% if vault_cooking %}

  <!-- entry in the Actions menu -->
  <div class="dropdown-submenu swh-vault-menu">
    <a class="dropdown-item dropdown-left" tabindex="-1" href="#">
      <i class="fa fa-download fa-fw" aria-hidden="true"></i>Download
    </a>
    <div class="dropdown-menu">
      {% if vault_cooking.directory_context %}
        <button class="dropdown-item" type="button" tabindex="-1" onclick="swh.vault.vaultRequest('directory', '{{ vault_cooking.directory_id }}')">
          <i class="{{ swh_object_icons.directory }} fa-fw" aria-hidden="true"></i>as tarball
        </button>
      {% endif %}
      {% if vault_cooking.revision_context %}
        <button class="dropdown-item" type="button" tabindex="-1" onclick="swh.vault.vaultRequest('revision', '{{ vault_cooking.revision_id }}')">
          <i class="{{ swh_object_icons.revision }} fa-fw"></i>as git
        </button>
      {% endif %}
    </div>
  </div>

  <!-- modals related to the creation of vault cooking tasks -->
  <!-- they will be reparented in the script below in order to be able to display them -->
  <div class="modal fade" id="vault-cook-directory-modal" tabindex="-1" role="dialog" aria-labelledby="vault-cook-directory-modal-label" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h6 class="modal-title" id="vault-cook-directory-modal-label">Cook and download a directory from the Software Heritage Vault</h6>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <p>
            You have requested the cooking of the directory with identifier <strong>{{ vault_cooking.directory_id }}</strong>
            into a standard <code>tar.gz archive</code>.
          </p>
          <p>
            Once downloaded, the directory can be extracted with the following command:
          </p>
          <p><code>$ tar xvzf {{ vault_cooking.directory_id }}.tar.gz</code></p>
          <p>
            Are you sure you want to continue ?
          </p>
          <form>
            <div class="form-group">
              <label for="email">(Optional) Send download link once it is available to that email address:</label>
              <input type="email" class="form-control" id="swh-vault-directory-email">
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
          <button type="button" class="btn btn-default btn-sm" onclick="swh.vault.cookDirectoryArchive('{{ vault_cooking.directory_id }}')">Ok</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="vault-fetch-directory-modal" tabindex="-1" role="dialog" aria-labelledby="vault-fetch-directory-modal-label" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h6 class="modal-title" id="vault-fetch-directory-modal-label">Download a directory from the Software Heritage Vault</h6>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <p>
            You have requested the download of the directory with identifier <strong>{{ vault_cooking.directory_id }}</strong>
            as a standard <code>tar.gz archive</code>.
          </p>
          <p>
            Once downloaded, the directory can be extracted with the following command:
          </p>
          <p><code>$ tar xvzf {{ vault_cooking.directory_id }}.tar.gz</code></p>
          <p>
            Are you sure you want to continue ?
          </p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
          <button type="button" class="btn btn-default btn-sm" onclick="swh.vault.fetchDirectoryArchive('{{ vault_cooking.directory_id }}')">Ok</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="vault-cook-revision-modal" tabindex="-1" role="dialog" aria-labelledby="vault-cook-revision-modal-label" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h6 class="modal-title" id="vault-cook-revision-modal-label">Cook and download a revision from the Software Heritage Vault</h6>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <p>
            You have requested the cooking of the history heading to revision with identifier <strong>{{ vault_cooking.revision_id }}</strong>
            into a <code>git fast-import archive</code>.
          </p>
          <p>
            Once downloaded, the git repository can be imported with the following commands:
          </p>
          <p>
            <code>$ git init</code><br/>
            <code>$ zcat {{ vault_cooking.revision_id }}.gitfast.gz | git fast-import</code>
          </p>
          <p>
            Are you sure you want to continue ?
          </p>
          <form>
            <div class="form-group">
              <label for="email">(Optional) Send download link once it is available to that email address:</label>
              <input type="email" class="form-control" id="swh-vault-revision-email">
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
          <button type="button" class="btn btn-default btn-sm" onclick="swh.vault.cookRevisionArchive('{{ vault_cooking.revision_id }}')">Ok</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="vault-fetch-revision-modal" tabindex="-1" role="dialog" aria-labelledby="vault-fetch-revision-modal-label" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h6 class="modal-title" id="vault-fetch-revision-modal-label">Download a revision from the Software Heritage Vault</h6>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <p>
            You have requested the download of the history heading to revision with identifier <strong>{{ vault_cooking.revision_id }}</strong>
            as a <code>git fast-import archive</code>.
          </p>
          <p>
            Once downloaded, the git repository can be imported with the following commands:
          </p>
          <p>
            <code>$ git init</code><br/>
            <code>$ zcat {{ vault_cooking.revision_id }}.gitfast.gz | git fast-import</code>
          </p>
          <p>
            Are you sure you want to continue ?
          </p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
          <button type="button" class="btn btn-default btn-sm" onclick="swh.vault.fetchRevisionArchive('{{ vault_cooking.revision_id }}')">Ok</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="invalid-email-modal" tabindex="-1" role="dialog" aria-labelledby="invalid-email-modal-label" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title" id="invalid-email-modal-label">Invalid Email !</h4>
        </div>
        <div class="modal-body">
          <p>The provided email is not well-formed.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Ok</button>
        </div>
      </div>
    </div>
  </div>

  {% include "includes/vault-common.html" %}

{% endif %}
