fix team name and rank formatting within table, sort tables during read

This commit is contained in:
Xevion
2020-06-27 16:06:55 -05:00
parent fd37c72117
commit f23b07be82
4 changed files with 24 additions and 19 deletions
+13 -10
View File
@@ -13,7 +13,7 @@ let REFRESH_TIMEOUT;
// Scroll table once. // Scroll table once.
function ScrollOnce(autoscroll) { function ScrollOnce(autoscroll) {
// If autoscroll has been disabled in between timer, this if statement will prevent it from executing. // If autoscroll has been disabled in between timer, this if statement will prevent it from executing.
if (AUTOSCROLL) if (AUTOSCROLL || !autoscroll)
$(".ui-row:first").appendTo(".js-standings") $(".ui-row:first").appendTo(".js-standings")
// Restart autoscroll as needed. // Restart autoscroll as needed.
@@ -55,21 +55,24 @@ function ToggleAutorefresh() {
} }
function sortUsingNestedText(parent, childSelector, keySelector) { function sortUsingNestedText(parent, childSelector, keySelector) {
var items = parent.children(childSelector).sort(function(a, b) { var items = parent.children(childSelector).sort(function (a, b) {
var vA = $(keySelector, a).text(); var vA = parseInt($(keySelector, a).text())
var vB = $(keySelector, b).text(); var vB = parseInt($(keySelector, b).text());
return (vA < vB) ? 1 : (vA > vB) ? -1 : 0; return (vA < vB) ? 1 : (vA > vB) ? -1 : 0;
}); });
parent.append(items); parent.append(items);
} }
// Sorts all Teams, rearranging them by Rank // Sorts all Teams, rearranging them by Rank
function SortTeams(topTeam = 0) { function SortTeams(topTeam = 5) {
// Sort by total score
sortUsingNestedText($(".js-standings"), '.ui-row', 'td.js-total-score') sortUsingNestedText($(".js-standings"), '.ui-row', 'td.js-total-score')
while($('.js-standings').firstChild.data('row-index') !== topTeam) { // Push
$(".ui-row:first").appendTo("tbody") console.log(parseInt($('.js-standings').find('>:first-child').data('row-index')))
} // while ( !== topTeam) {
// $(".ui-row:first").appendTo("tbody")
// }
} }
// Client Initialization // Client Initialization
@@ -78,7 +81,7 @@ $().ready(function () {
$(".js-scroll-row").on("click", ToggleAutoscroll); $(".js-scroll-row").on("click", ToggleAutoscroll);
$(".js-refresh").on("click", ToggleAutorefresh); $(".js-refresh").on("click", ToggleAutorefresh);
ToggleAutoscroll() ToggleAutoscroll();
ToggleAutorefresh() ToggleAutorefresh();
SortTeams(); SortTeams();
}) })
+5 -4
View File
@@ -9,17 +9,16 @@ body { font-family: Calibri, Arial, sans-serif; margin: 0; padding: 0; position:
.score-team-name:before { content: "&nbsp;"; visibility: hidden; } .score-team-name:before { content: "&nbsp;"; visibility: hidden; }
/* Projector View */ /* Projector View */
.ui-content { font-size: 300%; padding: 0.25em 0; }
tr[data-row-index="0"] td { border-top: 0.25em solid #000; }
.ui-content { font-size: 300%; padding: 0.25em 0; }
.ui-header { background-color: #b51329; border-bottom: 2px solid #27233a; color: #fff; padding: 0.5em 1em; } .ui-header { background-color: #b51329; border-bottom: 2px solid #27233a; color: #fff; padding: 0.5em 1em; }
/*.ui-content { padding: 0.5em 1em; }*/ /*.ui-content { padding: 0.5em 1em; }*/
.ui-footer { } .ui-footer { }
.ui-silent-row {color: #7c7c7c .ui-silent-row { color: #7c7c7c }
}
.center { text-align: center; } .center { text-align: center; }
.pointer { cursor: pointer; } .pointer { cursor: pointer; }
.left { text-align: left; }
.right { text-align: right; } .right { text-align: right; }
.rank-pad { padding-left: 0.3em; padding-right: 0.2em;} .rank-pad { padding-left: 0.3em; padding-right: 0.2em;}
.small-no-wrap { white-space: nowrap; width: 1%; } .small-no-wrap { white-space: nowrap; width: 1%; }
@@ -39,3 +38,5 @@ tr[data-row-index="0"] td { border-top: 0.25em solid #000; }
.table-striped > tbody > tr.has-warning:nth-child(odd) { background-color: #faf2cc; border-color: #f8e5be; } .table-striped > tbody > tr.has-warning:nth-child(odd) { background-color: #faf2cc; border-color: #f8e5be; }
.table-hover > tbody > tr:hover { background-color: #e0e0e0; } /* hover needs to come after striped so that striped rows have hover */ .table-hover > tbody > tr:hover { background-color: #e0e0e0; } /* hover needs to come after striped so that striped rows have hover */
.table-hover > tbody > tr.has-warning:hover, .table-hover > tbody > tr.has-warning-hover:hover { background-color: #f8edb5; border-color: #f6e79d; } .table-hover > tbody > tr.has-warning:hover, .table-hover > tbody > tr.has-warning-hover:hover { background-color: #f8edb5; border-color: #f6e79d; }
tr[data-row-index="0"] td { border-top: 0.25em solid #000; }
+4 -4
View File
@@ -37,7 +37,7 @@
<tr> <tr>
<th class="small-no-wrap rank-pad">Rank</th> <th class="small-no-wrap rank-pad">Rank</th>
<th class="small-no-wrap">ID</th> <th class="small-no-wrap">ID</th>
<th>Team Name</th> <th class="left">Team Name</th>
{% for i in range(scoreCount) %} {% for i in range(scoreCount) %}
<th class="small-no-wrap">{{ i + 1 }}</th> <th class="small-no-wrap">{{ i + 1 }}</th>
{% endfor %} {% endfor %}
@@ -45,8 +45,8 @@
</thead> </thead>
<tbody class="js-standings"> <tbody class="js-standings">
{% for team in teams %} {% for team in teams %}
<tr class="ui-row" data-row-index="{{ team.id }}"> <tr class="ui-row" data-row-index="{{ loop.index - 1}}">
<td>?</td> <td class="js-rank">?</td>
<td>{{ team.id }}</td> <td>{{ team.id }}</td>
{% if team.name | length > 0 %} {% if team.name | length > 0 %}
<td>{{ team.name }}</td> <td>{{ team.name }}</td>
@@ -55,7 +55,7 @@
{% endif %} {% endif %}
<td class="js-total-score">{{ team.scores | sum }}</td> <td class="js-total-score">{{ team.scores | sum }}</td>
{% for score in team.scores %} {% for score in team.scores %}
<td>{{ score }}</td> <td class="small-no-wrap right">{{ score }}</td>
{% endfor %} {% endfor %}
</tr> </tr>
{% endfor %} {% endfor %}
+1
View File
@@ -66,6 +66,7 @@ def refreshScores() -> None:
scores=team['scores'] scores=team['scores']
) for team in temp ) for team in temp
] ]
temp.sort(key=lambda team : sum(team.scores), reverse=True)
current_app.logger.debug(f'Successfully loaded ({len(temp)} teams).') current_app.logger.debug(f'Successfully loaded ({len(temp)} teams).')
global teams global teams