{% mbd_hash "mbd-events-"|add:id as table_id %}
<table id="{{ table_id }}" style="width: 100%;">
	{% mbd_datatable table_id order='[0, "desc"], [1, "desc"]' columns='[{"className": "dt-center"}, null, null, null, null, {"searchable": false, "orderable": false}]' %}
	<thead>
		<tr>
			<th title="going">On</th>
			<th>Event</th>
			<th>Distribution</th>
			<th>Source</th>
			<th>Version</th>
			<th>Menu</th>
		</tr>
	</thead>
	<tbody>
		{% for e in events %}
			<tr class="{% if e.ongoing %}mbd-ongoing{% endif %}">
				<td data-order="{{ e.ongoing|yesno:'1,0' }}">{{ e.ongoing|yesno:'yes,no' }}</td>
				<td data-order="{{ e.timestamp|date:"U:u" }}" data-search="{{ e.type.name }}">
					<details>
						<summary>
							<small class="mbd-localize-date" title="{{ e.timestamp|date:"r" }}">{{ e.timestamp|date:"r" }}</small>: <b class="{% mbd_cssmap 'events' e.type.name %}" title="{{ e.desc }}">{{ e.type.name }}</b>
						</summary>
						{% if e.strerror %}
							<code class="mbd-error">{{ e.strerror }}</code>
						{% endif %}

						<ul>
							{% 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 ({{ bres.builder }})">{{ arch }}({% spaceless %}{% mbd_sbuild_status bres %}{% endspaceless %})</a>
										<span class="mbd-error">{{ bres.internal_error }}</span>
									</li>
								{% endfor %}
							{% endif %}
						</ul>
					</details>
				</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 value_codenames=e.distribution|mbd_codename hide_options=True %}
				</td>
				<td data-search="{{ e.version }}">
					{% if e.extra.changes %}
						<a href="{% url 'events-dir' e.extra.changes %}" title="View package's changes file" alt="Changes">{{ e.version }}</a>
					{% else %}
						{{ e.version }}
					{% endif %}
				</td>
				<td>
					<nav>
						<ul>
							<li><a href="{% url 'events-dir' e.extra.bkey|add:"/"|add:e.json_file_name %}"><img class="mbd-icon" src="{% static 'icons/mimetypes/application-json.svg' %}"  title="View json file" alt="Event JSON"></a></li>
							{% 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" and e.ongoing %}
								<li>{% mbd_api_popup "cancel" value_bkey=e.extra.bkey hide_options=True %}</li>
							{% endif %}
						</ul>
					</nav>
				</td>
			</tr>
		{% endfor %}
	</tbody>
</table>
