Search page improvements

This commit is contained in:
magmaus3 2022-11-05 18:54:37 +01:00
parent 2b75aac67c
commit 1e81fe18bb
Signed by: magmaus3
GPG key ID: 966755D3F4A9B251
3 changed files with 27 additions and 14 deletions

View file

@ -23,6 +23,7 @@ template_env = jinja2.Environment(
error_template = template_env.get_template("error.html") error_template = template_env.get_template("error.html")
template_env.globals["convert_times"] = utils.convert_times template_env.globals["convert_times"] = utils.convert_times
template_env.globals["isSelected"] = utils.isSelected
template_env.globals["generate_thumbnail_url"] = utils.generate_thumbnail_url template_env.globals["generate_thumbnail_url"] = utils.generate_thumbnail_url
template_env.globals["__version__"] = __version__ template_env.globals["__version__"] = __version__

View file

@ -1,8 +1,9 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title></title> <title>IWM Browser - {{ QueryValues["q"] }}</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/index.css"> <link rel="stylesheet" href="/static/index.css">
<link rel="stylesheet" href="/static/main.css"> <link rel="stylesheet" href="/static/main.css">
@ -32,26 +33,30 @@
</div> </div>
<details> <details>
<summary>More options</summary> <summary>More options</summary>
{% macro option(name, value, key) -%}
<option value={{ value }} {{ isSelected(value, QueryValues[key]) }}>{{ name }}</option>
{%- endmacro %}
<div class="sortType"> <div class="sortType">
<label for="sort">Sort type</label> <label for="sort">Sort type</label>
<select id="sort" name="sort"> <select id="sort" name="sort">
<option value="average_rating">Rating</option> {{ option("Rating", "average_rating", "sort") }}
<option value="created_at">Upload date</option> {{ option("Upload date", "created_at", "sort") }}
<option value="average_difficulty">Difficulty</option> {{ option("Difficulty", "average_difficulty", "sort") }}
<option value="play_count">Plays</option> {{ option("Plays", "play_count", "sort") }}
</select> </select>
<select id="dir" name="dir"> <select id="dir" name="dir">
<option value="desc">Descending</option> {{ option("Descending", "desc", "dir") }}
<option value="asc">Ascending</option> {{ option("Ascending", "asc", "dir") }}
</select> </select>
</div> </div>
<div class="upload_date"> <div class="upload_date">
<label for="date">Upload date</label> <label for="date">Upload date</label>
<select id="date" name="date"> <select id="date" name="date">
<option value="-1">All time</option> {{ option("All time", -1, "date") }}
<option value="720">Past 30 days</option> {{ option("Past 30 days", 720, "date") }}
<option value="168">Past 7 days</option> {{ option("Past 7 days", 168, "date") }}
<option value="24">Past day</option> {{ option("Past day", 24, "date") }}
{{ option("Past hour", 1, "date") }}
</select> </select>
</div> </div>
</details> </details>
@ -61,15 +66,15 @@
<div class="searchResults"> <div class="searchResults">
{% for map in searchResults %} {% for map in searchResults %}
<div class="searchResultCard"> <div class="searchResultCard">
<div class="thumbnail"><img src="{{ generate_thumbnail_url(map['ID'], THUMB_URL) }}"></div> <div class="thumbnail"><img aria-hidden="true" src="{{ generate_thumbnail_url(map['ID'], THUMB_URL) }}"></div>
<div class="details"> <div class="details">
<div class="basic"> <div class="basic">
<div class="levelTitle"><a href="/level/{{ map['ID'] }}">{{ map['Name'] }}</a></div> <div class="levelTitle"><a href="/level/{{ map['ID'] }}">{{ map['Name'] }}</a></div>
<div class="levelDifficulty"><span>Difficulty: {{ '▲' * map['AverageUserDifficulty']|int }}</span></div> <div class="levelDifficulty"><span aria-label="Difficulty: {{ map['AverageUserDifficulty']|int }}">Difficulty: {{ '▲' * map['AverageUserDifficulty']|int }}</span></div>
<div class="creatorName">by <a href="/user/{{ map['CreatorId'] }}"><b>{{ map['CreatorName'] }}</b></a></div> <div class="creatorName">by <a href="/user/{{ map['CreatorId'] }}"><b>{{ map['CreatorName'] }}</b></a></div>
<div class="levelRating">{{ map['NumThumbsUp'] }} 👍 {{ map['NumThumbsDown'] }} 👎</div> <div class="levelRating">{{ map['NumThumbsUp'] }} 👍 {{ map['NumThumbsDown'] }} 👎</div>
{% if map['Description'] != ''%}<div class="levelDescription">{{ map['Description'] }}</div>{% endif %} {% if map['Description'] != ''%}<div class="levelDescription">{{ map['Description'] }}</div>{% endif %}
<div class="levelCode">Code: <input type="text" onclick="copy(this)" readonly=1 value="{{ map['MapCode'] }}" /></div> <div class="levelCode"><label for="levelCode-input-{{ map['ID'] }}">Code:</label> <input id="levelCode-input-{{ map['ID'] }}" type="text" onclick="copy(this)" readonly=1 value="{{ map['MapCode'] }}" /></div>
</div> </div>
<div class="times"> <div class="times">
<div class="FirstClear">First Clear: <b>{{ map['FirstClearUsername'] }}</b></div> <div class="FirstClear">First Clear: <b>{{ map['FirstClearUsername'] }}</b></div>

View file

@ -27,6 +27,13 @@ def config_value(key: str, default_value=None):
return default_value return default_value
def isSelected(selection, value):
"""Returns 'selected' if values are equal.
Intended for selection boxes"""
print(f"DBG: {selection} {value},")
return 'selected="true"' if selection == value else ''
# Specify default imgproxy instance. # Specify default imgproxy instance.
global_imgproxy_url = None global_imgproxy_url = None
global_imgproxy_params = None global_imgproxy_params = None