{% extends "base.html" %}

{% block title %}IceProd{% end %}

{% block page_title %}Tasks by Status{% end %}

{% block body %}

<table class='task_table'>
    <tr>
        <th>Job / Task Index</th>
        <th>Name</th>
        <th>Failures</th>
        {% if (current_user) %}
        <th><button class="set_status" onclick='set_tasks_and_jobs_status(dataset_id, task_ids_on_page, "reset", "{{ passkey }}");'>Reset All</button></th>
        <th><button class="set_status" onclick='set_tasks_status(dataset_id, task_ids_on_page, "suspended", "{{ passkey }}");'>Suspend All</button></th>
        {% end %}
    </tr>
    {% for t in tasks %}
    <tr>
        <td><a href="/dataset/{{ url_escape(tasks[t]['dataset_id']) }}/task/{{ url_escape(t) }}">{{ tasks[t]['job_index'] }} / {{ tasks[t]['task_index'] }}</a></td>
        <td>{{ tasks[t]['name'] }}</td>
        <td>{{ tasks[t]['failures'] }}</td>
        {% if (current_user) %}
        <td><button class="set_status" onclick='set_tasks_and_jobs_status(dataset_id, ["{{ tasks[t]['task_id'] }}"], "reset", "{{ passkey }}");'>Reset</button></td>
        <td><button class="set_status" onclick='set_tasks_status(dataset_id, ["{{ tasks[t]['task_id'] }}"], "suspended", "{{ passkey }}");'>Suspend</button></td>
        {% end %}
    </tr>
    {% end %}
</table>

{% 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 type="text/javascript">
var dataset_id = "{{ list(tasks.values())[0]['dataset_id'] if tasks else '' }}";
var task_ids_on_page = [
    {% for t in tasks %}
        "{{tasks[t]['task_id']}}",
    {% end %}
];
{% end %}
</script>
{% end %}
