{% extends "mini_buildd/api.html" %}
{% load mini_buildd_tags %}

{% block page_title %}{{ api_cmd.args.package.value }}{% endblock %}
{% block page_sub_title %}Source package{% endblock %}

{% block content %}
	<div id="mbd-api-show">
		{% for repository, codenames in api_cmd.repositories %}
			<div class="box">
				<h1 class="box-caption">
					<a class="box-anchor"
						 title="goto {{ repository }}"
						 href="/mini_buildd/repositories/{{ repository.identity }}/">{{ repository }}
					</a>
				</h1>

				<table>
					<tr>
						<th>Distribution</th>
						<th>Component</th>
						<th colspan="2">Version</th>
						<th>Migration</th>
						<th>Removal</th>
						<th>Rollbacks</th>
						<th colspan="2">Extras</th>
					</tr>
					{% for codename, distributions in codenames %}
						<tr>
							<td class="codename" colspan="9">{{ codename }}</td>
						</tr>
						{% for values in distributions|dictsort:"sort_no" %}
							<tr>
								<td class="distribution">{{ values.distribution }}</td>
								<td>{{ values.component }}</td>
								<td class="version">
									{% if values.sourceversion %}
										<a href="/mini_buildd/log/{{ repository.identity }}/{{ api_cmd.args.package.value }}/{{ values.sourceversion }}/" title="Build logs">{{ values.sourceversion }}</a>
									{% endif %}
								</td>
								<td>
									{% if values.sourceversion %}
										[<a href="{{ values.dsc_path }}" title="Source package URL">dsc</a>|<a href="{{ values.dsc_path|mbd_dirname }}/" title="Browse package pool directory">pool</a>]
									{% endif %}
								</td>
								<td>
									{% if values.migrates_to %}
										{% if values.sourceversion and not values.is_migrated %}
											{% mbd_api "migrate" title="...to "|add:values.migrates_to value_package=values.source value_distribution=values.distribution value_version=values.sourceversion output=referer %}
										{% elif values.sourceversion %}
											<div title="...to {{ values.migrates_to }}"><b>Migrated</b></div>
										{% else %}
											<div title="...to {{ values.migrates_to }}">Migrates</div>
										{% endif %}
									{% endif %}
								</td>
								<td>
									{% if values.sourceversion %}
										{% mbd_api "remove" title="...from "|add:values.distribution value_package=values.source value_distribution=values.distribution value_version=values.sourceversion output=referer %}
									{% endif %}
								</td>
								<td>
									{{ values.rollbacks|length }}/{{ values.rollback }}
									<details>
										<summary>Rollbacks</summary>
										{% for rollback in values.rollbacks|dictsort:"no" %}
											<br />
											<div>
												{% mbd_api "remove" name=rollback.no title="Remove "|add:rollback.sourceversion|add:" from "|add:rollback.distribution value_package=rollback.source value_distribution=rollback.distribution value_version=rollback.sourceversion output=referer %}
												{% if not values.sourceversion %}
													{% mbd_api "migrate" name=rollback.no title="Restore rollback "|add:rollback.sourceversion|add:" from "|add:rollback.distribution value_package=rollback.source value_distribution=rollback.distribution value_version=rollback.sourceversion output=referer %}
												{% endif %}
												[<a title="Get dsc of {{ rollback.sourceversion }} from {{ rollback.distribution }}"
														href="{{ rollback.dsc_path }}">dsc</a>|<a href="/mini_buildd/log/{{ repository.identity }}/{{ api_cmd.args.package }}/{{ rollback.sourceversion }}/" title="Build logs">logs</a>]
											</div>
										{% endfor %}
									</details>

								</td>

								<td>
									{% if values.sourceversion and values.uploadable %}
										{% mbd_api "port" name="Rebuild" title="...in "|add:values.distribution value_package=values.source value_from_distribution=values.distribution value_to_distributions=values.distribution value_version=values.sourceversion output=referer %}
									{% endif %}
								</td>
								<td>
									{% if values.sourceversion %}
										<details>
											<summary>Port Options</summary>
											{% mbd_api "port" title="Port this package version to other distribution(s)" value_package=values.source value_from_distribution=values.distribution value_version=values.sourceversion output=referer %}
										</details>
									{% endif %}
								</td>
							</tr>
						{% endfor %}
						<!-- omg. this tr is for some extra space only. fix in css -->
						<tr>
							<td colspan="8"></td>
						</tr>
					{% endfor %}
				</table>
			</div>
		{% endfor %}
	</div>

	<!-- Manage package specific subscriptions -->
	{% mbd_api "subscription" value_subscription=api_cmd.args.package.value|add:":" output=referer %}

{% endblock %}
