From 0d9e70896a0d9fd853a48f26cfe49f1cd7ca7467 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Sun, 21 Nov 2021 15:40:48 -0700 Subject: [PATCH] Add function to list seasons in submit form --- public/scripts/data.js | 6 ++++++ public/scripts/submit.js | 17 +++++++++++++++-- routes/data.js | 8 +++++++- views/submit.pug | 1 - 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/public/scripts/data.js b/public/scripts/data.js index 01b681b..44d50a1 100644 --- a/public/scripts/data.js +++ b/public/scripts/data.js @@ -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; } \ No newline at end of file diff --git a/public/scripts/submit.js b/public/scripts/submit.js index dc3b2b7..64b62ac 100644 --- a/public/scripts/submit.js +++ b/public/scripts/submit.js @@ -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(); \ No newline at end of file +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(); \ No newline at end of file diff --git a/routes/data.js b/routes/data.js index 072a63e..aa61618 100644 --- a/routes/data.js +++ b/routes/data.js @@ -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; \ No newline at end of file diff --git a/views/submit.pug b/views/submit.pug index 25ebe71..5ac6ccf 100644 --- a/views/submit.pug +++ b/views/submit.pug @@ -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')