{% extends 'base_wide_page.html' %}
{% load seahub_tags avatar_tags i18n %}

{% block sub_title %}{% trans "Access Log" %} - {% endblock %}

{% block wide_page_content %}
<h2 class="file-access-hd"><span class="op-target">{{ filename }}</span> {% trans "Access Log" %}</h2>
        <div class="file-audit-list-topbar">
            <p class="path">
                {% trans 'Current Path:' %}
                {% for name, link in zipped %}
                {% if not forloop.last %}
                <a href="{{ SITE_ROOT }}#common/lib/{{ repo.id }}/{{ link|strip_slash }}">{{ name }}</a> /
                {% else %}
                <a href="{% url 'view_lib_file' repo.id path %}" target="_blank" >{{ name }}</a>
                {% endif %}
                {% endfor %}
            </p>
        </div>

        {% if events %}
        <table class='file-audit-list'>
            <tr>
                <th width="25%" class="user">{% trans "User" %}</th>
                <th width="20%">{% trans "Type" %}</th>
                <th width="30%">{% trans "IP" %} / {% trans "Device Name" %}</th>
                <th width="25%">{% trans "Date" %}</th>
            </tr>

            {% for e in events %}
            <tr>
                <td class="user">
                    {% avatar e.user 16 %}
                    {% if e.user %}
                        <a href="{% url 'user_profile' e.user %}">{{ e.user }}</a>
                    {% else %}
                        <span>{% trans "Anonymous User" %}</span>
                    {% endif %}
                </td>
                <td><span>{{ e.event_type }}</span></td>
                <td>
                    {% if e.show_device %}
                        {{ e.ip }} / {{ e.show_device }}
                    {% else %}
                        {{ e.ip }}
                    {% endif %}
                </td>
                <td>{{ e.time|date:"Y-m-d G:i:s" }}</td>
            </tr>
            {% endfor %}
        </table>

        <div id="paginator">
            {% if current_page != 1 %}
            <a href="?page={{ prev_page }}&per_page={{ per_page }}{{ extra_href }}">{% trans "Previous" %}</a>
            {% endif %}
            {% if page_next %}
            <a href="?page={{ next_page }}&per_page={{ per_page }}{{ extra_href }}">{% trans "Next" %}</a>
            {% endif %}
            {% if current_page != 1 or page_next %}
            |
            {% endif %}
            <span>{% trans "Per page: " %}</span>
            {% if per_page == 25 %}
            <span> 25 </span>
            {% else %}
            <a href="?per_page=25{{ extra_href }}" class="per-page">25</a>
            {% endif %}
            {% if per_page == 50 %}
            <span> 50 </span>
            {% else %}
            <a href="?per_page=50{{ extra_href }}" class="per-page">50</a>
            {% endif %}
            {% if per_page == 100 %}
            <span> 100 </span>
            {% else %}
            <a href="?per_page=100{{ extra_href }}" class="per-page">100</a>
            {% endif %}
        </div>
        {% else %}
        <div class="empty-tips">
            <h2 class="alc">{% trans "This file has (apparently) not been accessed yet" %}</h2>
        </div>
        {% endif %}

{% endblock %}
