Add function to list seasons in submit form
parent
30ddb13ec6
commit
0d9e70896a
|
@ -2,4 +2,10 @@ export async function getSports() {
|
|||
const response = await fetch('/data/sports');
|
||||
const sportsList = await response.json();
|
||||
return sportsList;
|
||||
}
|
||||
|
||||
export async function getSeasons() {
|
||||
const response = await fetch('/data/seasons');
|
||||
const seasonsList = await response.json();
|
||||
return seasonsList;
|
||||
}
|
|
@ -2,13 +2,14 @@ import * as Data from "./data.js";
|
|||
|
||||
|
||||
const sportDropdown = document.getElementById('sport-dropdown');
|
||||
const seasonDropdown = document.getElementById('year-dropdown');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async function listSports() {
|
||||
let sportsList = await Data.getSports();
|
||||
const sportsList = await Data.getSports();
|
||||
|
||||
sportsList.forEach(sport => {
|
||||
const option = document.createElement('option');
|
||||
|
@ -17,4 +18,16 @@ async function listSports() {
|
|||
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();
|
|
@ -1,11 +1,17 @@
|
|||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var sports = require('../database/scores/sports');
|
||||
var seasons = require('../database/scores/seasons');
|
||||
|
||||
|
||||
/* GET submit page. */
|
||||
router.get('/sports', function(req, res, next) {
|
||||
sports.retrieveAll()
|
||||
.then(data => res.json(data));
|
||||
});
|
||||
|
||||
router.get('/seasons', function(req, res, next) {
|
||||
seasons.retrieveAll()
|
||||
.then(data => res.json(data));
|
||||
})
|
||||
|
||||
module.exports = router;
|
|
@ -10,7 +10,6 @@ block content
|
|||
label Year
|
||||
span(class='form-section-input')
|
||||
select#year-dropdown(name="year" class="main-dropdown")
|
||||
option(value="2022" selected) 2021-2022
|
||||
span(class='form-section')
|
||||
label Sport
|
||||
span(class='form-section-input')
|
||||
|
|
Reference in New Issue