{% extends "admin/base_site.html" %}
{% load i18n static jazzmin %}

{% block bodyclass %}{{ block.super }} dashboard{% endblock %}

{% block content_title %} {% trans 'dashboard' %} {% endblock %}

{% block breadcrumbs %}
    <ol class="breadcrumb float-sm-right">
        <li class="breadcrumb-item"><a href="{% url 'admin:index' %}"><i class="fa fa-tachometer-alt"></i> {% trans 'Home' %}</a></li>
        <li class="breadcrumb-item">{% trans 'Dashboard' %}</li>
    </ol>
{% endblock %}


{% block content %}
    {% get_side_menu as dashboard_list %}
    {% if dashboard_list %}
        {% widthratio dashboard_list|length 2 1 as middle %}
    {% endif %}

    <div class="col-md-9 col-sm-12">
        <div class="row">
            <div class="col-md-6 col-sm-12">
                {% for app in dashboard_list %}
                    <div class="card card-primary card-outline">
                        <div class="card-header">
                            <h5 class="m-0">{{ app.name }}</h5>
                        </div>
                        <div class="card-body">
                            <table class="table table-sm">
                                <tbody>
                                {% for model in app.models %}
                                    <tr>
                                        <td>
                                            {% if model.admin_url %}<a href="{{ model.admin_url }}">{{ model.name }}</a>{% else %}{{ model.name }}{% endif %}
                                        </td>
                                        <td>
                                            <div class="btn-group float-right">
                                                {% if model.add_url %}
                                                    <a href="{{ model.add_url }}" class="btn btn-sm btn-success btn-flat addlink">{% trans 'Add' %}</a>
                                                {% endif %}
                                                {% if model.admin_url %}
                                                    {% if model.view_only %}
                                                        <a href="{{ model.admin_url }}" class="btn btn-sm btn-outline-info btn-flat viewlink">{% trans 'View' %}</a>
                                                    {% else %}
                                                        <a href="{{ model.admin_url }}" class="btn btn-sm btn-outline-info btn-flat changelink">{% if model.custom %}{% trans 'Go' %}{% else %}{% trans 'Change' %}{% endif %}</a>
                                                    {% endif %}
                                                {% endif %}
                                            </div>
                                        </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>

                    {% if forloop.counter == middle|add:"0" %}
                    </div>
                    <div class="col-md-6 col-sm-12">
                    {% endif %}

                {% endfor %}
                </div>
        </div>

    </div>
    <div class="col-md-3 col-sm-12">
        <div id="content-related">
            <div class="module" id="recent-actions-module">
                <h3>{% trans 'Recent actions' %}</h3>
                {% load log %}
                {% get_admin_log 6 as admin_log for_user user %}
                {% if not admin_log %}
                    <p>{% trans 'None available' %}</p>
                {% else %}
                    <div class="timeline">
                        {% for entry in admin_log %}
                            <div>
                                {% if entry.is_change %}
                                    <i class="fas fa-edit bg-green"></i>
                                {% elif entry.is_deletion %}
                                    <i class="fas fa-trash bg-red"></i>
                                {% elif entry.is_addition %}
                                    <i class="fas fa-plus bg-blue"></i>
                                {% endif %}
                                <div class="timeline-item">
                                    <span class="time"><i class="fas fa-clock"></i> {{ entry.action_time|timesince }} Ago</span>
                                    <h3 class="timeline-header no-border">
                                        {% if entry.is_deletion or not entry.get_admin_url %}
                                            {{ entry.object_repr }}
                                        {% else %}
                                            <a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
                                        {% endif %}
                                        {% if entry.model %}
                                            <span class="mini quiet">{% filter capfirst %}
                                                {{ entry.model }}{% endfilter %}
                                            </span>
                                        {% else %}
                                            <span class="mini quiet">{% trans 'Unknown content' %}</span>
                                        {% endif %}
                                    </h3>
                                    <div class="timeline-body">
                                        {{ entry }}
                                    </div>
                                </div>
                            </div>
                        {% endfor %}
                        <div>
                            <i class="fa fa-clock bg-gray"></i>
                        </div>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>

{% endblock %}
