{% extends "tesm_core/base.html" %}
{% from "tesm_core/macros.html" import empty_state, alert %}

{% block page_title %}Protokollverlauf{% endblock %}
{% block page_sub %}{{ rotated | length }} rotierte Dateien &middot; {{ archived | length }} archivierte Audit-Tage{% endblock %}

{% block content %}
{{ alert('Rotiert wird per logrotate mit copytruncate -- keiner der schreibenden Prozesse
(Ueberwachung, Web, Kea) kann ein Reopen-Signal verarbeiten.', 'info') }}

<div class="grid grid--2">
  <section class="card">
    <div class="card__header">
      <div class="flex-1">
        <div class="card__title">{{ icon('file-text', size=17) }} Rotierte Dateien</div>
        <div class="card__sub">{{ log_dir }}</div>
      </div>
    </div>
    {% if rotated %}
      <div class="table-wrap">
        <table class="table table--compact">
          <thead><tr><th>Datei</th><th class="numeric">Groesse</th><th>Geaendert</th></tr></thead>
          <tbody>
            {% for entry in rotated %}
              <tr>
                <td><a href="{{ url_for('logs.history_file', name=entry.name) }}">{{ entry.name }}</a></td>
                <td class="numeric fs-sm">{{ entry.size | bytes }}</td>
                <td class="fs-sm">{{ entry.modified | int | string }}</td>
              </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    {% else %}
      {{ empty_state('Noch nichts rotiert', 'logrotate hat bisher keine Kopie angelegt.', 'clock') }}
    {% endif %}
  </section>

  <section class="card">
    <div class="card__header">
      <div class="flex-1">
        <div class="card__title">{{ icon('history', size=17) }} Archivierte Aenderungen</div>
        <div class="card__sub">Aus der Datenbank ausgelagerte Kalendertage</div>
      </div>
      {% if archived and current_user.has('logs_history.export') %}
        <form method="post" action="{{ url_for('logs.history_export') }}" data-no-guard>
          <input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
          <button class="btn btn--sm" type="submit">{{ icon('download', size=14) }} Als ZIP</button>
        </form>
      {% endif %}
    </div>
    {% if archived %}
      <div class="table-wrap">
        <table class="table table--compact">
          <thead><tr><th>Tag</th><th class="numeric">Groesse</th><th></th></tr></thead>
          <tbody>
            {% for entry in archived %}
              <tr>
                <td><a href="{{ url_for('logs.history_archive', day=entry.day) }}">{{ entry.day }}</a></td>
                <td class="numeric fs-sm">{{ entry.size | bytes }}</td>
                <td class="fs-sm faint">{{ entry.modified | dt }}</td>
              </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
      {% if current_user.has('logs_history.delete') %}
        <div class="card__footer">
          <form method="post" action="{{ url_for('logs.history_purge') }}" data-no-guard>
            <input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
            <button class="btn btn--sm btn--ghost danger-text" type="submit"
                    data-confirm="Alle {{ archived | length }} Archivdateien endgueltig vom Server loeschen? Bitte vorher als ZIP sichern."
                    data-confirm-title="Archiv loeschen" data-confirm-ok="Loeschen">
              Archiv vom Server entfernen
            </button>
          </form>
        </div>
      {% endif %}
    {% else %}
      {{ empty_state('Kein Archiv', 'Es wurden noch keine Audit-Tage ausgelagert.', 'history') }}
    {% endif %}
  </section>
</div>
{% endblock %}
