{% extends "master.html" %}

{% block title %}Projects · Anitya{% endblock %}

{% block body %}

<div class="page-header">
  <h1>Projects
      {% if status == 'updated' %}
      <small>that updated successfully at the last run</small>
      {% elif status == 'failed' %}
      <small>that failed to update at the last run</small>
      {% elif status == 'archived' %}
      <small>that are archived</small>
      {% elif status == 'never_updated' %}
      <small>that have never updated</small>
      {% endif %}
  </h1>
</div>

<div class="row show-grid">
  <div class="col-sm-4">
    {% if total_page > 1 %}
    <ul class="pagination pagination-sm">
        <li>
            {% if page > 1%}
              <a href="{{
                url_for('anitya_ui.projects_updated',
                        status=status, name=name, log=log, page=page-1) }}">
                «
              </a>
            {% else %}
              <a> « </a>
            {% endif %}
        </li>
        <li>
            <a> {{ page }} / {{ total_page }} </a>
        </li>
        <li>
            {% if page < total_page %}
              <a href="{{
                url_for('anitya_ui.projects_updated',
                        status=status, name=name, log=log, page=page+1) }}">
                »
              </a>
            {% else %}
              <a> » </a>
            {% endif %}
        </li>
    </ul>
    {% endif %}
  </div>

  <div class="col-sm-8">
    <form action="{{url_for('anitya_ui.projects_updated', status=status) }}"
          role="form" class="form-inline">
      <div class="form-group">
        <input type="text" name="name" placeholder="Project name" class="form-control input-sm"/>
        {% if status != 'archived' %}
        <input type="text" name="log" placeholder="Project log" class="form-control input-sm"/>
        {% endif %}
        <button type="submit" class="btn btn-sm btn-default">
          Search
        </button>
      </div>
    </form>
  </div>
</div>

<div class="row">
  <p>{{ projects_count }} projects found</p>
  <div class="list-group">
    {% if projects %}
    <span class="list-group-item">
      <h4 class="list-group-item-heading">
        <table class="table table-condensed">
            <th>Project name</th>
            {% if status != 'archived' %}
            <th>Log content</th>
            {% endif %}
            {% if status == 'failed' %}
            <th>Checks failed</th>
            {% endif %}
            {% if status == 'updated' or status == 'archived' %}
            <th>Last update</th>
            {% endif %}
            {% if status == 'never_updated' %}
            <th>Created on</th>
            {% endif %}
        {% for project in projects %}
            <tr>
              <td>
                <a href="{{ url_for('anitya_ui.project', project_id=project.id) }}">
                {{project.name}}
                </a>
              </td>
              {% if status != 'archived' %}
              <td>
                {{ project.logs }}
              </td>
              {% endif %}
              {% if status == 'failed' %}
              <td>{{ project.error_counter }}</td>
              {% endif %}
              {% if status == 'updated' or status == 'archived' %}
              <td>{{ project.last_check.strftime('%Y-%m-%d %H:%M:%S') }}</td>
              {% endif %}
              {% if status == 'never_updated' %}
              <td>{{ project.created_on.strftime('%Y-%m-%d %H:%M:%S') }}</td>
              {% endif %}
            </tr>
          {% endfor %}
          </table>
      </h4>
      <div class="clearfix"></div>
    </span>
  {% else %}
  <blockquote>
      No project found in this category.
  </blockquote>
  {% endif %}
  </div>
</div>

<div class="row show-grid">
  <div class="col-sm-4">
    {% if total_page > 1 %}
    <ul class="pagination pagination-sm">
        <li>
            {% if page > 1%}
              <a href="{{
                url_for('anitya_ui.projects_updated',
                        status=status, name=name, log=log, page=page-1) }}">
                «
              </a>
            {% else %}
              <a> « </a>
            {% endif %}
        </li>
        <li>
            <a> {{ page }} / {{ total_page }} </a>
        </li>
        <li>
            {% if page < total_page %}
              <a href="{{
                url_for('anitya_ui.projects_updated',
                        status=status, name=name, log=log, page=page+1) }}">
                »
              </a>
            {% else %}
              <a> » </a>
            {% endif %}
        </li>
    </ul>
    {% endif %}
  </div>
</div>
{% endblock %}
