{% extends 'layout_repo.html' %}
{% set active_page='repo' %}
{% set active_repo_page='browse' %}
{% block title %}{% trans %}Files{% endtrans %}{% endblock %}
{% block content %}

<ol class="pagination pagination-sm">
    {% if parents %}
    {% for parent in parents %}
    <li {{ attrib(class=loop.last and 'active') }}>
        <a {{ attrib(href=loop.last and "#" or url_for_browse(repo_path, parent.path)) }}>
            {{ parent.name }}
        </a>
    </li>
    {% endfor %}
    {% endif%}
</ol>

{% if not restore_dates %}
<table id="files" class="sortable table">
    <thead>
        <tr>
            <th id="name" class="sortable" data-type="dir">{% trans %}Name{% endtrans %}</th>
            <th id="size" class="sortable col-md-2" data-type="int">{% trans %}Size{% endtrans %}</th>
            <th id="last-revision" class="sortable col-md-2" data-type="int"><span class="hidden-sm hidden-md hidden-lg">{% trans %}Ver.{% endtrans %}</span><span class="hidden-xs">{% trans %}Previous version(s){% endtrans %}</span></th>
        </tr>
    </thead>
    <tbody>
        {% for entry in dir_entries %}
        <tr class="{% if entry.exists %}exists{% else %}notexists{% endif %}">
            <td {% if entry.isdir %}data-value="dir-{{ entry.display_name }}"
                {% else %}data-value="file-{{ entry.display_name }}"{% endif %}>
                <a {{ attrib(
                        href=(entry.isdir and url_for_browse(repo_path, entry.path)) or
                             (entry.last_change_date and url_for_restore(repo_path, entry.path, entry.last_change_date)) or
                             "#",
                        title=(entry.display_name | length > 45 and entry.display_name)
                      ) }} >
                    <i {% if entry.isdir %}class="icon-folder"{% else %}class="icon-file"{% endif %}></i>
                    {% if entry.isdir %}<span class="sr-only">&lt;DIR&gt;</span>{% endif %}
                    {% if not entry.exists %}<span class="sr-only">&lt;DELETED&gt;</span>{% endif %}
                    {{ entry.display_name | truncate(45,True) }}
                </a>
            </td>
            <td class="nowrap" data-value="{% if not entry.isdir %}{{ entry.file_size }}{% else %}0{% endif %}">
                {% if not entry.isdir %}
                {{ entry.file_size | filesize }}
                {% endif %}
            </td>
            <td data-value="{{ entry.last_change_date and entry.last_change_date.getSeconds() }}">
                {% if entry.change_dates %}
                <div class="dropdown">
                    <button class="btn btn-link dropdown-toggle btn-block" type="button" id="menu1" data-toggle="dropdown">
                        <span class="hidden-xs">
                            {{ entry.last_change_date | datetime }}
                        </span>
                        <span class="badge">{{ entry.change_dates | length }}</span>
                        <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu dropdown-menu-right-xs" role="menu" aria-labelledby="menu1">
                        {% for change_date in entry.change_dates[:-6:-1] %}
                        <li>
                            <a href="{{ url_for_restore(repo_path, entry.path, change_date) }}">
                                <!-- File date -->
                                <i class="icon-download"></i>
                                {{ change_date | datetime }}
                            </a>
                        </li>
                        {% endfor %}
                        <li>
                            <a href="{{ url_for_browse(repo_path, entry.path, restore=true) }}">{% trans %}Show more...{% endtrans %}</a>
                        </li>
                    </ul>
                </div>
                {% endif %}
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% else %}
<div class="panel panel-default">
    <ul class="list-group">
        {% for restore_date in restore_dates %}
        <li class="list-group-item clearfix">
            <i {% if isdir %}class="icon-folder"{% else %}class="icon-file"{% endif %}></i>
            {{ restore_date | datetime }}
            {% if isdir %}
            <div class="pull-right">
              <div class="btn-group">
                <a type="button" class="btn btn-default btn-xs" rel="nofollow" href="{{ url_for_restore(repo_path, path, restore_date) }}">
                  <i class="icon-download"></i>
                  <span>{% trans %}Download{% endtrans %}</span>
                </a>
                <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <span class="caret"></span>
                  <span class="sr-only">{% trans %}Toggle Dropdown{% endtrans %}</span>
                </button>
                <ul class="dropdown-menu dropdown-menu-right-xs" role="menu" aria-labelledby="menu1">
                <li>
                  <a rel="nofollow" href="{{ url_for_restore(repo_path, path, restore_date) }}">
                    <i class="icon-download"></i>
                    <span>{% trans %}Download{% endtrans %} ZIP</span>
                  </a>
                </li>
                <li>
                  <a rel="nofollow" href="{{ url_for_restore(repo_path, path, restore_date, 'tar.gz') }}">
                    <i class="icon-download"></i>
                    <span>{% trans %}Download{% endtrans %} TAR.GZ</span>
                  </a>
                </li>
                <li>
                  <a rel="nofollow" href="{{ url_for_restore(repo_path, path, restore_date, 'tar.bz2') }}">
                    <i class="icon-download"></i>
                    <span>{% trans %}Download{% endtrans %} TAR.BZ2</span>
                  </a>
                </li>
                </ul>
              </div>
            </div>
            {% else %}
            <div class="pull-right">
                <a type="button" class="btn btn-default btn-xs" rel="nofollow" href="{{ url_for_restore(repo_path, path, restore_date) }}">
                  <i class="icon-download"></i>
                  <span>{% trans %}Download{% endtrans %}</span>
                </a>
            </div>
            {% endif %}
        </li>
        {% endfor %}
    </ul>
</div>
{% if limit == restore_dates|count %}
<nav aria-label="...">
  <ul class="pager">
    <li><a href="?restore=T&limit={{ limit * 2 }}"><i class="icon-down-dir"></i> {% trans %}Show more...{% endtrans %}</a></li>
  </ul>
</nav>
{% endif %}
{% endif %}
{% endblock %}