{% extends "mini_buildd/base.html" %}
{% load staticfiles %}
{% load mini_buildd_tags %}

{% block title %}mini-buildd{% endblock %}
{% block page_title %}{% mbd_title %}{% endblock %}
{% block page_sub_title %}
	{% if not daemon.is_busy %}
		{% if daemon.is_running %}
			{% mbd_api "stop" output="referer" %}
		{% else %}
			{% mbd_api "start" output="referer" %}
		{% endif %}
	{% endif %}
	<span class="status {% if daemon.is_busy %}busy{% elif daemon.is_running %}running{% else %}stopped{% endif %}">
		{% if daemon.is_busy %}Busy...{% elif daemon.is_running %}Running{% else %}Stopped{% endif %}: {{ daemon.model }}
	</span>
	<br />
	{% mbd_api "getkey" %}
	{% mbd_api "getdputconf" %}
	{% mbd_api "logcat" %}
{% endblock %}

{% block content %}
	<div id="mbd_index_status">

		{% if not daemon.is_running %}
			{% mbd_api "autosetup" %}
		{% endif %}

		<div id="mbd_index_repositories" class="box">
			<h1 class="box-caption">
				{% if daemon.packages.items %}<img src="{% static "img/progress_blue.gif" %}" alt="Packaging..." title="Packaging..." style="margin: -5px 0 -5px 0; padding: 0" />{% endif %}
				Packager: {{ daemon.packages|length }} packaging</h1>

			{% if daemon.packages.items %}
			{% include "includes/mbd_packager_status.html" with packages=daemon.packages.values %}
			{% endif %}

			<details>
				<summary class="header">Last packages: {{ daemon.last_packages|length }}</summary>
				{% if daemon.last_packages %}
				{% include "includes/mbd_packager_status.html" with packages=daemon.last_packages %}
				{% endif %}
			</details>

			<h2 title="Repositories in use">Repositories:</h2>
			<ul>
				{% for r in repositories %}
				<li>
					<span class="status {{ r.get_status_display }}" title="{{ r.mbd_get_status_display }}">{{ r }}</span>
					(<a title="Go to repository overview page" href="/mini_buildd/repositories/{{ r.identity }}/">Overview</a>)
					{% if r.external_home_url %}
					(<a href="{{ r.external_home_url }}" title="Link to the repository's external documentation">ExtHome</a>)
					{% endif %}
				</li>
				{% empty %}
				<li>No repositories.</li>
				{% endfor %}
			</ul>

			<h3 title="Extra functionality">Extras:</h3>
			{% mbd_api "portext" %}
			{% mbd_api "keyringpackages" %}
			{% mbd_api "testpackages" %}
		</div>

		<div id="mbd_index_chroots" class="box">
			<h1 class="box-caption">
				{% if daemon.builds.items %}<img src="{% static "img/progress_blue.gif" %}" alt="Building..." title="Building..." style="margin: -5px 0 -5px 0; padding: 0" />{% endif %}
				Builder: {{ daemon.build_queue }} building
			</h1>
			{% if daemon.builds.items %}
				{% include "includes/mbd_builder_status.html" with builds=daemon.builds.values %}
			{% endif %}

			<details>
				<summary class="header">Last builds: {{ daemon.last_builds|length }}</summary>
				{% if daemon.last_builds %}
					{% include "includes/mbd_builder_status.html" with builds=daemon.last_builds %}
				{% endif %}
			</details>

			<h2 title="Chroots in use">Chroots:</h2>
			<ul>
				{% for c in chroots %}
					<li><span class="status {{ c.get_status_display }}" title="{{ c.mbd_get_status_display }}">{{ c }}</span></li>
				{% empty %}
					<li>No chroots.</li>
				{% endfor %}
			</ul>
		</div>

		<div id="mbd_index_remotes" class="box">
			<h1 class="box-caption">Network: {{ remotes|length }} remotes</h1>
			<h2 title="Remotes in use">Remotes:</h2>
			<ul>
				{% for r in remotes %}
					<li>
						<span class="status {{ r.get_status_display }}" title="{{ r.mbd_get_status_display }}">{{ r }}</span>
						(<a title="Visit remote" href="http://{{ r.http }}/">Visit</a>)
					</li>
				{% empty %}
					<li>No remotes.</li>
				{% endfor %}
			</ul>
		</div>
	</div>
{% endblock %}
