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

{% block page_title %}{{ api_cmd.args.package }}{% 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 }}/{{ values.sourceversion }}/" title="Build logs">{{ values.sourceversion }}</a>
									{% endif %}
								</td>
								<td>
									{% if values.sourceversion %}
										[<a href="{{ values.dsc_url }}" title="Source package URL">dsc</a>|<a href="{{ values.dsc_url|mbd_dirname }}/" title="Browse package pool directory">pool</a>]
									{% endif %}
								</td>
								<td>
									{% if values.migrates_to %}
										{% if values.sourceversion and not values.is_migrated %}
											<a class="button-migrate" title="...to {{ values.migrates_to }}"
												 href="/mini_buildd/api?command=migrate&amp;package={{ values.source|urlencode }}&amp;distribution={{ values.distribution|urlencode }}&amp;version={{ values.sourceversion|urlencode }}&amp;output=referer">Migrate</a>
										{% 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 %}
										<a class="button-remove"
											 title="...from {{ values.distribution }}"
											 href="/mini_buildd/api?command=remove&amp;package={{ values.source|urlencode }}&amp;distribution={{ values.distribution|urlencode }}&amp;version={{ values.sourceversion|urlencode }}&amp;output=referer">Remove</a>
									{% endif %}
								</td>
								<td>
									{{ values.rollbacks|length }}/{{ values.rollback }} (<a id="rollbacks_{{ values.distribution }}_header" href="javascript:mbdToggleElement('rollbacks_{{ values.distribution }}','rollbacks_{{ values.distribution }}_header','hide','show')" >show</a>)
									<div id="rollbacks_{{ values.distribution }}" style="display: none;">
										{% for rollback in values.rollbacks|dictsort:"no" %}
											<br />
											<div>
												<a class="button-remove"
													 title="Remove {{ rollback.sourceversion }} from {{ rollback.distribution }}"
													 href="/mini_buildd/api?command=remove&amp;package={{ rollback.source|urlencode }}&amp;distribution={{ rollback.distribution|urlencode }}&amp;version={{ rollback.sourceversion|urlencode }}&amp;output=referer">{{ rollback.no }}</a>
												{% if not values.sourceversion %}
													<a class="button-migrate-rollback"
														 title="Restore rollback {{ rollback.sourceversion }} from {{ rollback.distribution }}"
														 href="/mini_buildd/api?command=migrate&amp;package={{ rollback.source|urlencode }}&amp;distribution={{ rollback.distribution|urlencode }}&amp;version={{ rollback.sourceversion|urlencode }}&amp;output=referer">{{ rollback.no }}</a>
												{% endif %}
												[<a title="Get dsc of {{ rollback.sourceversion }} from {{ rollback.distribution }}"
														href="{{ rollback.dsc_url }}">dsc</a>|<a href="/mini_buildd/log/{{ repository.identity }}/{{ api_cmd.args.package }}/{{ rollback.sourceversion }}/" title="Build logs">logs</a>]
											</div>
											 {% endfor %}
									</div>

								</td>

								<td>
									{% if values.sourceversion and values.uploadable %}
										<a class="button-rebuild"
											 title="...in {{ values.distribution }}"
											 href="/mini_buildd/api?command=port&amp;package={{ values.source|urlencode }}&amp;from_distribution={{ values.distribution|urlencode }}&amp;to_distributions={{ values.distribution|urlencode }}&amp;version={{ values.sourceversion|urlencode }}&amp;output=referer">Rebuild</a>
									{% endif %}
								</td>
								<td>
									{% if values.sourceversion %}
										Port (<a id="port_{{ values.distribution }}_header"
														 href="javascript:mbdToggleElement('port_{{ values.distribution }}','port_{{ values.distribution }}_header','hide','show')" >show</a>)
										<div id="port_{{ values.distribution }}" style="display: none;">
											<form action="/mini_buildd/api" method="get">
												<div>
													<input type="hidden" name="command" value="port" />
													<input type="hidden" name="package" value="{{ values.source }}" />
													<input type="hidden" name="from_distribution" value="{{ values.distribution }}" />
													<input type="hidden" name="version" value="{{ values.sourceversion }}" />
													<input id="mbd_port_filter_{{ values.distribution }}" type="text" title="Bulk-select distributions via regex" onchange="mbdSelectByRegex('mbd_port_to_distributions_{{ values.distribution }}', 'mbd_port_filter_{{ values.distribution }}')"/>
													<br />
													<select id="mbd_port_to_distributions_{{ values.distribution }}" name="to_distributions" size="10" multiple="multiple" title="Distribution(s) to port to">
														{% mbd_distribution_options repository uploadable=True experimental=values.experimental %}
													</select>
													<input type="hidden" name="output" value="referer" />
													<br />
													<input type="submit" value="Port" title="Port this package version to other distribution(s)" />
												</div>
											</form>
										</div>
									{% 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 -->
	{% include "mini_buildd/snippet_manage_subscriptions.html" with repositories=repositories package=api_cmd.args.package %}

{% endblock %}
