{% extends "mini_buildd/base.html" %}
{% block title %}{% block page_title %}{{ route|title }}{% endblock %}{% endblock %}
{% block subtitle %}{{ view.mbd_repositories|length }} repositories{% endblock %}
{% block menu_r %}
	<li>{% mbd_api_popup "keyring_packages" %}</li>
	<li>{% mbd_api_popup "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 section %}
	{% 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>
					<li>{% mbd_api_popup "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 %}
			<details>
				<summary><strong>{{ d }}</strong></summary>

				{% mbd_token as table_id %}
				<table id="{{ table_id }}">
					{% mbd_datatable table_id no_search='[1, 2, 3, 4]' %}
					<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_parse_distribution r d s 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_popup "sources_list" value_codenames=d.base_source.codename value_repositories=r.identity value_suites=s.suite.name value_snapshot=snap %}</li>
																		<li>{% mbd_api_popup "snapshot_delete" value_distribution=distribution.name value_name=snap %}</li>
																	</ul>
																</nav>
															</td>
														</tr>
													{% endfor %}
												</tbody>
												<tfoot>
													<tr>
														<th colspan="2">{% mbd_api_popup "snapshot_create" value_distribution=distribution.name %}</th>
													</tr>
												</tfoot>
											</table>
										</details>
									{% endif %}
								</td>
								<td>
									<nav>
										<ul>
											<li>{% mbd_api_popup "sources_list" value_codenames=d.base_source.codename value_repositories=r.identity value_suites=s.suite.name %}</li>
											{% if s.uploadable %}
												<li>{% mbd_api_popup "port_ext" value_distributions=distribution.name %}</li>
											{% endif %}
										</ul>
									</nav>
								</td>
							</tr>
						{% endfor %}
					</tbody>
				</table>
			</details>
		{% endfor %}
	{% endfor %}
{% endblock %}
