{% extends "base.html" %}

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

{% block container %}
  <div class="container-fluid">
    <div class="btn-group btn-group-justified">
        <a id="btn-active" class="btn btn-default btn-large" href="/tasks?limit=100&amp;state=STARTED">Active: {{ sum(map(lambda x:x.get('active') or 0, workers.values() )) }}</a>
        <a id="btn-processed" class="btn btn-default btn-large" href="/tasks?limit=100">Processed: {{ sum(map(lambda x:x.get('task-received') or 0, workers.values() )) }}</a>
        <a id="btn-failed" class="btn btn-default btn-large" href="/tasks?limit=100&amp;state=FAILURE">Failed: {{ sum(map(lambda x:x.get('task-failed') or 0, workers.values() )) }}</a>
        <a id="btn-succeeded" class="btn btn-default btn-large" href="/tasks?limit=100&amp;state=SUCCESS">Succeeded: {{ sum(map(lambda x:x.get('task-succeeded') or 0, workers.values() )) }}</a>
        <a id="btn-retried" class="btn btn-default btn-large" href="/tasks?limit=100&amp;state=RETRY">Retried: {{ sum(map(lambda x:x.get('task-retried') or 0, workers.values() )) }}</a>
    </div>

    <div class="panel panel-default">
        <div class="panel-body">

    <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>
          <li><a href="#" onclick="flower.refresh_selected(event);">Refresh</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>Worker Name</th>
        <th>Status</th>
        <th>Active</th>
        <th>Processed</th>
        <th>Failed</th>
        <th>Succeeded</th>
        <th>Retried</th>
        <th>Load Average</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="{{ '/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>{{ info['active'] }}</td>
        <td>{{ info.get('task-received', 0) }}</td>
        <td>{{ info.get('task-failed', 0) }}</td>
        <td>{{ info.get('task-succeeded', 0) }}</td>
        <td>{{ info.get('task-retried', 0) }}</td>
        <td>{{ humanize(info['loadavg']) }}</td>
      </tr>
      {% end %}
      </tbody>
    </table>

        </div>
    </div>

  </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>
              <td></td>
              <td></td>
          </tr>
      </table>
  </div>

{% end %}
