{% extends "isearch/base.html" %}
{% import "isearch/include/macros.html" as macros %}

{% block title %}Список индексаций{% endblock %}

{% block sources_active %}active{% endblock %}

{% block container %}
    <h2>Индексации {% if name %}{{ name }} ({{ index or "default" }}) {% else %} - все источники{% endif %} {% if organization %}({{ organization.label }}){% endif %}</h2>
    {% if name %}
    <p><a href="{{ url('isearch-sources-revision-list', name, index or 'default' ) }}?organization_id={{organization.id}}">Список ревизий {% if organization %}{{ organization.label }}{% endif %}</a></p>
    <p>{% call macros.new_indexation(name, index, backend, defaults, suffixes, organization.label) %} Запустить новую индексацию {% endcall %}</p>
    {% endif %}
    <p>{% call macros.fail_indexations(name, index) %} Зафейлить зависшие индексации {% endcall %}</p>
    <table class="table table-bordered table-hover overflowed">
        <thead>
            <th>id</th>
            {% if not name %}
            <th>Источник</th>
            <th>Индекс</th>
            {% endif %}
            {% if not organization %}
            <th>Орг-ция</th>
            {% endif %}
            <th>Статус</th>
            <th>Начало</th>
            <th>Прод-ость</th>
            <th>Док-ов</th>
            <th>Ревизия</th>
            <th>Сервис</th>
            <th width="25%">Комментарий</th>
        </thead>
        {% for log in logs %}
        <tr id="{{ log.id }}">
            <td>{{ log.id }}</td>
            {% if not name %}
            <td><span class="label label-info">{{ log.search }}</span></td>
            <td><a href="{{ url('isearch-sources-indexation-list', log.search, log.index or 'default' ) }}?organization_id={{ organization.id }}">{{ log.index or "(default)" }}</a></td>
            {% endif %}
            {% if not organization %}
            <td>{{ macros.admin_org_link(log.revision.organization) }}</td>
            {% endif %}
            <td>
                {% call macros.render_status(log, link_type="indexation", check_swarm=True) %}{{ log.status }}{% endcall %}
                {% if log.status not in ('fail', 'done') %}
                    {% call macros.stop_indexation(log) %} {% endcall %}
                {% else %}
                    {% call macros.repeat_indexation(log) %} {% endcall %}
                {% endif %}
            </td>
            <td>{{ log.start_time }}</td>
            <td><span title="Закончилась: {{ log.end_time or 'нет' }}">{{ human_delta((log.end_time or now()) - log.start_time)}}</span></td>
            <td>
                {{ intformat(log.documents_count) or 0 }}
                {% if log.expected_documents_count is not none %}
                    / {{ intformat(log.expected_documents_count) or 0 }}
                {% endif %}
            </td>
            <td>{{ macros.render_revision(log.revision) }}</td>
            <td>{{ log.revision.service if log.revision else "(нет)"}}</td>
            <td class="big">{{ log.comment|truncate(100) or ""}}</td>
        </tr>
        {% endfor %}
    </table>
    {% with objects=logs %}
        {% include 'isearch/pager.html' %}
    {% endwith %}
{% endblock %}
