diff --git a/iwm_browser/main.py b/iwm_browser/main.py index 8208ed2..c0fbd96 100644 --- a/iwm_browser/main.py +++ b/iwm_browser/main.py @@ -3,6 +3,9 @@ from fastapi.staticfiles import StaticFiles from fastapi.middleware.gzip import GZipMiddleware from fastapi.responses import HTMLResponse, PlainTextResponse from fastapi import FastAPI, Form, Response +from typing import Optional +import urllib.parse +import starlette import jinja2 import uvicorn import httpx @@ -25,7 +28,11 @@ template_env = jinja2.Environment( error_template = template_env.get_template("error.html") + +template_env.globals["builtins"] = __builtins__ template_env.globals["convert_times"] = utils.convert_times +template_env.globals["json_dumps"] = json.dumps +template_env.globals["urlencode"] = urllib.parse.urlencode template_env.globals["combineCSS"] = utils.combineCSS template_env.globals["isSelected"] = utils.isSelected template_env.globals["generate_thumbnail_url"] = utils.generate_thumbnail_url @@ -68,6 +75,7 @@ async def root(): @app.get("/search", response_class=HTMLResponse) async def search( + request: starlette.requests.Request, q: Union[str, None] = None, p: int = 0, sort: str = "average_rating", @@ -80,7 +88,7 @@ async def search( p = 0 # Passed to the template - QueryValues = {"q": q, "p": p, "sort": sort, "dir": dir, "date": date} + QueryValues = {"q": q, "p": p, "sort": sort, "dir": dir, "date": date, **request.query_params} searchResults = None if q is not None: diff --git a/iwm_browser/static/search/searchResults.css b/iwm_browser/static/search/searchResults.css index bb41a61..10c6b72 100644 --- a/iwm_browser/static/search/searchResults.css +++ b/iwm_browser/static/search/searchResults.css @@ -4,6 +4,17 @@ align-content: start; } +.fullResponse { + font-size: small; + overflow: scroll; + max-width: 20rem; +} + +.fullResponse table, .fullResponse table td { + border: 1px solid gray; + border-collapse: collapse; +} + .searchResultCard { display: grid; margin: 4px; @@ -117,6 +128,18 @@ outline: 1px dashed pink; */ } +@keyframes pulse { + from { + border: 2px solid initial; + color: inherit; + } + + to { + border: 2px solid lime; + color: lime + } +} + .levelCode { margin-top: 0.5em; } @@ -131,6 +154,19 @@ border: 1px solid #505050; } +.levelCode input:focus { + outline: none; + background-color: #00FFFF10; +} + +.levelCode:active, .levelCode input:active { + animation: pulse 0.5s 1 ease-out; +} + +.illegal { + color: red; +} + /* .levelDifficulty { display: flex; diff --git a/iwm_browser/templates/search.html b/iwm_browser/templates/search.html index eded593..0754477 100644 --- a/iwm_browser/templates/search.html +++ b/iwm_browser/templates/search.html @@ -1,7 +1,8 @@ - IWM Browser - {{ QueryValues["q"] if QueryValues["q"] is not none }} + + IWM Browser - {{ QueryValues["q"] if QueryValues["q"] is not none }}{{ QueryValues["type"] }} @@ -18,7 +19,7 @@ // input field to clipboard, and // adds the "copied" css class navigator.clipboard.writeText(obj.value); - alert("Level code copied") + //alert("Level code copied") } @@ -75,13 +76,33 @@
Difficulty: {{ '▲' * map['AverageUserDifficulty']|int }}
by {{ map['CreatorName'] }}
{{ map['NumThumbsUp'] }} 👍 {{ map['NumThumbsDown'] }} 👎
+
Replays visible: {{ "always" if map['ReplayVisibility'] == 2 }}{{ "after clear" if map['ReplayVisibility'] == 0 }}
+
Gems : {{ map['DragonCoins'] }}
{% if map['Description'] != ''%}
{{ map['Description'] }}
{% endif %}
+
+
+ Full server response + + + + {% for value in map %} + + + + {% endfor %} + +
KeyValue
{{value}}{{map[value]}}
+ +
+
-
First Clear: {{ map['FirstClearUsername'] }}
+
First Clear: {{ map['FirstClearUsername'] }}
{% set BestTime = convert_times(map['BestTimePlaytime']) %} -
Best Time: {{ map['BestTimeUsername'] }} [{{ BestTime[0] }}:{{ BestTime[1] }}:{{ BestTime[2] }}]
+ {% set BestFullTime = convert_times(map['BestFullTimePlaytime']) %} +
Best Time: {{ map['BestTimeUsername'] }} [{{ BestTime[0] }}:{{ BestTime[1] }}:{{ BestTime[2] }}]
+ {% if map['BestFullTimeUserID'] != 0 %}
Best 100% Time: {{ map['BestFullTimeUsername'] }} [{{ BestFullTime[0] }}:{{ BestFullTime[1] }}:{{ BestFullTime[2] }}]{{ "(illegal time)" if not map['DragonCoins'] }}
{% endif %}
@@ -90,10 +111,12 @@
- {% set searchPage = QueryValues['p'] %} + {% set searchPage = builtins.int(QueryValues['p']) %}

Page {{ searchPage+1 }}

- {% if not searchPage <= 0 %}Prev{% endif %} - {% if not entryNumber < entryLimit %}Next{% endif %} + {##} + {% if not searchPage <= 0 %}Prev{% endif %} + {% if not entryNumber < entryLimit %}Next{% endif %} + {#{% if not entryNumber < entryLimit %}Next{% endif %}#}
{% endif %}