{% mbd_hash "mbd-events-"|add:id as table_id %}
<table id="{{ table_id }}" style="width: 100%;">
	{% mbd_datatable table_id order='[0, "desc"]' columns='[null, null, null, null, null, {"searchable": false, "orderable": false}]' %}
	<thead>
		<tr>
			<th>Event</th>
			<th>Type</th>
			<th>Distribution</th>
			<th>Source</th>
			<th>Version</th>
			<th>Menu</th>
		</tr>
	</thead>
	<tbody>
		{% for e in events %}
			{% mbd_get e.ongoing as ongoing %}   <!-- call maybe expensive function only once -->
			<tr class="{{ ongoing|yesno:'mbd-ongoing,' }}" title="{{ e.extra.key }}">
				<td data-order="{{ e.timestamp|date:"U:u" }}">
					<a href="{% url 'events-dir' e.extra.bkey|add:"/"|add:e.json_file_name %}" title="View json file"><small class="mbd-localize-date">{{ e.timestamp|date:"r" }}</small></a>
				</td>
				<td class="{% mbd_cssmap 'events' e.type.name %}" title="{{ e.desc }}">
					<b>{{ e.type.name }}</b>
				</td>
				<td>{{ e.distribution }}</td>
				<td>
					<span class="mbd-hidden">{{ e.source }}</span>  {# Needed to make name searchable via datatable #}
					{% mbd_api "show" 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">{{ e.version }}</a>
					{% else %}
						{{ e.version }}
					{% endif %}
				</td>
				<td>
					<nav>
						<ul>
							{% if e.strerror %}
								<li><code class="mbd-error">{{ e.strerror }}</code></li>
							{% endif %}
							{% if e.type.name == "BUILT" or e.type.name == "BUILDING" %}
								{% if e.type.name == "BUILT" and e.extra.bkey in mbd.daemon.builder.uploader.failed %}
										<li><code class="mbd-warning">Upload to {{ e.extra.upload_to }} failed (will retry)</code></li>
								{% endif %}
								<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>
								<li><a href="{% url 'builds-dir' e.extra.bkey %}">
									<img class="mbd-icon" src="{% static 'icons/places/folder.svg' %}" alt="browse" title="Browse builds dir">
								</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 %}
							{% if e.type.name == "FAILED" or e.type.name == "REJECTED" or e.type.name == "PACKAGING" and not ongoing %}
								<li>{% mbd_api "retry" value_bkey=e.extra.bkey hide_options=True %}</li>
							{% endif %}
							{% if e.type.name == "BUILDING" and ongoing %}
								<li>{% mbd_api "cancel" value_bkey=e.extra.bkey hide_options=True %}</li>
							{% endif %}
							<li><a href="{% url 'events-dir' e.extra.key %}">
								<img class="mbd-icon" src="{% static 'icons/places/folder.svg' %}" alt="browse" title="Browse events dir">
							</a></li>
						</ul>
					</nav>
				</td>
			</tr>
		{% endfor %}
	</tbody>
</table>
