{% extends "admin/base_site.html" %}
{% load i18n admin_static %}
{% load url from future %}

{% block content_title %}<h1>{{ title }}</h1>{% endblock %}

{% block extrastyle %}
	{{ block.super }}
	<style>table {width: 100%;}</style>
{% endblock %}

{% block extrahead %}
	{{ block.super }}
	<script type="text/javascript" src="{% static "rq/jquery.js" %}"></script>
	<script type="text/javascript" src="{% static "rq/underscore.js" %}"></script>
	<script type="text/javascript" src="{% static "rq/rqdashboard.js" %}"></script>
{% endblock %}

{% block bodyclass %}dashboard{% endblock %}

{% block content %}
	<div id="content-main">
		<div class="module">
			<table id="queues">
				<caption>{% trans "Queues" %}</caption>
				<thead>
					<tr>
						<th>{% trans "Queue" %}</th>
						<th>{% trans "Jobs" %}</th>
					</tr>
				</thead>
				<tbody>
					{% for queue in queues %}
						<tr class="{% cycle "row2" "row1" %}">
							<td><a href="{% url "rq_queue" queue.name %}">{{ queue.name }}</a></td>
							<td>{{ queue.count }}</td>
						</tr>
					{% empty %}
						<tr><td colspan="2">{% trans "No queues" %}</td></tr>
					{% endfor %}
				</tbody>
			</table>
		</div>

		<div class="module">
			<table id="workers">
				<caption>{% trans "Workers" %}</caption>
				<thead>
					<tr>
						<th>{% trans "Worker" %}</th>
						<th>{% trans "Queues" %}</th>
						<th>{% trans "State" %}</th>
					</tr>
				</thead>
				<tbody>
					{% for worker in workers %}
						<tr class="{% cycle "row2" "row1" %}">
							<td><a href="{% url "rq_worker" worker.name %}">{{ worker.name }}</a></td>
							<td>{% for queue in worker.queues %}{{ queue.name }}{% if not forloop.last %}, {% endif %}{% endfor %}</td>
							<td>{{ worker.state }}</td>
						</tr>
					{% empty %}
						<tr><td colspan="3">{% trans "No workers" %}</td></tr>
					{% endfor %}
				</tbody>
			</table>
		</div>
	</div>

	<script type="text/template" name="error-row">
		<tr><td colspan="2">{% trans "Error fetching status" %}</td></tr>
	</script>

	<script type="text/template" name="no-queue-row">
		<tr><td colspan="2">{% trans "No queues" %}</td></tr>
	</script>

	<script type="text/template" name="queue-row">
		<tr class="<%= klass %>">
			<td><a href="<%= url %>"><%= name %></a></td>
			<td><%= count %></td>
		</tr>
	</script>

	<script type="text/template" name="no-worker-row">
		<tr><td colspan="3">{% trans "No workers" %}</td></tr>
	</script>

	<script type="text/template" name="worker-row">
		<tr class="<%= klass %>">
			<td><a href="<%= url %>"><%= name %></a></td>
			<td><%= queues %></td>
			<td><%= state %></td>
		</tr>
	</script>
{% endblock %}
