Tweak scores view page

main
sudoer777 2021-11-21 22:07:25 -07:00
parent 4f2b496cf2
commit 8674781ba9
2 changed files with 36 additions and 27 deletions

View File

@ -7,6 +7,7 @@ const divisionDropdown = document.getElementById('division-dropdown');
const teamDropdown = document.getElementById('team-dropdown');
const gamesTable = document.getElementById('games-table');
const gamesTableHeader = document.getElementById('games-table-header');
const noScoresMessage = document.getElementById('no-scores-message');
@ -101,43 +102,49 @@ async function listTeams() {
async function listGames() {
gamesTable.innerHTML = "";
gamesTableHeader.textContent = "";
noScoresMessage.textContent = "";
const selectedTeamID = teamDropdown.value;
const selectedDivisionID = divisionDropdown.value;
const selectedSeasonID = seasonDropdown.value;
if(selectedTeamID && selectedDivisionID) {
await setupGamesTable();
gamesTableHeader.textContent = `Scores for ${teamDropdown.options[teamDropdown.selectedIndex].text}`;
const gamesList = await Data.getGames(selectedTeamID, selectedDivisionID, selectedSeasonID);
if(gamesList.length > 0) {
await setupGamesTableHeaders();
gamesList.forEach((game) => {
const row = document.createElement('tr');
const scoreCell = document.createElement('td');
const winLossLine = document.createElement('span');
winLossLine.textContent = (game.team1Score > game.team2Score) ? "Win" : (game.team1Score < game.team2Score) ? "Loss" : "Tie";
scoreCell.appendChild(winLossLine);
const scoreLine = document.createElement('span');
scoreLine.textContent = game.team1Score + "-" + game.team2Score;
scoreCell.appendChild(scoreLine);
row.appendChild(scoreCell);
const opponentCell = document.createElement('td');
Data.getTeamName(game.team2ID)
.then(data => opponentCell.textContent = data);
row.appendChild(opponentCell);
const dateCell = document.createElement('td');
dateCell.textContent = game.date;
row.appendChild(dateCell);
gamesTable.appendChild(row);
});
gamesList.forEach((game) => {
const row = document.createElement('tr');
const scoreCell = document.createElement('td');
const winLossLine = document.createElement('span');
winLossLine.textContent = (game.team1Score > game.team2Score) ? "Win" : (game.team1Score < game.team2Score) ? "Loss" : "Tie";
scoreCell.appendChild(winLossLine);
const scoreLine = document.createElement('span');
scoreLine.textContent = game.team1Score + "-" + game.team2Score;
scoreCell.appendChild(scoreLine);
row.appendChild(scoreCell);
const opponentCell = document.createElement('td');
Data.getTeamName(game.team2ID)
.then(data => opponentCell.textContent = data);
row.appendChild(opponentCell);
const dateCell = document.createElement('td');
dateCell.textContent = game.date;
row.appendChild(dateCell);
gamesTable.appendChild(row);
});
}
else {
noScoresMessage.textContent = "No scores available";
}
}
}
async function setupGamesTable() {
gamesTableHeader.textContent = `Scores for ${teamDropdown.options[teamDropdown.selectedIndex].text}`;
async function setupGamesTableHeaders() {
const row = document.createElement('tr');
@ -165,4 +172,5 @@ sportDropdown.onchange = (() => {
listTeams();
});
genderDropdown.onchange = listDivisions;
teamDropdown.onchange = listGames;
teamDropdown.onchange = listGames;
seasonDropdown.onchange = listGames;

View File

@ -25,6 +25,7 @@ block content
span(class='form-section')
div
h2#games-table-header
span#no-scores-message
table
colgroup
col#score-column(span="1")