{% extends 'main_header.html' %}
{% block body %}

<div class="page-title-bar">
    <!-- <h2>scheduler freerun entries</h2> -->
    {% import 'block_enable_auto_refresh.html' as block_enable_refresh %}
    {{ block_enable_refresh.enable_auto_refresh() }}
</div>

<div class="u-max-full-width freerun-container">

    <table class="u-full-width table-entries context-menu">
        <thead>
            <tr class="table-entries-header">
                <th scope="col"><input type="checkbox" name="select_all" onclick="toggleAllCheckboxes(this)"/></th>
                <th scope="col" class="pl-1">Trigger On/Alive</th>
                <th scope="col">Process Name</th>
                <th scope="col">Entry Name</th>
                <th scope="col">Trigger Frequency</th>
                <th scope="col"></th> <!-- Trigger Now -->
                <th scope="col">Next Run In</th>
                <th scope="col">Arguments</th>
                <th scope="col"></th> <!-- View Uow --><!-- Uow Log --><!-- Timeline -->
                <th scope="col"></th> <!-- Cancel Uow --><!-- Edit -->
            </tr>
        </thead>
        <tbody>

            {%- for row in details.freerun_entries %}
            {%- set tr_class = '' -%}
                {%- if row.is_on != row.is_alive -%}
                    {%- set tr_class = 'state_inconsistent' -%}
                {%- elif not row.is_alive -%}
                    {%- set tr_class = 'state_inactive' -%}
                {%- endif -%}
            <tr class="{{ tr_class }}">
                <td>
                    {% set value = "{ process_name: '" + row.process_name + "', entry_name: '" + row.entry_name + "' }" %}
                    <input type="checkbox" name="batch_processing" value="{{ value }}"/>
                </td>
                <td class="pl-1">{{ row.is_on }} / {{ row.is_alive }}</td>
                <td>{{ row.process_name }}</td>
                <td>{{ row.entry_name }}</td>
                <td>
                    <form class="table-form" method="POST" action="/scheduler/freerun/entry/interval/">
                        <input type="hidden" name="process_name" value="{{ row.process_name }}"/>
                        <input type="hidden" name="entry_name" value="{{ row.entry_name }}"/>
                        <input type="text" size="8" maxlength="32" name="interval" value="{{ row.trigger_frequency }}"/>
                        <button type="submit" class="action_button btn-icons btn-center" title="Apply">
                            <i class="fa fa-check"></i></button>
                    </form>
                </td>
                <td>
                    <form class="table-form" method="POST" action="/scheduler/freerun/entry/trigger/">
                        <input type="hidden" name="process_name" value="{{ row.process_name }}"/>
                        <input type="hidden" name="entry_name" value="{{ row.entry_name }}"/>
                        <button type="submit" class="action_button btn-center" title="Trigger">
                            <i class="fa fa-bolt"></i><span>Trigger</span></button>
                    </form>
                </td>

                <td>{{ row.next_run_in }}</td>
                <td style="max-width: 180px">{{ row.arguments|jsonify }}</td>
                <td class="button-col">
                    {% set url = 'action=scheduler/freerun/uow' + '&process_name=' + row.process_name + '&entry_name=' + row.entry_name %}
                    <form class="table-form inline" method="GET"
                          onsubmit="openViewerWindow('/scheduler/viewer/object/?{{ url }}', 'View Uow'); return false;">
                        <button type="submit" class="action_button btn-icons btn-center" title="View Uow">
                            <i class="fa fa-file-code-o"></i><span>Uow</span></button>
                    </form>

                    {% set url = 'action=scheduler/freerun/uow/log' + '&process_name=' + row.process_name + '&entry_name=' + row.entry_name %}
                    <form class="table-form inline" method="GET"
                          onsubmit="openViewerWindow('/scheduler/viewer/object/?{{ url }}', 'Uow Log'); return false;">
                        <button type="submit" class="action_button btn-icons btn-center" title="Log Uow">
                            <i class="fa fa-file-text-o"></i><span>Log Uow</span></button>
                    </form>

                    {% set url = 'action=scheduler/freerun/timeline' + '&process_name=' + row.process_name + '&entry_name=' + row.entry_name %}
                    <form class="table-form inline" method="GET"
                          onsubmit="openViewerWindow('/scheduler/viewer/object/?{{ url }}', 'Job Timeline'); return false;">
                        <button type="submit" class="action_button btn-icons btn-center" title="Timeline">
                            <i class="fa fa-history"></i><span>Timeline</span></button>
                    </form>
                </td>
                <td class="button-col">
                    <form class="table-form inline" method="GET" action="/scheduler/freerun/uow/cancel/">
                        <input type="hidden" name="process_name" value="{{ row.process_name }}"/>
                        <input type="hidden" name="entry_name" value="{{ row.entry_name }}"/>
                        <button type="submit" class="action_button btn-icons btn-center" title="Cancel Uow">
                            <i class="fa fa-remove"></i><span>Cancel</span></button>
                    </form>

                    {% set url = '/scheduler/viewer/schedulable/?process_name=' + row.process_name + '&entry_name=' + row.entry_name + '&is_new_entry=False' %}
                    <form class="table-form inline" method="GET"
                          onsubmit="openViewerWindow('{{ url }}', 'Edit Freerun Trigger'); return false;">
                        <button type="submit" class="action_button btn-icons btn-center" title="Edit">
                            <i class="fa fa-edit"></i><span>Edit</span></button>
                    </form>
                </td>
            </tr>
            {%- endfor %}

            <tr>
                <td colspan="13" style="text-align: right">
                    {% set url = '/scheduler/viewer/schedulable/?is_new_entry=True' %}
                    <a href="#"
                        onclick="openViewerWindow('{{ url }}', 'New Freerun Trigger'); return false;">
                        <i class="fa fa-plus"></i><span>&nbsp;Add New Freerun Trigger</span>
                    </a>
                </td>
            </tr>

        </tbody>
    </table>
</div>
{% import 'block_context_menu.html' as context_menu %}
{{ context_menu.trigger_menu(true) }}

{% endblock %}
