{% extends "mini_buildd/base.html" %}
{% block title %}{% block titledup %}{{ view.mbd_title|default:route|title }} {% if path %}: /{{ path }}{% endif %}{% endblock %}{% endblock %}
{% block tooltip %}{{ view.mbd_tooltip }}{% endblock %}

{% block content %}
	<table id="mbd-events-table" style="width: 100%;">
		{% mbd_datatable "mbd-events-table" order='[0, "desc"]' columns='[{"searchable": false}, 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"><span class="mbd-localize-date">{{ e.timestamp|date:"r" }}</span></a>
						<a class="mbd-icon" href="{% url 'events' e.extra.key %}" title="Show related events"><img class="mbd-icon" src="{% static 'icons/structure.svg' %}" alt="related events"></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 #}
						{% if e.type in e.PACKAGING %}
							{% mbd_api "show" name=e.source value_source=e.source value_codenames=e.distribution|mbd_codename hide_options=True %}
						{% else %}
							<span class="mbd-table-source-text">{{ e.source }}</span>
						{% endif %}
					</td>
					<td data-search="{{ e.version }}">
						{% if e.extra.changes %}
							<a class="mbd-table-version" href="{% url 'events-dir' e.extra.changes %}" title="Package's changes file">{{ e.version }}</a>
						{% else %}
							<span class="mbd-table-version">{{ e.version }}</span>
						{% endif %}
					</td>
					<td>
						<nav>
							<ul>
								{% if e.strerror %}
									<li><code class="mbd-error">{{ e.strerror }}</code></li>
								{% endif %}
								{% if e.type in e.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 class="mbd-icon" 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 %}
							</ul>
						</nav>
					</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>
{% endblock %}
