From 5f4a08f3ad0d8d4065e2ed88fb1a922d9552468d Mon Sep 17 00:00:00 2001 From: magmaus3 Date: Sun, 9 Apr 2023 18:06:58 +0200 Subject: [PATCH] Some small updates - Show 100% clears (also shows if a 100% clear is impossible (no gems in the level)) - Show the type in the title if `type` param is set (it might conflict with search query) - Pass the same search query to the prev/next page - Shows some 0.822 info (if gems are in the level and replay visibility status) - Add a (hidden by default) table with the server response - (incomplete) pulse when copying instead of using an alert --- iwm_browser/main.py | 10 +++++- iwm_browser/static/search/searchResults.css | 36 ++++++++++++++++++++ iwm_browser/templates/search.html | 37 +++++++++++++++++---- 3 files changed, 75 insertions(+), 8 deletions(-) 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'] }}
+ {% 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 %}