{% extends "layout.html" %}

{% from "macros/filter_form.html" import sidefilter, paginate %}

{% set pager = paginate(paginator) %}

{% macro url_to_href(url) %} href="{{ url }}"{% endmacro %}

{% macro stream_content() %}
  {{ pager }}
  <table class="items">
    <thead>
      <th></th>
      <th></th>
      <th>Тип</th>
      {% if not item is defined %}
        <th>Объект</th>
      {% endif %}
      <th>Автор</th>
      <th>Дата</th>
    </thead>
    <tbody>
    {% if not paginator.items %}
      <td colspan="5">История пуста</td>
    {% endif %}
    {%- for entry in paginator.items %}
      {% set obj=entry.obj %}
      {% set lang_kw = {'lang': entry.lang } if entry.lang else {} %}
      <tr class="item {{ loop.cycle('odd', 'even') }} edit-log-{{obj.type}}">
          {% if entry.item %}
              {%- set url = entry.stream.url_for(env, 'edit_log.entry', item=obj.object_id, log_id=obj.id, **lang_kw) -%}
              {% set href = url_to_href(url) %}
          {% else %}
              {% set href = '' %}
          {% endif %}

          <td class="field_id"><a {{ href }}>{{ obj.id }}</a></td>
          <td>
            {% if entry.lang %}<span class="lang-{{ entry.lang }}"></span>{% endif -%}
          </td>
          <td><a {{ href }}>{{ entry.type }}</a></td>
          {% if not item is defined %}
              <td><a {{ href }}>{{ entry.item_title }}</a></td>
          {% endif %}
          <td><a {{ href }}>
            {%- for user in obj.users %}
              {{- user.name or user.login }}
            {% endfor -%}
          </a></td>
          <td><a {{ href }}>
              {{ obj.update_time.strftime("%d.%m.%Y %H:%M") }}
          </a></td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
  {{ pager }}
{% endmacro %}

{% block content %}
  {% if no_layout %}
      {{ stream_content() }}
  {% else %}
    <div class="content itemlist">
      <div class="header">
        <h1 class="stream_title nowrap">{{ title }}</h1>
        {% if item is defined %}
          <a style="font-size: 10px;" href="{{ stream.url_for(env, 'item', item=item.id) }}">{{ item }}</a>
        {% endif %}
      </div>
      <div>
        <div class="stream">
          <div class="line"></div>
          {{ sidefilter(filter_form, current_url) }}
  
          <div class="stream-items with-sidefilter">
            {{ stream_content() }}
          </div>
        </div>
      <div>
    </div>
  {% endif %}
{% endblock %}
