{% extends "base.html" %}
{% load filters_deploys %}

{% block header %}
<h1>Events</h1>
{% endblock %}

{% block content %}
<div class="container-fluid">
  <div class="row">
    <div class="col-md-12">
      <form action="" method="GET">
        <select name="kindName">
          <option value="">all events</option>
          {% for kind in kinds %}
          <option value="{{ kind.Name }}">{{ kind.Name }}</option>
          {% endfor %}
        </select>
        <button>filter</button>
      </form>
      <table class="events table" id="list">
        <thead>
          <tr>
            <th>Action</th>
            <th>Target</th>
            <th>Owner</th>
            <th>Start</th>
            <th>Duration</th>
          </tr>
        </thead>
        <tbody>
          {% for event in events %}
          <tr>
            <tr class="{% if event.Running %}bg-info{% endif %}{% if event.CancelInfo.Canceled %}bg-warning{% else %}{% if event.Error %}bg-danger{% endif %}{% endif %}">
              <td>
                <a href="{% url 'event-info' event.UniqueID %}">
                  {{ event.Kind.Name }}
                </a>
              </td>
              <td>
                {{ event.Target.Type }}: {{ event.Target.Value }}
              </td>
              <td>
                {{ event.Owner.Type }}{% if event.Owner.Name %}: {{ event.Owner.Name }}{% endif %}
              </td>
              <td>
                {% if event.StartTime %}
                {{ event.StartTime|date:" d-m-Y H:i:s " }}
                {% endif %}
              </td>
              <td>
                {% if event.EndTime %}
                {{ event.StartTime|timesince:event.EndTime }}
                {% endif %}
              </td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
        <div class="pager">
          {% if previous %}
          <span class="page">
            <a href="?page={{ previous }}{% if request.GET.kindName %}&kindName={{ request.GET.kindName }}{% endif %}">&lt; Prev</a>
          </span>
          {% endif %}

          {% if next %}
          <span class="page">
            <a href="?page={{ next }}{% if request.GET.kindName %}&kindName={{ request.GET.kindName }}{% endif %}">Next &gt;</a>
          </span>
          {% endif %}
        </div>
      </div>
    </div>
  </div>
  {% endblock %}
