{% extends "base.html" %}

{% block title %}Job #{{ job.id }} | left4me{% endblock %}

{% block content %}
<section class="panel">
  <div class="page-heading">
    <h1>Job #{{ job.id }}</h1>
    {% if job.state in ["queued", "running"] %}
    <form method="post" action="/jobs/{{ job.id }}/cancel" class="inline-form">
      <input type="hidden" name="csrf_token" value="{{ session.get('csrf_token', '') }}">
      <input type="hidden" name="next" value="/jobs/{{ job.id }}">
      <button class="danger" type="submit">cancel</button>
    </form>
    {% endif %}
  </div>

  <table class="definition-table">
    <tbody>
      <tr><th>Operation</th><td>{{ job.operation }}</td></tr>
      <tr><th>State</th><td>{{ job.state }}</td></tr>
      <tr><th>User</th><td>{{ owner.username if owner else "system" }}</td></tr>
      <tr><th>Server</th><td>{% if server %}<a href="/servers/{{ server.id }}">{{ server.name }}</a>{% else %}-{% endif %}</td></tr>
      <tr><th>Created</th><td>{{ job.created_at | timeago }}</td></tr>
      <tr><th>Started</th><td>{% if job.started_at %}{{ job.started_at | timeago }}{% else %}-{% endif %}</td></tr>
      <tr><th>Finished</th><td>{% if job.finished_at %}{{ job.finished_at | timeago }}{% else %}-{% endif %}</td></tr>
      <tr><th>Exit code</th><td>{{ job.exit_code if job.exit_code is not none else "-" }}</td></tr>
    </tbody>
  </table>

  <h2>Job Logs</h2>
  <pre class="log-stream" data-sse-url="/jobs/{{ job.id }}/stream"></pre>
</section>
{% endblock %}
