{% extends "base.html" %}

{% autoescape None %}

{% block title %}Job {{ job['job_index'] }}, Dataset {{ dataset['dataset'] }} - IceProd{% end %}

{% block page_title %}Job Details{% end %}

{% block body %}

<div class="task_details">
{% for k in job %}
<div class="key_value">
  <div>{{ escape(k) }}</div>
  <div>
  {% if k == 'dataset_id' %}
    <a href="/dataset/{{ url_escape(job[k]) }}">{{ escape(job[k]) }}</a>
  {% elif k == 'tasks' %}
  {% else %}
    {{ job[k] }}
  {% end %}
  </div>
</div>
{% end %}

{% if (current_user) %}
<div class="action">
    <button onclick='set_jobs_status(dataset_id, ["{{ job["job_id"] }}"], "processing", "{{ passkey }}", ["queued", "processing", "errors", "suspended"]);'>Reset</button>
    <button onclick='set_jobs_status(dataset_id, ["{{ job["job_id"] }}"], "processing", "{{ passkey }}");'>Hard Reset</button>
    <button onclick='set_jobs_status(dataset_id, ["{{ job["job_id"] }}"], "suspended", "{{ passkey }}", ["idle", "waiting", "queued", "processing", "reset"]);'>Suspend</button>
</div>
{% end %}

</div>

<div class="task_completion">
    <h2>Tasks</h2>
    <table>
        <tr>
            <th>Name</th>
            <th>Type</th>
            <th>Status</th>
            <th>Failures</th>
            <th>Walltime</th>
            <th>Walltime Err</th>
        </tr>
        {% for task in job['tasks'] %}
        <tr>
            <td><a href="/dataset/{{ url_escape(job['dataset_id']) }}/task/{{ url_escape(task['task_id']) }}">{{ task['name'] }}</a></td>
            <td>{{ 'GPU' if 'gpu' in task['requirements'] and task['requirements']['gpu'] else 'CPU' }}</td>
            <td>{{ task['status'] }}</td>
            <td>{{ task['failures'] }}</td>
            <td>{{ '{:.2f}'.format(task['walltime']/3600) }}</td>
            <td>{{ '{:.2f}'.format(task['walltime_err']/3600) }}</td>
        </tr>
        {% end %}
    </table>
</div>

{% end %}

{% block body_scripts %}

{% if (current_user) %}
<script type="text/javascript" src="/static/fetch.js"></script>
<script type="text/javascript" src="/static/rest.js"></script>
<script>
var dataset_id = "{{ job['dataset_id'] if job else '' }}";
</script>
{% end %}

{% end %}
