{% extends "sentry/bases/admin.html" %}

{% load i18n %}
{% load sentry_helpers %}
{% load sentry_admin_helpers %}

{% block title %}{% trans "Manage Projects" %} | {{ block.super }}{% endblock %}

{% block admin-nav-projects %} class="active"{% endblock %}

{% block main %}
    {% paginator project_list from request as project_list per_page 50 %}

    <form class="pull-right" method="GET" action="">
        <input class="form-control" type="text" name="pquery" value="{% if project_query %}{{ project_query }}{% endif %}" placeholder="search by project name" style="width: 240px; margin-top: -4px;">
    </form>

    <h3 class="no-border">{% trans "Projects" %}</h3>

    {% if sort == "events" %}
        <p class="alert alert-info">{% trans "You are viewing projects sorted by the number of events created in the last 24 hours. Projects that have not sent any data are not shown in this view." %}</p>
    {% endif %}

    {% querystring from request without sort as sort_querystring %}

    {% if project_list.paginator.objects %}
        <table class="table" style="margin-bottom: 20px">
            <colgroup>
                <col>
                <col style="width:150px;">
                <col style="width:150px;">
                <col style="width:150px;">
            </colgroup>
            <thead>
                <tr>
                    <th><a href="?{{ sort_querystring }}&amp;sort=name">{% trans "Project" %}</a></th>
                    <th style="text-align:right;">{% trans "Events (24h)" %}</th>
                    <th style="text-align:right;"><a href="?{{ sort_querystring }}&amp;sort=date">{% trans "Date Added" %}</a></th>
                </tr>
            </thead>
            <tbody>
                {% for project, avg_events in project_list.paginator.objects|with_event_counts %}
                    <tr>
                        <td>
                            {% if project.team %}
                                <a href="{% url 'sentry-manage-project' project.organization.slug project.slug %}"><strong>{{ project.organization.slug }}/{{ project.slug }}</strong></a>
                                <a href="{% url 'sentry-stream' project.organization.slug project.slug %}">[stream]</a><br/>
                            {% else %}
                                <strong>{{ project.slug }}</strong>
                            {% endif %}
                        </td>
                        <td style="text-align:right; vertical-align:middle;">
                            {{ avg_events|small_count }}
                        </td>
                        <td style="text-align:right; vertical-align:middle;">
                            {{ project.date_added|date }}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>

    {% else %}
        <p class="alert alert-notice">{% trans "There are no active projects in Sentry." %}</p>
    {% endif %}

    <div class="btn-toolbar">
        <div class="btn-group pull-right">
            <a class="btn btn-lg prev{% if not project_list.paginator.has_previous %} disabled{% else %}" href="?{{ project_list.query_string|escape }}&amp;p={{ project_list.paginator.previous_page }}{% endif %}"><span class="icon-arrow-left"></span></a>
            <a class="btn btn-lg next{% if not project_list.paginator.has_next %} disabled{% else %}" href="?{{ project_list.query_string|escape }}&amp;p={{ project_list.paginator.next_page }}{% endif %}"><span class="icon-arrow-right"></span></a>
        </div>
    </div>
{% endblock %}
