Merge branch 'develop' into 'testing'

Add tweaks to testing

See merge request sudoer777/score-tracker!11
main
Ethan Reece 2021-11-27 05:11:11 +00:00
commit 9ba5511fbb
9 changed files with 137 additions and 157 deletions

View File

@ -108,6 +108,16 @@ async function getFromID(gameID) {
return new Game(row[0], row[3].toISOString().slice(0,10), row[4], row[5], row[6], row[7], row[1], row[2], row[8]); return new Game(row[0], row[3].toISOString().slice(0,10), row[4], row[5], row[6], row[7], row[1], row[2], row[8]);
} }
async function getLatest(userID = undefined) {
if(userID) {
const games = await retrieveByUser(userID);
return games[0];
} else {
const games = await retrieve();
return games[0];
}
}
@ -118,3 +128,4 @@ exports.retrieve = retrieve;
exports.retrieveByUser = retrieveByUser; exports.retrieveByUser = retrieveByUser;
exports.edit = edit; exports.edit = edit;
exports.getFromID = getFromID; exports.getFromID = getFromID;
exports.getLatest = getLatest;

104
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "score-tracker", "name": "score-tracker",
"version": "1.0.0-pre", "version": "1.0.1-pre",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "score-tracker", "name": "score-tracker",
"version": "1.0.0-pre", "version": "1.0.1-pre",
"dependencies": { "dependencies": {
"async": "^3.2.2", "async": "^3.2.2",
"bcrypt": "^5.0.1", "bcrypt": "^5.0.1",
@ -629,6 +629,25 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/glob": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
"integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==",
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/has": { "node_modules/has": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
@ -927,6 +946,17 @@
"node": ">= 8" "node": ">= 8"
} }
}, },
"node_modules/mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"bin": {
"mkdirp": "bin/cmd.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/morgan": { "node_modules/morgan": {
"version": "1.9.1", "version": "1.9.1",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz", "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
@ -1431,25 +1461,6 @@
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/rimraf/node_modules/glob": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
"integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==",
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/safe-buffer": { "node_modules/safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
@ -1609,17 +1620,6 @@
"node": ">= 10" "node": ">= 10"
} }
}, },
"node_modules/tar/node_modules/mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"bin": {
"mkdirp": "bin/cmd.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/to-fast-properties": { "node_modules/to-fast-properties": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
@ -2218,6 +2218,19 @@
"has-symbols": "^1.0.1" "has-symbols": "^1.0.1"
} }
}, },
"glob": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
"integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"has": { "has": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
@ -2437,6 +2450,11 @@
"yallist": "^4.0.0" "yallist": "^4.0.0"
} }
}, },
"mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
},
"morgan": { "morgan": {
"version": "1.9.1", "version": "1.9.1",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz", "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
@ -2832,21 +2850,6 @@
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"requires": { "requires": {
"glob": "^7.1.3" "glob": "^7.1.3"
},
"dependencies": {
"glob": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
"integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
}
} }
}, },
"safe-buffer": { "safe-buffer": {
@ -2970,13 +2973,6 @@
"minizlib": "^2.1.1", "minizlib": "^2.1.1",
"mkdirp": "^1.0.3", "mkdirp": "^1.0.3",
"yallist": "^4.0.0" "yallist": "^4.0.0"
},
"dependencies": {
"mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
}
} }
}, },
"to-fast-properties": { "to-fast-properties": {

View File

@ -1,6 +1,6 @@
{ {
"name": "score-tracker", "name": "score-tracker",
"version": "1.0.0-pre", "version": "1.0.1-pre",
"private": true, "private": true,
"scripts": { "scripts": {
"start": "node ./bin/www" "start": "node ./bin/www"

View File

@ -78,6 +78,14 @@ export async function getGame(gameID) {
return game; return game;
} }
export async function getLatestGame(ofUser = false) {
let URL = `/data/game?`;
if(ofUser) URL += `ofuser=1`;
const response = await fetch(URL);
const game = await response.json();
return game;
}
export async function getAccounts() { export async function getAccounts() {
const response = await fetch(`/data/accounts`); const response = await fetch(`/data/accounts`);
const accounts = await response.json(); const accounts = await response.json();

View File

@ -84,7 +84,7 @@ export async function populateDivisions (divisionDropdown, selectedSportID, sele
} }
} }
export async function populateTeams(teamDropdown, selectedSportID, selectedTeamID) { export async function populateTeams(teamDropdown, selectedSportID, selectedTeamID = undefined) {
teamDropdown.innerHTML = ""; teamDropdown.innerHTML = "";
if(selectedSportID) { if(selectedSportID) {

View File

@ -1,4 +1,5 @@
import * as Data from "./data.js"; import * as Data from "./data.js";
import * as Form from "./form.js";
const sportDropdown = document.getElementById('sport-dropdown'); const sportDropdown = document.getElementById('sport-dropdown');
const seasonDropdown = document.getElementById('year-dropdown'); const seasonDropdown = document.getElementById('year-dropdown');
@ -15,93 +16,48 @@ const manageButton = document.getElementById('manage-button');
async function listSeasons() { async function initializeForm() {
seasonDropdown.innerHTML = ""; let latestGame;
const seasonsList = await Data.getSeasons(); try {
latestGame = await Data.getLatestGame();
seasonsList.forEach(season => { } catch {
const option = document.createElement('option'); latestGame = null;
option.text = (season.year - 1) + "-" + season.year;
option.value = season.id;
seasonDropdown.appendChild(option);
});
}
listSeasons();
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();
}
listSports();
async function listGenders() {
genderDropdown.innerHTML = "";
const selectedSportID = sportDropdown.value;
const gendersList = await Data.getGenders(selectedSportID);
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);
});
} }
listDivisions(); if(latestGame) {
} Form.populateSeasons(seasonDropdown, latestGame.seasonID);
async function listDivisions() { const division = await Data.getDivision(latestGame.divisionID);
divisionDropdown.innerHTML = ""; await Form.populateSports(sportDropdown, division.sportID);
await Form.populateGenders(genderDropdown, sportDropdown.value, division.gender.name);
const selectedSportID = sportDropdown.value; await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value, latestGame.divisionID);
const selectedGender = genderDropdown.value; await Form.populateTeams(teamDropdown, sportDropdown.value, latestGame.team1ID);
} else {
if(selectedGender) { Form.populateSeasons(seasonDropdown);
const divisionsList = await Data.getDivisions(selectedSportID, selectedGender); await Form.populateSports(sportDropdown);
await Form.populateGenders(genderDropdown, sportDropdown.value);
divisionsList.forEach(division => { await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
const option = document.createElement('option'); await Form.populateTeams(teamDropdown, sportDropdown.value);
option.text = division.name;
option.value = division.id;
divisionDropdown.appendChild(option);
});
}
listTeams();
}
async function listTeams() {
teamDropdown.innerHTML = "";
const selectedSportID = sportDropdown.value;
if(selectedSportID) {
const teamsList = await Data.getTeams(selectedSportID);
teamsList.forEach(team => {
const option = document.createElement('option');
option.text = team.name;
option.value = team.id;
teamDropdown.appendChild(option);
});
} }
listGames(); sportDropdown.onchange = async () => {
} await Form.populateGenders(genderDropdown, sportDropdown.value)
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
await Form.populateTeams(teamDropdown, sportDropdown.value);
};
async function listGames() { genderDropdown.onchange = async () => {
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
};
loadTable();
}
initializeForm();
async function loadTable() {
gamesTable.innerHTML = ""; gamesTable.innerHTML = "";
gamesTableHeader.textContent = ""; gamesTableHeader.textContent = "";
noScoresMessage.textContent = ""; noScoresMessage.textContent = "";
@ -136,6 +92,7 @@ async function listGames() {
const dateCell = document.createElement('td'); const dateCell = document.createElement('td');
dateCell.textContent = game.date; dateCell.textContent = game.date;
dateCell.style['white-space'] = 'nowrap';
row.appendChild(dateCell); row.appendChild(dateCell);
gamesTable.appendChild(row); gamesTable.appendChild(row);
@ -146,8 +103,8 @@ async function listGames() {
} }
} }
} }
async function setupGamesTableHeaders() {
async function setupGamesTableHeaders() {
const row = document.createElement('tr'); const row = document.createElement('tr');
const scoresHeader = document.createElement('th'); const scoresHeader = document.createElement('th');
@ -167,16 +124,6 @@ async function setupGamesTableHeaders() {
sportDropdown.onchange = (() => {
listGenders();
listTeams();
});
genderDropdown.onchange = listDivisions;
teamDropdown.onchange = listGames;
seasonDropdown.onchange = listGames;
if(addScoreButton) { if(addScoreButton) {
addScoreButton.addEventListener('click', () => { addScoreButton.addEventListener('click', () => {
window.location.href = '/manage/game'; window.location.href = '/manage/game';

View File

@ -40,12 +40,24 @@ async function initializeForm() {
team2ScoreTextbox.value = game.team2Score; team2ScoreTextbox.value = game.team2Score;
} }
else { else {
await Form.populateSeasons(seasonDropdown); try {
await Form.populateSports(sportDropdown) const game = await Data.getLatestGame(true);
await Form.populateGenders(genderDropdown, sportDropdown.value)
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value); Form.populateSeasons(seasonDropdown, game.seasonID);
await Form.populateTeams(team1Dropdown, sportDropdown.value); const data = await Data.getDivision(game.divisionID)
await Form.populateTeams(team2Dropdown, sportDropdown.value); await Form.populateSports(sportDropdown, data.sportID)
await Form.populateGenders(genderDropdown, sportDropdown.value, data.gender.name)
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value, game.divisionID);
await Form.populateTeams(team1Dropdown, sportDropdown.value, game.team1ID);
await Form.populateTeams(team2Dropdown, sportDropdown.value, game.team2ID);
} catch {
await Form.populateSeasons(seasonDropdown);
await Form.populateSports(sportDropdown)
await Form.populateGenders(genderDropdown, sportDropdown.value)
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
await Form.populateTeams(team1Dropdown, sportDropdown.value);
await Form.populateTeams(team2Dropdown, sportDropdown.value);
}
dateInput.value = (new Date()).toISOString().slice(0,10); dateInput.value = (new Date()).toISOString().slice(0,10);
} }

View File

@ -122,7 +122,13 @@ router.get('/games', async function(req, res, next) {
router.get('/game', async function(req, res, next) { router.get('/game', async function(req, res, next) {
try { try {
const gameID = req.query.game; const gameID = req.query.game;
const data = await games.getFromID(gameID); const ofUser = req.query.ofuser;
const currentUserID = req.user ? req.user[0] : null;
let data;
if(gameID) data = await games.getFromID(gameID);
else if(ofUser) data = await games.getLatest(currentUserID);
else data = await games.getLatest();
res.json(data); res.json(data);
} catch(err) { } catch(err) {
console.error("ERROR: " + err.message); console.error("ERROR: " + err.message);

View File

@ -14,7 +14,7 @@ var checkLoginStatus = require('./checkLoginStatus');
router.get('/' ,checkLoginStatus.user, function(req, res, next) { router.get('/' ,checkLoginStatus.user, function(req, res, next) {
if(req.user[2]) res.render('manage', { title: 'Score Management', userLoggedIn: !!req.user }); if(req.user[2]) res.render('manage', { title: 'Management Panel', userLoggedIn: !!req.user });
else res.render('manage/manage-nonadmin', { title: "My Games", userLoggedIn: !!req.user }); else res.render('manage/manage-nonadmin', { title: "My Games", userLoggedIn: !!req.user });
}); });