{% extends "base.html" %}
{% load package_extras %}

{% block title %}Arch Linux - Package Search{% endblock %}
{% block navbarclass %}anb-packages{% endblock %}

{% block head %}
{% if is_paginated and page_obj.number > 1 %}<meta name="robots" content="noindex, nofollow"/>{% endif %}
<link rel="alternate" type="application/rss+xml" title="Arch Linux Package Updates" href="/feeds/packages/" />
{% endblock %}

{% block content %}
<div id="pkglist-search" class="box filter-criteria">
    <h2>Package Search</h2>

    <form id="pkg-search" method="get" action="/packages/">
        <p>{{ search_form.sort }}</p>
        {{ search_form.non_field_errors }}
        <fieldset>
            <legend>Enter search criteria</legend>
            <div>{{ search_form.arch.errors }}
                <label for="id_arch" title="Limit results a specific CPU architecture">
                    Arch</label>{{ search_form.arch }}</div>
            <div>{{ search_form.repo.errors }}
                <label for="id_repo" title="Limit results to a specific repository">
                    Repository</label>{{ search_form.repo }}</div>
            <div>{{ search_form.q.errors }}
                <label for="id_q" title="Enter keywords as desired (provides are also supported e.g. 'java-environment=7')">
                    Keywords</label>{{ search_form.q }}</div>
            <div>{{ search_form.maintainer.errors }}
                <label for="id_maintainer" title="Limit results to a specific maintainer">
                    Maintainer</label>{{ search_form.maintainer}}</div>
            <div>{{ search_form.flagged.errors }}
                <label for="id_flagged" title="Limit results based on out-of-date status">
                    Flagged</label>{{ search_form.flagged }}</div>
            <div><label>&nbsp;</label><input title="Search for packages using this criteria"
                type="submit" value="Search" /></div>
        </fieldset>
    </form>
</div>

{% if not is_paginated or page_obj.number == 1 %}{% with search_form.exact_matches as exact_matches %}{% if exact_matches %}
<div id="exact-matches" class="box">
    <div class="pkglist-stats">
        <p>{{ exact_matches|length }} exact match{{ exact_matches|pluralize:"es" }} found.</p>
    </div>
    <table class="results">
        <thead>
            <tr>
                <th>Arch</th>
                <th>Repo</th>
                <th>Name</th>
                <th>Version</th>
                <th>Description</th>
                <th>Last Updated</th>
                <th>Flag Date</th>
            </tr>
        </thead>
        <tbody>
            {% for pkg in exact_matches %}
            <tr>
                <td>{{ pkg.arch.name }}</td>
                <td>{{ pkg.repo.name|capfirst }}</td>
                <td>{% pkg_details_link pkg %}</td>
                {% if pkg.flag_date %}
                <td><span class="flagged" title="Flagged out-of-date">{{ pkg.full_version }}</span></td>
                {% else %}
                <td>{{ pkg.full_version }}</td>
                {% endif %}
                <td class="wrap">{{ pkg.pkgdesc }}</td>
                <td>{{ pkg.last_update|date:"Y-m-d" }}</td>
                <td>{{ pkg.flag_date|date:"Y-m-d" }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endif %}{% endwith %}{% endif %}

<div id="pkglist-results" class="box">
    {% include "packages/search_paginator.html" %}
    <form id="pkglist-results-form" method="post" action="/packages/update/">{% csrf_token %}
        <table class="results">
            <thead>
                <tr>
                    {% if perms.main.change_package %}
                    <th>&nbsp;</th>
                    {% endif %}
                    <th><a href="/packages/?{% buildsortqs "arch" %}"
                            title="Sort packages by architecture">Arch</a></th>
                    <th><a href="/packages/?{% buildsortqs "repo" %}"
                            title="Sort packages by repository">Repo</a></th>
                    <th><a href="/packages/?{% buildsortqs "pkgname" %}"
                            title="Sort packages by package name">Name</a></th>
                    <th>Version</th>
                    <th>Description</th>
                    <th><a href="/packages/?{% buildsortqs "-last_update" %}"
                            title="Sort packages by last update">Last Updated</a></th>
                    <th><a href="/packages/?{% buildsortqs "-flag_date" %}"
                            title="Sort packages by when marked-out of-date">Flag Date</a></th>
                </tr>
            </thead>
            <tbody>
                {% for pkg in package_list %}
                <tr>
                    {% if perms.main.change_package %}
                    <td><input type="checkbox" name="pkgid" value="{{ pkg.id }}" /></td>
                    {% endif %}
                    <td>{{ pkg.arch.name }}</td>
                    <td>{{ pkg.repo.name|capfirst }}</td>
                    <td>{% pkg_details_link pkg %}</td>
                    {% if pkg.flag_date %}
                    <td><span class="flagged" title="Flagged out-of-date">{{ pkg.full_version }}</span></td>
                    {% else %}
                    <td>{{ pkg.full_version }}</td>
                    {% endif %}
                    <td class="wrap">{{ pkg.pkgdesc }}</td>
                    <td>{{ pkg.last_update|date:"Y-m-d" }}</td>
                    <td>{{ pkg.flag_date|date:"Y-m-d" }}</td>
                </tr>
                {% empty %}
                <tr class="empty"><td colspan="{% if perms.main.change_package %}8{% else %}7{% endif %}"><em>No matching packages found</em></td></tr>
                {% endfor %}
            </tbody>
        </table>
        {% include "packages/search_paginator.html" %}

        {% if perms.main.change_package %}
        <p><input title="Adopt selected packages" type="submit" id="adopt-btn"
        name="adopt" value="Adopt Packages" />
        <input title="Orphan selected packages" type="submit" id="disown-btn"
        name="disown" value="Disown Packages" /></p>
        {% endif %}
    </form>
</div>

<div id="pkglist-about" class="box">
    <p>Can't find what you are looking for? Try searching again
    using different criteria, or try
    {% if search_form.q.data %}
    <a href="https://aur.archlinux.org/packages?K={{ search_form.q.data|urlencode }}">searching the AUR</a>
    {% else %}searching the <a href="https://aur.archlinux.org/">AUR</a>{% endif %}
    to see if the package can be found there.</p>

    <p>You are browsing the Arch Linux package database. From here you can find
    detailed information about packages located in the official supported repositories.</p>
</div>
{% endblock %}
