Add function to list seasons in submit form

main
sudoer777 2021-11-21 15:40:48 -07:00
parent 30ddb13ec6
commit 0d9e70896a
4 changed files with 28 additions and 4 deletions

View File

@ -2,4 +2,10 @@ export async function getSports() {
const response = await fetch('/data/sports'); const response = await fetch('/data/sports');
const sportsList = await response.json(); const sportsList = await response.json();
return sportsList; return sportsList;
}
export async function getSeasons() {
const response = await fetch('/data/seasons');
const seasonsList = await response.json();
return seasonsList;
} }

View File

@ -2,13 +2,14 @@ import * as Data from "./data.js";
const sportDropdown = document.getElementById('sport-dropdown'); const sportDropdown = document.getElementById('sport-dropdown');
const seasonDropdown = document.getElementById('year-dropdown');
async function listSports() { async function listSports() {
let sportsList = await Data.getSports(); const sportsList = await Data.getSports();
sportsList.forEach(sport => { sportsList.forEach(sport => {
const option = document.createElement('option'); const option = document.createElement('option');
@ -17,4 +18,16 @@ async function listSports() {
sportDropdown.appendChild(option); sportDropdown.appendChild(option);
}); });
} }
listSports(); 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);
});
}
listSeasons();

View File

@ -1,11 +1,17 @@
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
var sports = require('../database/scores/sports'); var sports = require('../database/scores/sports');
var seasons = require('../database/scores/seasons');
/* GET submit page. */
router.get('/sports', function(req, res, next) { router.get('/sports', function(req, res, next) {
sports.retrieveAll() sports.retrieveAll()
.then(data => res.json(data)); .then(data => res.json(data));
}); });
router.get('/seasons', function(req, res, next) {
seasons.retrieveAll()
.then(data => res.json(data));
})
module.exports = router; module.exports = router;

View File

@ -10,7 +10,6 @@ block content
label Year label Year
span(class='form-section-input') span(class='form-section-input')
select#year-dropdown(name="year" class="main-dropdown") select#year-dropdown(name="year" class="main-dropdown")
option(value="2022" selected) 2021-2022
span(class='form-section') span(class='form-section')
label Sport label Sport
span(class='form-section-input') span(class='form-section-input')