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-22 00:15:02 +00:00
|
|
|
const team1Dropdown = document.getElementById('team1-dropdown');
|
|
|
|
const team2Dropdown = document.getElementById('team2-dropdown');
|
2021-11-21 22:30:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-21 22:40:48 +00:00
|
|
|
async function listSeasons() {
|
2021-11-21 23:51:35 +00:00
|
|
|
seasonDropdown.innerHTML = "";
|
|
|
|
|
2021-11-21 22:40:48 +00:00
|
|
|
const seasonsList = await Data.getSeasons();
|
|
|
|
|
|
|
|
seasonsList.forEach(season => {
|
|
|
|
const option = document.createElement('option');
|
2021-11-22 21:07:51 +00:00
|
|
|
option.text = (season.year - 1) + "-" + season.year;
|
2021-11-21 22:40:48 +00:00
|
|
|
option.value = season.id;
|
|
|
|
seasonDropdown.appendChild(option);
|
|
|
|
});
|
|
|
|
}
|
2021-11-21 23:24:43 +00:00
|
|
|
listSeasons();
|
|
|
|
|
2021-11-21 23:51:35 +00:00
|
|
|
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();
|
2021-11-22 00:15:02 +00:00
|
|
|
listTeams();
|
2021-11-21 23:51:35 +00:00
|
|
|
}
|
|
|
|
listSports();
|
|
|
|
|
2021-11-21 23:24:43 +00:00
|
|
|
async function listGenders() {
|
|
|
|
genderDropdown.innerHTML = "";
|
|
|
|
|
|
|
|
const selectedSportID = sportDropdown.value;
|
|
|
|
const gendersList = await Data.getGenders(selectedSportID);
|
|
|
|
|
2021-11-21 23:51:35 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
2021-11-21 23:48:03 +00:00
|
|
|
|
|
|
|
listDivisions();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function listDivisions() {
|
|
|
|
divisionDropdown.innerHTML = "";
|
|
|
|
|
|
|
|
const selectedSportID = sportDropdown.value;
|
|
|
|
const selectedGender = genderDropdown.value;
|
|
|
|
|
2021-11-21 23:51:35 +00:00
|
|
|
if(selectedGender) {
|
|
|
|
const divisionsList = await Data.getDivisions(selectedSportID, selectedGender);
|
2021-11-21 23:48:03 +00:00
|
|
|
|
2021-11-21 23:51:35 +00:00
|
|
|
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-22 00:15:02 +00:00
|
|
|
async function listTeams() {
|
|
|
|
team1Dropdown.innerHTML = "";
|
|
|
|
team2Dropdown.innerHTML = "";
|
2021-11-21 23:24:43 +00:00
|
|
|
|
2021-11-22 00:15:02 +00:00
|
|
|
const selectedSportID = sportDropdown.value;
|
2021-11-21 23:24:43 +00:00
|
|
|
|
2021-11-22 00:15:02 +00:00
|
|
|
if(selectedSportID) {
|
|
|
|
const teamsList = await Data.getTeams(selectedSportID);
|
|
|
|
|
|
|
|
teamsList.forEach(team => {
|
|
|
|
const optionT1 = document.createElement('option');
|
|
|
|
optionT1.text = team.name;
|
|
|
|
optionT1.value = team.id;
|
|
|
|
team1Dropdown.appendChild(optionT1);
|
|
|
|
|
|
|
|
const optionT2 = document.createElement('option');
|
|
|
|
optionT2.text = team.name;
|
|
|
|
optionT2.value = team.id;
|
|
|
|
team2Dropdown.appendChild(optionT2);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-11-21 23:24:43 +00:00
|
|
|
|
|
|
|
|
2021-11-22 00:15:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sportDropdown.onchange = (() => {
|
|
|
|
listGenders();
|
|
|
|
listTeams();
|
|
|
|
});
|
2021-11-21 23:48:03 +00:00
|
|
|
genderDropdown.onchange = listDivisions;
|