{% extends "app_home/base.html" %}
{% load static %}
{% load i18n %}

{% block navbar_app %}
{% include 'app_home/_sidebar.html' %}
{% endblock %}


{% block title %}
<h2>Logs</h2>
<small class="text-muted">{{ count }} {% translate "entries" %}</small>
<hr>
{% endblock %}


{% block content %}

<div class="btn-group">

  <div>
    <a class="btn btn-outline-danger dropdown-toggle me-4" role="button" data-bs-toggle="dropdown" aria-expanded="false">
    Level ({{ level }})</a>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="{% url 'app_home:log' 'debug' %}">DEBUG</a>
      <a class="dropdown-item" href="{% url 'app_home:log' 'info' %}">INFO</a>
      <a class="dropdown-item" href="{% url 'app_home:log' 'warning' %}">WARNING</a>
      <a class="dropdown-item" href="{% url 'app_home:log' 'error' %}">ERROR</a>
      <a class="dropdown-item" href="{% url 'app_home:log' 'critical' %}">CRITICAL</a>
    </div>
  </div>


  <div class="mx-4"> <!-- SEARCH -->
  <form class="d-flex" role="search" action="" method="post">{% csrf_token %}
  <button class="btn btn-success" type="submit"><i class="fa fa-search"></i></button> &nbsp;&nbsp;
  <input class="form-control" type="search" name="query" placeholder="{% translate 'Filter' %}" value="{{ query }}" >
  </form>
  </div>

&nbsp;&nbsp;&nbsp;

<!--  PAGINATOR -->
    {% if page_last > 1 %}
    <div class="ms-4 my-2"> {% translate 'Page' %}</div>

    <div class="mx-3"> <!-- PAGINATOR :  PREV | FIRST (bool)|| CURRENT or page... || LAST | NEXT -->
    <ul class="pagination">
      <!-- PREV -->
      <li class="page-item"><a class="page-link" href="?page={{ page_prev }}&size={{ size }}">&laquo; </a></li>
      
      <!-- FIRST -->
      {% if page_first %}
      <li class="page-item"><a class="page-link active" href="?page=1&size={{ size }}">1</a></li>
      {% else %}
      <li class="page-item"><a class="page-link" href="?page=1&size={{ size }}">1</a></li>
      {% endif %}

    &nbsp;&nbsp;&nbsp;  <!-- CURRENT -->
      {% if page_current %}
      <li class="page-item"><a class="page-link active" href="?page={{ page }}&size={{ size }}">{{ page }}</a></li>
      {% else %}
      <li class="page-item"><a class="page-link disabled">...</a></li>
      {% endif %}
    &nbsp;&nbsp;&nbsp;

      <!-- LAST -->
      {% if page_last_active %}
      <li class="page-item"><a class="page-link active" href="?page={{ page_last }}&size={{ size }}">{{ page_last }}</a></li>
      {% else %}
      <li class="page-item"><a class="page-link" href="?page={{ page_last }}&size={{ size }}">{{ page_last }}</a></li>
      {% endif %}

      <!-- NEXT -->
      <li class="page-item"><a class="page-link" href="?page={{ page_next }}&size={{ size }}">&raquo; </a></li>

    </ul> 
    </div>
    {% endif %}

<!-- SIZE -->
    <div>
      <a class="btn btn-outline-primary dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
      {{ size }} {% translate 'per page' %} </a> 
      <div class="dropdown-menu">
        <a class="dropdown-item" href="{% url 'app_home:log' %}?size=50">50</a>
        <a class="dropdown-item" href="{% url 'app_home:log' %}?size=100">100</a>
        <a class="dropdown-item" href="{% url 'app_home:log' %}?size=500">500</a>
        <a class="dropdown-item" href="{% url 'app_home:log' %}?size=1000">1000</a>
        <a class="dropdown-item" href="{% url 'app_home:log' %}?size=5000">5000</a>
      </div>
    </div>

<!-- PURGE -->
{% if 'p_log_admin' in aaa.perms %}
    <div class="">
    <li class="nav-item">
    <form method="post">{% csrf_token %}
    <input class="btn btn-outline-danger ms-4" type="submit" value="Purge Logs" name="purge">
    </form>
    </li>
    </div>{% endif %}

</div>


<hr>

<table  id="table_managed_off"  class="table table-striped table-hover small">
<thead class="thead-dark"><tr>
<th>ID</th>
<th>Date</th>
<th>User</th>
<th>User-as</th>
<th>User IP</th>
<th>Level</th>
<th>App</th>
<th>View</th>
<th>Action</th>
<th>Status</th>
<th>Info</th>
</tr>
</thead>



{% for log in logs %}
<tr>
<td class="py-1 text-left">{{ log.id }}</td>
<td class="py-1 px-1 mx-0">{{ log.created|date:'Y-m-d H:i:s (D)' }}</td>    
<td class="py-1 text-left">{{ log.username }}</td>
<td class="py-1 text-left">{{ log.impersonate }}</td>
<td class="py-1 text-left">{{ log.user_ip }}</td>
<td class="py-1 text-left">{{ log.level }}</td>
<td class="py-1 text-left">{{ log.app }}</td>
<td class="py-1 text-left">{{ log.view }}</td>
<td class="py-1 text-left">{{ log.action }}</td>
<td class="py-1 text-left">{{ log.status }}</td>
<td class="py-1 text-left">{{ log.data |truncatechars:70}}</pre></td>
</tr>{% endfor %}
</table>






{% endblock %}
