{% extends 'main_header.html' %}
{% block body %}
<table class="one-column-emphasis context-menu">
    <thead>
    <tr class="one-column-emphasis-first">
        <th scope="col"><input type="checkbox" name="select_all" onclick="toggle_all_checkboxes(this)"/> </th>
        <th scope="col">Trigger On/Alive</th>
        <th scope="col">Process Name</th>
        <th scope="col">Trigger Frequency</th>
        <th scope="col"></th>  <!-- Trigger Now -->
        <th scope="col">Next Run In</th>
        <th scope="col">Next Timeperiod</th>
    </tr>
    </thead>
    <tbody>

    {%- for row in details.managed_entries -%}
    {%- if row.is_on != row.is_alive -%}
    <tr class="state_inconsistent">
    {%- elif not row.is_alive -%}
    <tr class="state_inactive">
    {%- else -%}
    <tr>
    {%- endif -%}
        <td>
            {% set value = "{ process_name: '" + row.process_name + "', timeperiod: 'NA' }" %}
            <input type="checkbox" name="batch_processing" value="{{ value }}"/>
        </td>
        <td>{{ row.is_on }} / {{ row.is_alive }}</td>
        <td>{{ row.process_name }}</td>
        <td>
            <form method="GET" action="/action/change_interval/">
                <input type="hidden" name="process_name" value="{{ row.process_name }}" />
                <input type="hidden" name="timeperiod" value="NA" />
                <input type="text" size="8" maxlength="32" name="interval" value="{{ row.trigger_frequency }}" />
                <input type="submit" title="Apply" class="fa-input" value="&#xf00c;"/>
            </form>
        </td>
        <td>
            <form method="GET" action="/action/trigger_now/">
                <input type="hidden" name="process_name" value="{{ row.process_name }}" />
                <input type="hidden" name="timeperiod" value="NA" />
                <input type="submit" class="action_button fa-input" title="Trigger" value="&#xf1d9;&nbsp;Trigger"/>
            </form>
        </td>
        <td>{{ row.next_run_in }}</td>
        <td>{{ row.next_timeperiod }}</td>
    </tr>
    {%- endfor -%}

    </tbody>
</table>

<table class="one-column-emphasis">
    <thead>
    <tr class="one-column-emphasis-first">
        <th scope="col" width="15%">
            <div class="table_layout">
                <div class="table_layout_element">
                    <form method="GET" action="/gc/flush_all/" onsubmit="refreshWithDelay()">
                        <input type="submit" title="Flush All" class="action_button fa-input" value="&#xf1b8;&nbsp;Flush&nbsp;All"/>
                    </form>
                </div>
                <div class="table_layout_element">
                    <form method="GET" action="/gc/refresh/" onsubmit="refreshWithDelay()">
                        <input type="submit" title="Refresh" class="action_button fa-input" value="&#xf021;&nbsp;Refresh"/>
                    </form>
                </div>
            </div>
        </th>
        <th scope="col" width="15%">Process Name</th>
        <th scope="col">Units Of Work</th>
    </tr>
    </thead>
    <tbody>

    <!-- nonEmptyQ flow is a hack for Jinja2 to overcome variable visibility scope problem -->
    {% set nonEmptyQ = [] %}
    {%- for process_name, q in details.reprocess_uows.items() -%}
    {%- if q.queue|length != 0 -%}
    {%- if nonEmptyQ.append('A') -%}{%- endif -%}
    <tr>
        <td>
            <form method="GET" action="/gc/flush_one/" onsubmit="refreshWithDelay()">
                <input type="hidden" name="process_name" value="{{ process_name }}" />
                <input type="submit" title="Flush" class="action_button fa-input" value="&#xf1b8;&nbsp;Flush"/>
            </form>
        </td>
        <td>{{ process_name }}</td>
        <td>
            {%- for priority_entry in q.queue -%}
                {{ priority_entry.entry.timeperiod }}
                {%- if not loop.last -%}
                    {{ ", " }}
                {%- endif -%}
            {%- endfor -%}
        </td>
    </tr>
    {%- endif -%}
    {%- endfor -%}

    {%- if nonEmptyQ|length == 0 -%}
    <tr>
        <td><input type="submit" name="Flush" class="action_button fa-input" value="&#xf1b8;&nbsp;Flush" disabled/></td>
        <td>Empty</td>
        <td>Empty</td>
    </tr>
    {%- endif -%}

    </tbody>
</table>


<table class="one-column-emphasis">
    <thead>
    <tr class="one-column-emphasis-first">
        <th scope="col">Build Version</th>
        <th scope="col">Uptime</th>
        <th scope="col">Resident Memory</th>
        <th scope="col">Virtual Memory</th>
        <th scope="col">% CPU Core Load</th>
        <th scope="col">Available Physical Memory</th>
        <th scope="col">Available Virtual Memory</th>
    </tr>
    </thead>
    <tbody>

    <tr>
        <td>{{ scheduler_version() }}</td>
        <td>{{ scheduler_uptime() }}</td>
        <td>{{ details.footprint.memory_rss }}</td>
        <td>{{ details.footprint.memory_vms }}</td>
        <td>{{ details.footprint.cpu_utilization }}</td>
        <td>{{ details.footprint.mem_virtual_free }}</td>
        <td>{{ details.footprint.mem_swap_free }}</td>
    </tr>

    </tbody>
</table>

{% import 'block_context_menu.html' as context_menu %}
{{ context_menu.trigger_menu(false) }}

{% endblock %}
