{% mbd_hash "mbd-events-"|add:id as table_id %}
<table id="{{ table_id }}">
	{% mbd_datatable table_id order='[0, "desc"]' no_search='[0, 5]' no_order='[5]' %}
	<thead>
		<tr>
			<th>Event</th>
			<th>Distribution</th>
			<th>Source</th>
			<th>Version</th>
			<th>Result</th>
			<th>Menu</th>
		</tr>
	</thead>
	<tbody>
		{% for e in events %}
			<tr>
				<td data-order="{{ e.timestamp|date:"U:u" }}">
					<a href="{% url 'events-dir' e.extra.bkey|add:"/"|add:e.json_file_name %}" title="{{ e.json_file_name }}">{{ e.timestamp|date:"r" }}</a>
				</td>
				<td>{{ e.distribution }}</td>
				<td>
					<span class="mbd-hidden">{{ e.source }}</span>  {# Needed to make name searchable via datatable #}
					{% mbd_api_popup "ls" name=e.source value_source=e.source hide_options=True %}
				</td>
				<td><a href="{% url 'events' e.source|add:"/"|add:e.version %}" title="Events for this package and version only">{{ e.version }}</a></td>
				<td class="{% mbd_cssmap 'events' e.type.name %}">
					<b>{{ e.type.name }}</b>: {{ e.strerror }}
				</td>
				<td>
					<nav>
						<ul>
							{% if e.extra.changes %}
								<li><a href="{% url 'events-dir' e.extra.changes %}"><img class="mbd-icon" src="{% static 'icons/mimetypes/text-x-changelog.svg' %}" title="{{ e.extra.changes }}" alt="Changes"></a></li>
							{% endif %}
							{% if e.type.name == "FAILED" %}
								<li>{% mbd_api_popup "retry" title="Retry "|add:e.version value_bkey=e.extra.bkey hide_options=True %}</li>
							{% endif %}
							{% if e.type.name == "BUILDING" %}
								<li>{% mbd_api_popup "cancel" value_bkey=e.extra.bkey hide_options=True %}</li>
							{% endif %}

							{% if e.type.name == "BUILT" or e.type.name == "BUILDING" %}
								<li><a href="{% url 'builds-dir' e.extra.buildlog %}" title="Build Log">{{ e.extra.architecture }}({% if e.type.name == "BUILT" %}{% spaceless %}{% mbd_sbuild_status e.extra %}{% endspaceless %}{% endif %})</a></li>
							{% elif e.type.name == "PACKAGING" %}
								{% for arch, breq in e.extra.buildrequests.items %}
									<li><a href="{{ breq.builder }}{% url 'builds-dir' breq.buildlog %}" title="Build Log">{{ arch }}</a></li>
								{% endfor %}
							{% elif e.type.name == "INSTALLED" or e.type.name == "FAILED" %}
								{% for arch, bres in e.extra.buildresults.items %}
									<li><a href="{% url 'events-dir' bres.buildlog %}" title="Build Log">{{ arch }}({% spaceless %}{% mbd_sbuild_status bres %}{% endspaceless %})</a></li>
								{% endfor %}
							{% endif %}
						</ul>
					</nav>
				</td>
			</tr>
		{% endfor %}
	</tbody>
</table>
