{% extends "one_column_body.html" %}
{% from "macros.html" import paginator, timeago %}
{% from "analytics/macros.html" import format_query_string, sort_icon_class, full_date, analytics_user_activity_link, analytics_group_activity_link %}
{% block title %}{% filter trim %}{% trans %}Analytics / Home{% endtrans %}{% endfilter %}{% endblock %}
{% block forestyle %}
  <style>
    table {
      border-collapse: collapse;
      margin-bottom: 1rem;
    }
    th, td {
      padding: 0.5rem;
    }
    th {
      background-color: #f2f2f2;
    }
    tbody tr:nth-child(even) {
      background-color: #f2f2f2;
    }
    tbody td:not(:first-child) {
      text-align: center;
    }
    td {
        text-align: left !important;
    }
    td.org-name {
        text-align: center !important;
    }
    .title-row {
      align-items: center;
    }
    .analytics-summary {
      margin-bottom: 2rem;
    }
  </style>
{% endblock %}
{% block layout_class %}{{ super() }} analytics-page{% endblock %}
{% block forum_header %}{% endblock %}
{% block content %}
<div class="title-row">
  <h1>
    {% for breadcrumb in breadcrumbs %}
      {% if loop.last %}
        {{ breadcrumb.name }}
      {% else %}
        <a href="{{ breadcrumb.url }}">{{ breadcrumb.name }}</a> /
      {% endif %}
    {% endfor %}
  </h1>
  {% include "analytics/date_selector.html" %}
</div>
<table>
  {% set show_org=settings.GROUPS_ENABLED %} {#and not users_url_segment.startswith('group:') and not users_url_segment.startswith('user:')) #}
  <thead>
    <tr>
      <th>User</th>
      {% if show_org %}<th>Organization</th>{% endif %}
      <th>Event</th>
      <th>Date</th>
    </tr>
  </thead>
  <tbody>
    {% for content_event in events %}
      <tr>
        <td>
          {{ analytics_user_activity_link(content_event.session.user, dates=dates) }}
        </td>
        {% if show_org %}
          <td class="org-name">{{ analytics_group_activity_link(content_event.session.user, dates=dates) }}</td>
        {% endif %}
        <td>
            <em>{{ content_event.get_event_type_display() }}</em>&nbsp;
            {% if content_event.content_type == post_content_type %}
                {% set post = content_event.content_object %}
                <a href={{ post.get_absolute_url() }}>
                  {% if post.post_type == 'question' %}
                    {{ post.thread.title|truncate(30) }}
                  {% else %}
                    {{ post.text|truncate(30) }}
                  {% endif %}
                </a>
            {% endif %}
        </td>
        <td>{{ full_date(content_event.timestamp) }}</td>
      </tr>
    {% endfor %}
    {% if paginator_context.is_paginated %}
      <tr class="paginator-row">
        <td colspan="3">
        {{ paginator(paginator_context) }}
        </td>
      </tr>
    {% endif %}
  </tbody>
</table>
{% endblock %}
