From fd37c721176974364f6f484cb86586ba613e8ef9 Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 26 Jun 2020 13:05:45 -0500 Subject: [PATCH] fixed jinja2 whitespace trim, move script tag up, re-add silent row class, table sorting function --- trivia/create_app.py | 4 ++++ trivia/static/script.js | 23 ++++++++++++++++++++++- trivia/static/style.css | 2 ++ trivia/templates/index.html | 3 ++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/trivia/create_app.py b/trivia/create_app.py index d066dde..20aba65 100644 --- a/trivia/create_app.py +++ b/trivia/create_app.py @@ -13,6 +13,10 @@ def create_app(env=None): env = app.config['ENV'] app.config.from_object(configs[env]) + # Fixes poor whitespace rendering in templates + app.jinja_env.trim_blocks = True + app.jinja_env.lstrip_blocks = True + with app.app_context(): # noinspection PyUnresolvedReferences from trivia import routes, api, utils diff --git a/trivia/static/script.js b/trivia/static/script.js index 26c5b41..212fc1e 100644 --- a/trivia/static/script.js +++ b/trivia/static/script.js @@ -14,7 +14,7 @@ let REFRESH_TIMEOUT; function ScrollOnce(autoscroll) { // If autoscroll has been disabled in between timer, this if statement will prevent it from executing. if (AUTOSCROLL) - $(".ui-row:first").appendTo("tbody") + $(".ui-row:first").appendTo(".js-standings") // Restart autoscroll as needed. if (autoscroll && AUTOSCROLL) { @@ -49,6 +49,26 @@ function ToggleAutorefresh() { } else { $(".js-refresh-start").show(); $(".js-refresh-stop").hide(); + + clearTimeout(REFRESH_TIMEOUT); + } +} + +function sortUsingNestedText(parent, childSelector, keySelector) { + var items = parent.children(childSelector).sort(function(a, b) { + var vA = $(keySelector, a).text(); + var vB = $(keySelector, b).text(); + return (vA < vB) ? 1 : (vA > vB) ? -1 : 0; + }); + parent.append(items); +} + +// Sorts all Teams, rearranging them by Rank +function SortTeams(topTeam = 0) { + sortUsingNestedText($(".js-standings"), '.ui-row', 'td.js-total-score') + + while($('.js-standings').firstChild.data('row-index') !== topTeam) { + $(".ui-row:first").appendTo("tbody") } } @@ -60,4 +80,5 @@ $().ready(function () { ToggleAutoscroll() ToggleAutorefresh() + SortTeams(); }) \ No newline at end of file diff --git a/trivia/static/style.css b/trivia/static/style.css index 605fca4..9e266e5 100644 --- a/trivia/static/style.css +++ b/trivia/static/style.css @@ -15,6 +15,8 @@ tr[data-row-index="0"] td { border-top: 0.25em solid #000; } .ui-header { background-color: #b51329; border-bottom: 2px solid #27233a; color: #fff; padding: 0.5em 1em; } /*.ui-content { padding: 0.5em 1em; }*/ .ui-footer { } +.ui-silent-row {color: #7c7c7c +} .center { text-align: center; } .pointer { cursor: pointer; } diff --git a/trivia/templates/index.html b/trivia/templates/index.html index 7e4c18f..7276b72 100644 --- a/trivia/templates/index.html +++ b/trivia/templates/index.html @@ -9,6 +9,7 @@ integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"> +
@@ -52,6 +53,7 @@ {% else %} Team {{ team.id }} {% endif %} + {{ team.scores | sum }} {% for score in team.scores %} {{ score }} {% endfor %} @@ -62,5 +64,4 @@
- \ No newline at end of file