Add function to list seasons in submit form
parent
30ddb13ec6
commit
0d9e70896a
|
@ -3,3 +3,9 @@ export async function getSports() {
|
||||||
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;
|
||||||
|
}
|
|
@ -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');
|
||||||
|
@ -18,3 +19,15 @@ async function listSports() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
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 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;
|
|
@ -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')
|
||||||
|
|
Reference in New Issue