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();
|
try {
|
||||||
|
latestGame = await Data.getLatestGame();
|
||||||
seasonsList.forEach(season => {
|
} catch {
|
||||||
const option = document.createElement('option');
|
latestGame = null;
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
sportDropdown.onchange = async () => {
|
||||||
divisionDropdown.innerHTML = "";
|
await Form.populateGenders(genderDropdown, sportDropdown.value)
|
||||||
|
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||||
|
await Form.populateTeams(teamDropdown, sportDropdown.value);
|
||||||
|
};
|
||||||
|
|
||||||
const selectedSportID = sportDropdown.value;
|
genderDropdown.onchange = async () => {
|
||||||
const selectedGender = genderDropdown.value;
|
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() {
|
async function loadTable() {
|
||||||
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() {
|
|
||||||
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';
|
||||||
|
|
Reference in New Issue