{% extends request.is_ajax|yesno:"base_ajax_nomodal.html,base_rigs.html" %}

{% load static %}
{% load humanize %}
{% load paginator from filters %}
{% load to_class_name from filters %}
{% load cache %}

{% block content %}
{% cache None feed_data request.user %}
<div class="list-group-item">
    <div class="media">
    {% for version in object_list %}
            {% if not version.withPrevious %}
                {% if not forloop.first %}
                    </div> {#/.media-body#}
                </div> {#/.media#}
                </div>
                <div class="list-group-item">
                <div class="media">
                {% endif %}
                    <div class="align-self-start mr-3">
                    {% if version.revision.user %}
                        <a href="{% url 'profile_detail' pk=version.revision.user.pk %}" class="modal-href">
                        <img class="media-object rounded" src="{{ version.revision.user.profile_picture}}" />
                    {% else %}
                        <img class="media-object rounded" src="{% static 'imgs/pyrigs-avatar.png' %}" />
                    {% endif %}
                    </div>
                    <div class="media-body">
                    <h5>
                        {{ version.revision.user.name|default:'System' }}
                        {% if version.revision.user %}</a>{% endif %}
                        <span class="float-right"><small><span class="fas fa-clock"></span> <span class="time">{{version.revision.date_created|date:"c"}}</span> ({{version.revision.date_created}})</small></span>
                    </h5>
            {% endif %}
                    <p>
                    {% if version.changes.old == None %}
                        Created
                    {% else %}
                        Changed {% include 'partials/version_changes.html' %} in
                    {% endif %}
                    {% include 'partials/object_button.html' with object=version.changes.new %}
                    </p>
    {% endfor %}
    </div>
    </div>
</div>
{% endcache %}
{% endblock %}

{% block js %}
<script>
$(document).ready(function() {
    const times = document.getElementsByClassName("time");
    var i;
    for(i = 0; i < times.length; i++) {
        times[i].innerHTML = moment(times[i].innerHTML).fromNow();
    }
});
</script>
{% endblock %}
