{% extends "pyfarm/user_interface/layout.html" %}
{% block title %}Queues{% endblock %}
{% block jobqueues_nb_class %}active{% endblock %}
{% block content %}

<form method="GET" action="{{ url_for('jobqueues_index_ui') }}" class="form-inline" role="form" style="margin-top: 15px;">
  <div class="btn-group">
    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="state-dropdown-menu" aria-expanded="true">
      Job States <span class="caret"></span>
    </button>
    <ul class="dropdown-menu dropdown-menu-form" role="menu" aria-labelledby="state-dropdown-menu">
      <li>
        <label class="checkbox">
          {% if filters.state_paused %}
          <input type="checkbox" name="state_paused" value="true" checked/>
          {% else %}
          <input type="checkbox" name="state_paused" value="true"/>
          {% endif %}
          Paused
        </label>
      </li>
      <li>
        <label class="checkbox">
          {% if filters.state_queued %}
          <input type="checkbox" name="state_queued" value="true" checked/>
          {% else %}
          <input type="checkbox" name="state_queued" value="true"/>
          {% endif %}
          Queued
        </label>
      </li>
      <li>
        <label class="checkbox">
          {% if filters.state_running %}
          <input type="checkbox" name="state_running" value="true" checked/>
          {% else %}
          <input type="checkbox" name="state_running" value="true"/>
          {% endif %}
          Running
        </label>
      </li>
      <li>
        <label class="checkbox">
          {% if filters.state_failed %}
          <input type="checkbox" name="state_failed" value="true" checked/>
          {% else %}
          <input type="checkbox" name="state_failed" value="true"/>
          {% endif %}
          Failed
        </label>
      </li>
      <li>
        <label class="checkbox">
         {% if filters.state_done %}
          <input type="checkbox" name="state_done" value="true" checked/>
          {% else %}
          <input type="checkbox" name="state_done" value="true"/>
          {% endif %}
          Done
        </label>
      </li>
    </ul>
  </div>
  <input type="submit" class="btn" value="Filter">
</form>

<div class="tree" style="margin-top:12px">
<ul>
  {% for queue in jobqueues recursive %}
  <li>
    <span>
      <i class="glyphicon glyphicon-minus-sign"></i>{{ queue.path() }}
      <p>
        Agents min / current / max: {{ queue.minimum_agents or "-"}} / {{ queue.num_assigned_agents() }} / {{ queue.maximum_agents or "-" }}<br/>
        Priority: {{ queue.priority }}<br/>
        Weight: {{ queue.weight }}
      </p>
    </span>
    <a href="{{ url_for('single_jobqueue_ui', queue_id=queue.id) }}" title="Edit Queue">
      <i class="glyphicon glyphicon-pencil"></i>
    </a>
    <form style="display: inline;" role="form" method="POST" action="{{ url_for('delete_jobqueue_ui', queue_id=queue.id) }}">
      <label for="remove-queue-{{queue.id}}-submit" class="clickable-icon" title="Delete Jobqueue"><i class="glyphicon glyphicon-trash" aria-hidden="true"></i></label>
      <input id="remove-queue-{{queue.id}}-submit" type="submit" class="hidden" onclick="return confirm('Are you sure you want to delete this jobqueue?');"/>
    </form>
    {% if queue.children or queue.jobs.count() != 0 %}
    <ul>
      {{ loop(queue.child_queues_sorted()) }}
      <li><a href="{{ url_for('jobqueue_create_ui', parent=queue.id) }}" class="btn btn-default" role="button">Create Subqueue</a></li>
      {% for job in queue.child_jobs(filters=filters) %}
      <li>
        <div class="panel {{ 'panel-success' if job.state == WorkState.DONE }} {{ 'panel-danger' if job.state == WorkState.FAILED }} {{ 'panel-default' if job.state == None }} {{ 'panel-info' if job.state == WorkState.RUNNING }} {{ 'panel-warning' if job.state == WorkState.PAUSED }}" style="max-width:50%;margin-bottom:0">
          <div class="panel-heading"><h3 class="panel-title">{{ job.title }}</h3></div>
          <div class="panel-body">
            <a style="float:right" href="{{ url_for('single_job_ui', job_id=job.id) }}" title="View Job">
              <i class="glyphicon glyphicon-eye-open"></i>
            </a>
            State: {{ job.state or "queued" }}<br/>
            Agents min / current / max: {{ job.minimum_agents or "-"}} / {{ job.num_assigned_agents() }} / {{ job.maximum_agents or "-" }}<br/>
            Priority: {{ job.priority }}<br/>
            Weight: {{ job.weight }}<br/>
          </div>
        </div>
      </li>
      {% endfor %}
    </ul>
    {% endif %}
  </li>
  {% endfor %}
  <li><a href="{{ url_for('jobqueue_create_ui') }}" class="btn btn-default" role="button">Create</a></li>
  {% for job in top_level_jobs %}
  <li>
    <div class="panel {{ 'panel-success' if job.state == WorkState.DONE }} {{ 'panel-danger' if job.state == WorkState.FAILED }} {{ 'panel-default' if job.state == None }} {{ 'panel-info' if job.state == WorkState.RUNNING }} {{ 'panel-warning' if job.state == WorkState.PAUSED }}" style="max-width:50%;margin-bottom:0">
      <div class="panel-heading"><h3 class="panel-title">{{ job.title }}</h3></div>
      <div class="panel-body">
        <a style="float:right" href="{{ url_for('single_job_ui', job_id=job.id) }}" title="View Job">
          <i class="glyphicon glyphicon-eye-open"></i>
        </a>
        State: {{ job.state or "queued" }}<br/>
        Agents min / current / max: {{ job.minimum_agents or "-"}} / {{ job.num_assigned_agents() }} / {{ job.maximum_agents or "-" }}<br/>
        Priority: {{ job.priority }}<br/>
        Weight: {{ job.weight }}<br/>
      </div>
    </div>
  </li>
  {% endfor %}
</ul>
</div>
{% endblock %}
