Verified Commit bfd59229 authored by Kevin Morris's avatar Kevin Morris
Browse files

change: display default package search parameter values in its form

The previous behavior was carried over from PHP. It has been requested
that we use the true defaults when rendering the default form, making
search a bit more sensible.

Closes #269



Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 0bfecb98
......@@ -40,7 +40,7 @@ async def packages_get(request: Request, context: Dict[str, Any],
search_by = context["SeB"] = request.query_params.get("SeB", "nd")
# Query sort by.
sort_by = context["SB"] = request.query_params.get("SB", "p")
sort_by = request.query_params.get("SB", None)
# Query sort order.
sort_order = request.query_params.get("SO", None)
......@@ -93,13 +93,6 @@ async def packages_get(request: Request, context: Dict[str, Any],
# Apply user-specified specified sort column and ordering.
search.sort_by(sort_by, sort_order)
# If no SO was given, default the context SO to 'a' (Ascending).
# By default, if no SO is given, the search should sort by 'd'
# (Descending), but display "Ascending" for the Sort order select.
if sort_order is None:
sort_order = "a"
context["SO"] = sort_order
# Insert search results into the context.
results = search.results().with_entities(
models.Package.ID,
......
......@@ -34,6 +34,9 @@
</div>
<div>
<label for="id_sort_by">{{ "Sort by" | tr }}</label>
{% if not SB %}
{% set SB = 'p' %}
{% endif %}
<select name='SB'>
<option value='n' {% if SB == "n" %}selected{% endif %}>{{ "Name" | tr }}</option>
<option value='v' {% if SB == "v" %}selected{% endif %}>{{ "Votes" | tr }}</option>
......@@ -46,6 +49,9 @@
</div>
<div>
<label for="id_order_by">{{ "Sort order" | tr }}</label>
{% if not SO %}
{% set SO = 'd' %}
{% endif %}
<select name='SO'>
<option value='a' {% if SO == "a" %}selected{% endif %}>{{ "Ascending" | tr }}</option>
<option value='d' {% if SO == "d" %}selected{% endif %}>{{ "Descending" | tr }}</option>
......
{% set reverse_order = "d" if SO == "a" else "a" %}
<table {% if table_id %}id="{{ table_id }}"{% endif %} class="results">
<thead>
<tr>
......@@ -5,9 +7,10 @@
<th></th>
{% endif %}
<th>
{% set order = SO %}
{% if SB == "n" %}
{% set order = "d" if order == "a" else "a" %}
{% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'n'), ('SO', order)) | urlencode }}">
{{ "Name" | tr }}
......@@ -15,35 +18,39 @@
</th>
<th>{{ "Version" | tr }}</th>
<th>
{% set order = SO %}
{% if SB == "v" %}
{% set order = "d" if order == "a" else "a" %}
{% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'v'), ('SO', order)) | urlencode }}">
{{ "Votes" | tr }}
</a>
</th>
<th>
{% set order = SO %}
{% if SB == "p" %}
{% set order = "d" if order == "a" else "a" %}
{% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'p'), ('SO', order)) | urlencode }}">{{ "Popularity" | tr }}</a><span title="{{ 'Popularity is calculated as the sum of all votes with each vote being weighted with a factor of %.2f per day since its creation.' | format(0.98) }}" class="hover-help"><sup>?</sup></span>
</th>
{% if request.user.is_authenticated() %}
<th>
{% set order = SO %}
{% if SB == "w" %}
{% set order = "d" if order == "a" else "a" %}
{% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'w'), ('SO', order)) | urlencode }}">
{{ "Voted" | tr }}
</a>
</th>
<th>
{% set order = SO %}
{% if SB == "o" %}
{% set order = "d" if order == "a" else "a" %}
{% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'o'), ('SO', order)) | urlencode }}">
{{ "Notify" | tr }}
......@@ -52,9 +59,10 @@
{% endif %}
<th>{{ "Description" | tr }}</th>
<th>
{% set order = SO %}
{% if SB == "m" %}
{% set order = "d" if order == "a" else "a" %}
{% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'm'), ('SO', order)) | urlencode }}">
{{ "Maintainer" | tr }}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment