{% load i18n %}
{% load hro %}
{% load arrowfilter %}
<div id="activity-timeline" class="timeline">

{% for a in activities %}
<div class="activity{% if a.pk == active.pk %} activity-active{%endif%}"
  data-activity-id="{{ a.pk }}" data-activity-code="{{ a.activity_code }}" data-timestamp="{{ a.started|date:"U" }}">
  <span class="timeline-icon{% if a.has_failed %} timeline-icon-failed{% endif %}">
  <i class="fa {% if not a.finished %}fa-refresh fa-spin {% else %}fa-{{a.icon}}{% endif %}"></i>
</span>
{% spaceless %}
<strong{% if a.result %} title="{{ a.result|get_text:user }}"{% endif %}>
  <a href="{{ a.get_absolute_url }}">
    {% if a.times > 1 %}({{ a.times }}x){% endif %}
    {{ a.readable_name|get_text:user|capfirst }}</a>

{% if a.has_percent %}
  - {{ a.percentage }}%
{% endif %}
</strong>
{% endspaceless %}{% if a.times < 2 %}&nbsp;<span title="{{ a.started }}">{{ a.started|arrowfilter:LANGUAGE_CODE }}</span>{% endif %}{% if a.user %},
  <a class="no-style-link" href="{% url "dashboard.views.profile" username=a.user.username %}">
    {% include "dashboard/_display-name.html" with user=a.user show_org=True show_pic=True %}
  </a>
{% endif %}
{% if a.is_abortable_for_user %}
<form action="{{ a.instance.get_absolute_url }}" method="POST" class="pull-right">
  {% csrf_token %}
  <input type="hidden" name="abort_operation"/>
  <input type="hidden" name="activity" value="{{ a.pk }}"/>
  <button class="btn btn-danger btn-xs"><i class="fa fa-bolt"></i> {% trans "Abort" %}</button>
</form>
{% endif %}
  {% if a.children.count > 0 %}
    <div class="sub-timeline">
      {% for s in a.children.all %}
      <div data-activity-id="{{ s.pk }}" data-activity-code="{{ s.activity_code }}"
        class="sub-activity{% if s.has_failed %} sub-activity-failed{% endif %}{% if s.pk == active.pk %} sub-activity-active{% endif %}">
        <span{% if s.result %} title="{{ s.result|get_text:user }}"{% endif %}>
          <a href="{{ s.get_absolute_url }}">
              {{ s.readable_name|get_text:user|capfirst }}</a></span> &ndash;
        {% if s.finished %}
          <span title="{{ s.finished }}">
            {{ s.finished|arrowfilter:LANGUAGE_CODE }}
          </span>
        {% else %}
          <i class="fa fa-refresh fa-spin"></i>
        {% endif %}
        {% if s.has_failed %}
          <div class="label label-danger">{% trans "failed" %}</div>
        {% endif %}
        </div>
      {% endfor %}
    </div>
  {% endif %}
</div>
{% endfor %}
</div>

{% if show_show_all %}
<div id="show-all-activities-container">
  <a id="show-all-activities" href="#">
    {% if activities|length > 10 %}
      {% trans "Show less activities" %} <i class="fa fa-angle-double-up"></i>
    {% else %}
      {% trans "Show all activities" %} <i class="fa fa-angle-double-down"></i>
    {% endif %}
  </a>
</div>
{% endif %}
