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 = "";
|
teamDropdown.innerHTML = "";
|
||||||
|
|
||||||
if(selectedSportID) {
|
if(selectedSportID) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import * as Data from "./data.js";
|
import * as Data from "./data.js";
|
||||||
|
import * as Form from "./form.js";
|
||||||
|
|
||||||
const sportDropdown = document.getElementById('sport-dropdown');
|
const sportDropdown = document.getElementById('sport-dropdown');
|
||||||
const seasonDropdown = document.getElementById('year-dropdown');
|
const seasonDropdown = document.getElementById('year-dropdown');
|
||||||
|
@ -15,93 +16,48 @@ const manageButton = document.getElementById('manage-button');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function listSeasons() {
|
async function initializeForm() {
|
||||||
seasonDropdown.innerHTML = "";
|
let latestGame;
|
||||||
|
|
||||||
const seasonsList = await Data.getSeasons();
|
|
||||||
|
|
||||||
seasonsList.forEach(season => {
|
try {
|
||||||
const option = document.createElement('option');
|
latestGame = await Data.getLatestGame();
|
||||||
option.text = (season.year - 1) + "-" + season.year;
|
} catch {
|
||||||
option.value = season.id;
|
latestGame = null;
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
listDivisions();
|
if(latestGame) {
|
||||||
}
|
Form.populateSeasons(seasonDropdown, latestGame.seasonID);
|
||||||
|
|
||||||
async function listDivisions() {
|
const division = await Data.getDivision(latestGame.divisionID);
|
||||||
divisionDropdown.innerHTML = "";
|
await Form.populateSports(sportDropdown, division.sportID);
|
||||||
|
await Form.populateGenders(genderDropdown, sportDropdown.value, division.gender.name);
|
||||||
const selectedSportID = sportDropdown.value;
|
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value, latestGame.divisionID);
|
||||||
const selectedGender = genderDropdown.value;
|
await Form.populateTeams(teamDropdown, sportDropdown.value, latestGame.team1ID);
|
||||||
|
} else {
|
||||||
if(selectedGender) {
|
Form.populateSeasons(seasonDropdown);
|
||||||
const divisionsList = await Data.getDivisions(selectedSportID, selectedGender);
|
await Form.populateSports(sportDropdown);
|
||||||
|
await Form.populateGenders(genderDropdown, sportDropdown.value);
|
||||||
divisionsList.forEach(division => {
|
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||||
const option = document.createElement('option');
|
await Form.populateTeams(teamDropdown, sportDropdown.value);
|
||||||
option.text = division.name;
|
|
||||||
option.value = division.id;
|
|
||||||
divisionDropdown.appendChild(option);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
listTeams();
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
sportDropdown.onchange = async () => {
|
||||||
}
|
await Form.populateGenders(genderDropdown, sportDropdown.value)
|
||||||
|
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||||
|
await Form.populateTeams(teamDropdown, sportDropdown.value);
|
||||||
|
};
|
||||||
|
|
||||||
async function listGames() {
|
genderDropdown.onchange = async () => {
|
||||||
|
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
loadTable();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
initializeForm();
|
||||||
|
|
||||||
|
async function loadTable() {
|
||||||
gamesTable.innerHTML = "";
|
gamesTable.innerHTML = "";
|
||||||
gamesTableHeader.textContent = "";
|
gamesTableHeader.textContent = "";
|
||||||
noScoresMessage.textContent = "";
|
noScoresMessage.textContent = "";
|
||||||
|
@ -146,8 +102,8 @@ async function listGames() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function setupGamesTableHeaders() {
|
|
||||||
|
|
||||||
|
async function setupGamesTableHeaders() {
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
|
|
||||||
const scoresHeader = document.createElement('th');
|
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) {
|
if(addScoreButton) {
|
||||||
addScoreButton.addEventListener('click', () => {
|
addScoreButton.addEventListener('click', () => {
|
||||||
window.location.href = '/manage/game';
|
window.location.href = '/manage/game';
|
||||||
|
@ -187,4 +133,4 @@ if(manageButton) {
|
||||||
manageButton.addEventListener('click', () => {
|
manageButton.addEventListener('click', () => {
|
||||||
window.location.href = '/manage'
|
window.location.href = '/manage'
|
||||||
});
|
});
|
||||||
}
|
}
|
Reference in New Issue