{% load events %}

<div class="container-fluid">
  <div class="row">
    <div class="col-md-12">
      {% if show_controls %}
        <div id="controls"></div>
      {% endif %}
      <table class="events table" id="list">
        <thead>
          <tr>
            <th>Action</th>
            {% if not app_name %}<th>Target</th>{% endif %}
            <th>Owner</th>
            <th>Start</th>
            <th>Duration</th>
            <th>Status</th>
          </tr>
        </thead>
        <tbody>
          {% for event in events %}
          {% event_url event.UniqueID app_name as event_info_url %}
          <tr {% if event.Error %}data-container="body" data-toggle="tooltip" title="{{ event.Error|truncatechars:300 }}"{% endif %}>
            <td>
              <a href="{{ event_info_url }}">
                {{ event.Kind.Name }}
              </a>
            </td>
            {% if not app_name %}
            <td>
              <a href="{{ event_info_url }}">
                <div>{{ event.Target.Type }}: {{ event.Target.Value }}</div>
                {% for et in event.ExtraTargets %}
                  <div>{{ et.Target.Type }}: {{ et.Target.Value }}</div>
                {% endfor %}
              </a>
            </td>
            {% endif %}
            <td>
              <a href="{{ event_info_url }}">
                {{ event.Owner.Type }}{% if event.Owner.Name %}: {{ event.Owner.Name }}{% endif %}
              </a>
            </td>
            <td>
              <a href="{{ event_info_url }}">
                {% if event.StartTime %}
                {{ event.StartTime|date:" d-m-Y H:i:s " }}
                {% endif %}
              </a>
            </td>
            <td>
              <a href="{{ event_info_url }}">
                {% if event.EndTime and not event.Running %}
                {{ event.StartTime|timesince:event.EndTime }}
                {% endif %}
              </a>
            </td>
            <td class="status-col {% if not event.Running and not event.CancelInfo.Canceled and not event.Error %}status-success{% endif %}{% if event.Running %}status-running{% endif %}{% if event.Error %}status-error{% endif %}">
              <a href="{{ event_info_url }}">
                <div class="status-block">
                  {% if event.Running %}
                  Running
                  {% endif %}
                  {% if event.Error %}
                  Error
                  {% endif %}
                  {% if not event.Running and not event.CancelInfo.Canceled and not event.Error %}
                  Success
                  {% endif %}
                </div>
              </a>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      <div class="pager">
        {% if previous is not None %}
        <span class="page">
          <a href="?{{ previous }}">&lt; Prev</a>
        </span>
        {% endif %}

        {% if next is not None %}
        <span class="page">
          <a href="?{{ next }}">Next &gt;</a>
        </span>
        {% endif %}
      </div>
    </div>
  </div>
</div>
