{% extends "mini_buildd/base.html" %}
{% block title %}{% block titledup %}{{ route|title }}: /{{ path }}{% endblock %}{% endblock %}
{% block tooltip %}Showing latest {{ view.mbd_events|length }} of {{ view.mbd_events_total }} total events before {{ view.mbd_before|date:"r" }}{% endblock %}
{% block menu %}{% include "mini_buildd/includes/range_menu.html" %}{% endblock %}

{% block content %}
	<table id="mbd-events-table" style="width: 100%;">
		{% mbd_datatable "mbd-events-table" 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 view.mbd_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="Json file"><small class="mbd-localize-date">{{ e.timestamp|date:"r" }}</small></a>
					</td>
					<td class="mbd-event-{{ 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="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="Live 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/builds-dir.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="Live Build Log ({{ breq.builder }})">{{ 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>
											<span class="mbd-error">{{ bres.internal_error }}</span>
										</li>
									{% endfor %}
								{% endif %}
								{% if e.type.name == "FAILED" or e.type.name == "REJECTED" and "source" in e.extra.architecture %}
									<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/events-dir.svg' %}" alt="browse" title="Browse events dir">
								</a></li>
							</ul>
						</nav>
					</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>
{% endblock %}
