Allow check/unchecking all decks for a player in graph page

This commit is contained in:
Jack Jackson 2024-07-31 20:50:21 -07:00
parent fff4fa6c57
commit 5d71f422f3
4 changed files with 20 additions and 2 deletions

View File

@ -62,7 +62,6 @@ def stats_graph_api(
# Add a fake final datapoint to the series for any decks that weren't played in the latest game, so that lines # Add a fake final datapoint to the series for any decks that weren't played in the latest game, so that lines
# continue all the way to the end of the graph # continue all the way to the end of the graph
latest_date_formatted = latest_date_so_far.strftime("%Y-%m-%d") latest_date_formatted = latest_date_so_far.strftime("%Y-%m-%d")
print(f"DEBUG = {latest_date_formatted=}")
for games in data_grouped_by_deck.values(): for games in data_grouped_by_deck.values():
if games[-1]["date"] != latest_date_formatted: if games[-1]["date"] != latest_date_formatted:
games.append( games.append(

View File

@ -2,4 +2,12 @@
float: left; float: left;
margin: 2px; margin: 2px;
background-color: lightblue; background-color: lightblue;
}
p.playerName {
cursor: pointer;
}
p.all_checked {
font-weight: bold;
} }

View File

@ -15,6 +15,16 @@ function updateGraphWithFilter() {
$(document).ready(function() { $(document).ready(function() {
$('#filter_button').click(updateGraphWithFilter) $('#filter_button').click(updateGraphWithFilter)
$('body').on('click', 'p.playerName', function() {
// Check or uncheck all checkboxes in that div
if ($(this).hasClass('all_checked')) {
$(this).parent().children('input[type=checkbox]').prop('checked', false);
$(this).removeClass('all_checked')
} else {
$(this).parent().children('input[type=checkbox]').prop('checked', true);
$(this).addClass('all_checked')
}
})
fetch('/api/deck/by_player') fetch('/api/deck/by_player')
.then(response => response.json()) .then(response => response.json())
@ -58,7 +68,7 @@ function buildPlayerDecksDiv(parentDiv, playerName, playerDecks) {
div = $('<div>', div = $('<div>',
id='player_div_for_' + playerName id='player_div_for_' + playerName
) )
div.append('<p>' + playerName + '</p>') div.append('<p class="playerName">' + playerName + '</p>')
for (deck of playerDecks) { for (deck of playerDecks) {
div.append('<input type="checkbox" id="' + deck["id"] + '" name="' + deck["name"] + '" value="' + deck["name"] + '"><label for="' + deck["name"] + '">' + deck["name"] + '</label><br/>') div.append('<input type="checkbox" id="' + deck["id"] + '" name="' + deck["name"] + '" value="' + deck["name"] + '"><label for="' + deck["name"] + '">' + deck["name"] + '</label><br/>')
} }

View File

@ -16,6 +16,7 @@
<div id="options"> <div id="options">
<h2>Filter</h2> <h2>Filter</h2>
<h3>(Click a player name to check/uncheck all their decks)</h3>
<button id="filter_button">Go!</button><br/> <button id="filter_button">Go!</button><br/>
</div> </div>
{% endblock %} {% endblock %}