{% extends "base.html" %}

{% block navbar %}
  {% module Template("navbar.html", active_tab="workers", absolute_url=absolute_url) %}
{% end %}

{% block container %}
  <div class="container-fluid">
    <div class="page-header">
      <h1>Workers</h1>
    </div>

    <div class="btn-toolbar">
      <div class="btn-group">
        <button class="btn" onclick="flower.toggle_selected_workers(event);"><input id="select-workers-toggler" type="checkbox" style="margin: 0;"></button>
        <button class="btn dropdown-toggle" data-toggle="dropdown"><span
          class="caret"></span></button>
        <ul class="dropdown-menu">
          <li><a href="#" onclick="flower.select_all_workers(event);">All</a></li>
          <li><a href="#" onclick="flower.select_none_workers(event);">None</a></li>
        </ul>
      </div>

      <div class="btn-group">
        <button class="btn" onclick="flower.shutdown_selected(event);">Shut Down</button>
        <button class="btn dropdown-toggle" data-toggle="dropdown"><span
          class="caret"></span></button>
        <ul class="dropdown-menu">
          <li><a href="#" onclick="flower.shutdown_selected(event);">Shut Down</a></li>
          <li><a href="#" onclick="flower.restart_selected(event);">Restart Pool</a></li>
        </ul>
      </div>
    </div>

    <table id="workers-table" class="table table-bordered table-striped">
      <thead>
      <tr>
        <th style="width: 15px; min-width: 15px;"></th>
        <th>Name</th>
        <th>Status</th>
        <th>Concurrency</th>
        <th>Completed Tasks</th>
        <th>Running Tasks</th>
        <th>Queues</th>
      </tr>
      </thead>
      <tbody>
      {% for name,info in workers.items() %}
      <tr id="{{ url_escape(name) }}">
        <td class="is_selected"><input type="checkbox"></td>
        <td><a href="{{ absolute_url('worker/' + name) }}">{{ name }}</a></td>
        <td>
          {% if info['status'] %}
          <span class="label label-success">Online</span>
          {% else %}
          <span class="label label-important">Offline</span>
          {% end %}
        </td>
        <td>{{ humanize(info['concurrency']) }}</td>
        <td>{{ info['completed_tasks'] }}</td>
        <td>{{ info['running_tasks'] }}</td>
        <td>{{ humanize(info['queues']) }}</td>
      </tr>
      {% end %}
      </tbody>
    </table>

    <p>
    <strong>Broker:</strong> {{ broker }}
    </p>

  </div>

  <div class="hidden">
      <table>
          <tr id="workers-table-row">
              <td class="is_selected"><input type="checkbox"></td>
              <td><a href=""></a></td>
              <td><span class="label label-success">Online</span></td>
              <td></td><td></td><td></td><td></td>
          </tr>
      </table>
  </div>

{% end %}
