{% extends "mini_buildd/base.html" %}
{% block title %}{% block titledup %}{{ route|title }}{% endblock %}{% endblock %}
{% block tooltip %}{{ view.mbd_repositories|length }} repositories{% endblock %}
{% block menu %}
	<li>{% mbd_api "keyring_packages" %}</li>
	<li>{% mbd_api "test_packages" %}</li>
	<li><a href="{% url 'admin:mini_buildd_repository_changelist' %}"><img class="mbd-icon" src="{% static 'icons/categories/preferences-other.svg' %}" alt="Configure"></a></li>
{% endblock %}

{% block content %}
	{% if view.mbd_repositories %}
		{% for r in view.mbd_repositories %}
			<header class="mbd-grid-lcr">
				{% mbd_dict_get mbd.daemon.attention "repositories" as attention %}
				<h2 class="{{ attention|yesno:'mbd-attention,' }}" title="{{ attention|join:"&#10;" }}">{{ r }}</h2>
				<nav>
				</nav>
				<nav>
					<ul>
						{% if r.external_home_url %}
							<li><a href="{{ r.external_home_url }}" title="External doc for this repository">Manual</a></li>
						{% endif %}
						<li>{% mbd_api "uploaders" value_repositories=r.identity %}</li>
						<li><a href="{% url 'admin:mini_buildd_repository_change' r.identity %}"><img class="mbd-icon" src="{% static 'icons/categories/preferences-other.svg' %}" alt="Configure"></a></li>
					</ul>
				</nav>
			</header>

			{% for d in r.mbd_sorted_distributions %}
				<ul>
					<li><a href="{% url 'repositories' r.identity|add:'/dists/'|add:d.base_source.codename|add:'-'|add:r.identity|add:'-'|add:r.layout.suiteoption_set.all.first.suite.name %}">{{ d }}</a></li>
				</ul>
			{% endfor %}
		{% endfor %}
	{% elif view.mbd_repository %}
		{% with r=view.mbd_repository d=view.mbd_distribution %}
			{% mbd_token as table_id %}
			<table id="{{ table_id }}" style="width: 100%;">
				{% mbd_datatable table_id columns='[null, {"searchable": false}, {"searchable": false}, {"searchable": false}, {"searchable": false}]' %}
				<thead>
					<tr>
						<th>Distribution</th>
						<th>Flags</th>
						<th>Build Info</th>
						<th>Snapshots</th>
						<th>Menu</th>
					</tr>
				</thead>
				<tbody>
					{% for s in r.layout.suiteoption_set.all %}
						{% mbd_dict_get view.mbd_xtra s.suite.name as distribution %}
						<tr>
							<td>{{ distribution.name }}</td>
							<td>
								{% if s.uploadable %}<span class="mbd-notice" title="Uploadable (mandatory version regex)">U({{ distribution.mandatory_version_regex }})</span>{% endif %}
								{% if s.experimental %}<span class="mbd-warning" title="Experimental">E</span>{% endif %}
								{% if s.migrates_to %}<span class="mbd-success" title="Migrates to"> =&gt; {{ s.migrates_to.suite.name }}</span>{% endif %}
							</td>
							<td>
								<nav>
									<ul>
										{% if s.uploadable %}
											<li>
												<details>
													<summary>APT sources.list</summary>
													{% mbd_file content=distribution.apt_build_sources_list %}
												</details>
											</li>
											<li>
												<details>
													<summary>APT preferences</summary>
													{% mbd_file content=distribution.apt_build_preferences %}
												</details>
											</li>
										{% endif %}
									</ul>
								</nav>
							</td>
							<td>
								{% if not s.migrates_to and not s.experimental %}
									<details>
										<summary>{{ distribution.snapshots|length }} Snapshots</summary>
										{% mbd_token as snapshots_table_id %}
										<table id="{{ snapshots_table_id }}">
											{% mbd_datatable snapshots_table_id info='false' paging='false' searching='false' %}
											<thead>
												<tr>
													<th>Name</th>
													<th>Menu</th>
												</tr>
											</thead>
											<tbody>
												{% for snap in distribution.snapshots %}
													<tr>
														<td>{{ snap }}</td>
														<td>
															<nav>
																<ul>
																	<li>{% mbd_api "sources_list" value_codenames=d.base_source.codename value_repositories=r.identity value_suites=s.suite.name value_snapshot=snap %}</li>
																	<li>{% mbd_api "snapshot_delete" value_distribution=distribution.name value_name=snap %}</li>
																</ul>
															</nav>
														</td>
													</tr>
												{% endfor %}
											</tbody>
											<tfoot>
												<tr>
													<th colspan="2">{% mbd_api "snapshot_create" value_distribution=distribution.name %}</th>
												</tr>
											</tfoot>
										</table>
									</details>
								{% endif %}
							</td>
							<td>
								<nav>
									<ul>
										<li>{% mbd_api "sources_list" value_codenames=d.base_source.codename value_repositories=r.identity value_suites=s.suite.name %}</li>
										{% if s.uploadable %}
											<li>{% mbd_api "port_ext" value_distributions=distribution.name %}</li>
										{% endif %}
									</ul>
								</nav>
							</td>
						</tr>
					{% endfor %}
				</tbody>
			</table>
		{% endwith %}
	{% endif %}
{% endblock %}
