2021-11-21 22:30:54 +00:00
|
|
|
import * as Data from "./data.js";
|
|
|
|
|
|
|
|
|
|
|
|
const sportDropdown = document.getElementById('sport-dropdown');
|
2021-11-21 22:40:48 +00:00
|
|
|
const seasonDropdown = document.getElementById('year-dropdown');
|
2021-11-21 23:24:43 +00:00
|
|
|
const genderDropdown = document.getElementById('gender-dropdown');
|
2021-11-21 23:48:03 +00:00
|
|
|
const divisionDropdown = document.getElementById('division-dropdown');
|
2021-11-21 22:30:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function listSports() {
|
2021-11-21 22:40:48 +00:00
|
|
|
const sportsList = await Data.getSports();
|
2021-11-21 22:30:54 +00:00
|
|
|
|
|
|
|
sportsList.forEach(sport => {
|
|
|
|
const option = document.createElement('option');
|
|
|
|
option.text = sport.name;
|
|
|
|
option.value = sport.id;
|
|
|
|
sportDropdown.appendChild(option);
|
|
|
|
});
|
2021-11-21 23:48:03 +00:00
|
|
|
|
|
|
|
listSeasons();
|
2021-11-21 22:30:54 +00:00
|
|
|
}
|
2021-11-21 22:40:48 +00:00
|
|
|
listSports();
|
|
|
|
|
|
|
|
async function listSeasons() {
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
2021-11-21 23:24:43 +00:00
|
|
|
listSeasons();
|
|
|
|
|
|
|
|
async function listGenders() {
|
|
|
|
genderDropdown.innerHTML = "";
|
|
|
|
|
|
|
|
const selectedSportID = sportDropdown.value;
|
|
|
|
const gendersList = await Data.getGenders(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);
|
|
|
|
});
|
2021-11-21 23:48:03 +00:00
|
|
|
|
|
|
|
listDivisions();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function listDivisions() {
|
|
|
|
divisionDropdown.innerHTML = "";
|
|
|
|
|
|
|
|
const selectedSportID = sportDropdown.value;
|
|
|
|
const selectedGender = genderDropdown.value;
|
|
|
|
|
|
|
|
if(!selectedGender) return;
|
|
|
|
|
|
|
|
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);
|
|
|
|
})
|
2021-11-21 23:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-21 23:48:03 +00:00
|
|
|
sportDropdown.onchange = listGenders;
|
|
|
|
genderDropdown.onchange = listDivisions;
|