Index page updates to latest score
parent
2bec2b4be5
commit
6243427976
|
@ -84,7 +84,7 @@ export async function populateDivisions (divisionDropdown, selectedSportID, sele
|
|||
}
|
||||
}
|
||||
|
||||
export async function populateTeams(teamDropdown, selectedSportID, selectedTeamID) {
|
||||
export async function populateTeams(teamDropdown, selectedSportID, selectedTeamID = undefined) {
|
||||
teamDropdown.innerHTML = "";
|
||||
|
||||
if(selectedSportID) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as Data from "./data.js";
|
||||
import * as Form from "./form.js";
|
||||
|
||||
const sportDropdown = document.getElementById('sport-dropdown');
|
||||
const seasonDropdown = document.getElementById('year-dropdown');
|
||||
|
@ -15,93 +16,48 @@ const manageButton = document.getElementById('manage-button');
|
|||
|
||||
|
||||
|
||||
async function listSeasons() {
|
||||
seasonDropdown.innerHTML = "";
|
||||
async function initializeForm() {
|
||||
let latestGame;
|
||||
|
||||
const seasonsList = await Data.getSeasons();
|
||||
|
||||
seasonsList.forEach(season => {
|
||||
const option = document.createElement('option');
|
||||
option.text = (season.year - 1) + "-" + season.year;
|
||||
option.value = season.id;
|
||||
seasonDropdown.appendChild(option);
|
||||
});
|
||||
}
|
||||
listSeasons();
|
||||
|
||||
async function listSports() {
|
||||
sportDropdown.innerHTML = "";
|
||||
|
||||
const sportsList = await Data.getSports();
|
||||
|
||||
sportsList.forEach(sport => {
|
||||
const option = document.createElement('option');
|
||||
option.text = sport.name;
|
||||
option.value = sport.id;
|
||||
sportDropdown.appendChild(option);
|
||||
});
|
||||
|
||||
listGenders();
|
||||
}
|
||||
listSports();
|
||||
|
||||
async function listGenders() {
|
||||
genderDropdown.innerHTML = "";
|
||||
|
||||
const selectedSportID = sportDropdown.value;
|
||||
const gendersList = await Data.getGenders(selectedSportID);
|
||||
|
||||
if(selectedSportID) {
|
||||
gendersList.forEach(gender => {
|
||||
const option = document.createElement('option');
|
||||
option.text = (gender.name == "female") ? "Female" : (gender.name == "male") ? "Male" : "";
|
||||
option.value = gender.name;
|
||||
genderDropdown.appendChild(option);
|
||||
});
|
||||
try {
|
||||
latestGame = await Data.getLatestGame();
|
||||
} catch {
|
||||
latestGame = null;
|
||||
}
|
||||
|
||||
listDivisions();
|
||||
if(latestGame) {
|
||||
Form.populateSeasons(seasonDropdown, latestGame.seasonID);
|
||||
|
||||
const division = await Data.getDivision(latestGame.divisionID);
|
||||
await Form.populateSports(sportDropdown, division.sportID);
|
||||
await Form.populateGenders(genderDropdown, sportDropdown.value, division.gender.name);
|
||||
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value, latestGame.divisionID);
|
||||
await Form.populateTeams(teamDropdown, sportDropdown.value, latestGame.team1ID);
|
||||
} else {
|
||||
Form.populateSeasons(seasonDropdown);
|
||||
await Form.populateSports(sportDropdown);
|
||||
await Form.populateGenders(genderDropdown, sportDropdown.value);
|
||||
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||
await Form.populateTeams(teamDropdown, sportDropdown.value);
|
||||
}
|
||||
|
||||
async function listDivisions() {
|
||||
divisionDropdown.innerHTML = "";
|
||||
sportDropdown.onchange = async () => {
|
||||
await Form.populateGenders(genderDropdown, sportDropdown.value)
|
||||
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||
await Form.populateTeams(teamDropdown, sportDropdown.value);
|
||||
};
|
||||
|
||||
const selectedSportID = sportDropdown.value;
|
||||
const selectedGender = genderDropdown.value;
|
||||
genderDropdown.onchange = async () => {
|
||||
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||
};
|
||||
|
||||
loadTable();
|
||||
|
||||
if(selectedGender) {
|
||||
const divisionsList = await Data.getDivisions(selectedSportID, selectedGender);
|
||||
|
||||
divisionsList.forEach(division => {
|
||||
const option = document.createElement('option');
|
||||
option.text = division.name;
|
||||
option.value = division.id;
|
||||
divisionDropdown.appendChild(option);
|
||||
});
|
||||
}
|
||||
listTeams();
|
||||
}
|
||||
initializeForm();
|
||||
|
||||
async function listTeams() {
|
||||
teamDropdown.innerHTML = "";
|
||||
|
||||
const selectedSportID = sportDropdown.value;
|
||||
|
||||
if(selectedSportID) {
|
||||
const teamsList = await Data.getTeams(selectedSportID);
|
||||
|
||||
teamsList.forEach(team => {
|
||||
const option = document.createElement('option');
|
||||
option.text = team.name;
|
||||
option.value = team.id;
|
||||
teamDropdown.appendChild(option);
|
||||
});
|
||||
}
|
||||
|
||||
listGames();
|
||||
}
|
||||
|
||||
async function listGames() {
|
||||
async function loadTable() {
|
||||
gamesTable.innerHTML = "";
|
||||
gamesTableHeader.textContent = "";
|
||||
noScoresMessage.textContent = "";
|
||||
|
@ -146,8 +102,8 @@ async function listGames() {
|
|||
}
|
||||
}
|
||||
}
|
||||
async function setupGamesTableHeaders() {
|
||||
|
||||
async function setupGamesTableHeaders() {
|
||||
const row = document.createElement('tr');
|
||||
|
||||
const scoresHeader = document.createElement('th');
|
||||
|
@ -167,16 +123,6 @@ async function setupGamesTableHeaders() {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
sportDropdown.onchange = (() => {
|
||||
listGenders();
|
||||
listTeams();
|
||||
});
|
||||
genderDropdown.onchange = listDivisions;
|
||||
teamDropdown.onchange = listGames;
|
||||
seasonDropdown.onchange = listGames;
|
||||
|
||||
if(addScoreButton) {
|
||||
addScoreButton.addEventListener('click', () => {
|
||||
window.location.href = '/manage/game';
|
||||
|
|
Reference in New Issue