Compare commits
12 Commits
3a54ce0d56
...
1fef5fd818
Author | SHA1 | Date |
---|---|---|
Ethan Reece | 1fef5fd818 | |
sudoer777 | 84700c069f | |
sudoer777 | e231610fab | |
Ethan Reece | bb9c583ed2 | |
Ethan Reece | 46194f6e46 | |
Ethan Reece | 946316d4b5 | |
Ethan Reece | 8266b146ea | |
Ethan Reece | 6ceeed1ef6 | |
sudoer777 | 8d830735ff | |
sudoer777 | 29605613c0 | |
Ethan Reece | e6ffa52708 | |
Ethan Reece | 194b49a0f9 |
|
@ -12,11 +12,11 @@ A web app designed to collect and display scores for sports
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
This repository is designed to be pushed to Heroku/Dokku/etc.
|
This repository can be cloned and then pushed to Heroku/Dokku/etc.
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
- PostgreSQL (with empty database created and an account to access it)
|
- PostgreSQL (with an empty database created and an account to access it)
|
||||||
|
|
||||||
### Environment Variables
|
### Environment Variables
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ This repository is designed to be pushed to Heroku/Dokku/etc.
|
||||||
|
|
||||||
This program uses Node.js/Express.js for the backend, PostgreSQL for the database (with node-postgres), and Passport.js for managing users and sessions.
|
This program uses Node.js/Express.js for the backend, PostgreSQL for the database (with node-postgres), and Passport.js for managing users and sessions.
|
||||||
|
|
||||||
|
To view the code, clone the repository and open it in VSCode/VSCodium.
|
||||||
|
|
||||||
### Structure
|
### Structure
|
||||||
|
|
||||||
- `database` folder contains backend scripts for managing and storing data.
|
- `database` folder contains backend scripts for managing and storing data.
|
||||||
|
@ -44,6 +46,7 @@ This program uses Node.js/Express.js for the backend, PostgreSQL for the databas
|
||||||
- `auth.js` deals with logging in and out (`/auth/*`).
|
- `auth.js` deals with logging in and out (`/auth/*`).
|
||||||
- `checkLoginStatus.js` contains functions for checking the login status of the current user.
|
- `checkLoginStatus.js` contains functions for checking the login status of the current user.
|
||||||
- `data.js` sends various data to the client in JSON format (`/data/*`).
|
- `data.js` sends various data to the client in JSON format (`/data/*`).
|
||||||
|
- `fetch.js` sends more specific data formatted for specific pages in JSON format (`/fetch/*`)
|
||||||
- `index.js` directs to the home page (`/`).
|
- `index.js` directs to the home page (`/`).
|
||||||
- `manage.js` contains various functions that allows the user to add and edit items through the web browser (`/manage/*`).
|
- `manage.js` contains various functions that allows the user to add and edit items through the web browser (`/manage/*`).
|
||||||
- `views` folder contains pug templates for each webpage, and a `layout` template for the base layout of each page.
|
- `views` folder contains pug templates for each webpage, and a `layout` template for the base layout of each page.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "score-tracker",
|
"name": "score-tracker",
|
||||||
"version": "1.0.3-pre",
|
"version": "1.2.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./bin/www"
|
"start": "node ./bin/www"
|
||||||
|
|
|
@ -15,7 +15,7 @@ async function initializeForm() {
|
||||||
let params = new URLSearchParams(location.search);
|
let params = new URLSearchParams(location.search);
|
||||||
let divisionID = params.get('division');
|
let divisionID = params.get('division');
|
||||||
if(divisionID) {
|
if(divisionID) {
|
||||||
const division = await Data.getDivision(divisionID);
|
const division = await (await fetch(`/fetch/manage/division?division=${divisionID}`)).json();
|
||||||
|
|
||||||
nameTextbox.value = division.name;
|
nameTextbox.value = division.name;
|
||||||
|
|
||||||
|
@ -27,7 +27,11 @@ async function initializeForm() {
|
||||||
if(gender == 'female') genderDropdown.selectedIndex = 1;
|
if(gender == 'female') genderDropdown.selectedIndex = 1;
|
||||||
else genderDropdown.selectedIndex = 2;
|
else genderDropdown.selectedIndex = 2;
|
||||||
|
|
||||||
Form.populateSports(sportDropdown, division.sportID);
|
let data = {};
|
||||||
|
data.sports = [division.sport];
|
||||||
|
data.latestGame = {sportID : division.sportID };
|
||||||
|
|
||||||
|
Form.populateSports(sportDropdown, null, data);
|
||||||
|
|
||||||
Form.addHiddenValue('division', divisionID, submissionForm);
|
Form.addHiddenValue('division', divisionID, submissionForm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,14 +14,18 @@ async function initializeForm() {
|
||||||
let params = new URLSearchParams(location.search);
|
let params = new URLSearchParams(location.search);
|
||||||
let teamID = params.get('team');
|
let teamID = params.get('team');
|
||||||
if(teamID) {
|
if(teamID) {
|
||||||
const team = await Data.getTeam(teamID);
|
const team = await (await fetch(`/fetch/manage/team?team=${teamID}`)).json();
|
||||||
|
|
||||||
nameTextbox.value = team.name;
|
nameTextbox.value = team.name;
|
||||||
|
|
||||||
deleteButton.style.visibility = "visible";
|
deleteButton.style.visibility = "visible";
|
||||||
deleteButton.disabled = false;
|
deleteButton.disabled = false;
|
||||||
|
|
||||||
Form.populateSports(sportDropdown, team.sportID);
|
let data = {};
|
||||||
|
data.sports = [team.sport];
|
||||||
|
data.latestGame = {sportID : team.sportID };
|
||||||
|
|
||||||
|
Form.populateSports(sportDropdown, null, data);
|
||||||
|
|
||||||
Form.addHiddenValue('team', teamID, submissionForm);
|
Form.addHiddenValue('team', teamID, submissionForm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ router.get('/team', async function(req, res, next) {
|
||||||
console.error("ERROR: " + err.message);
|
console.error("ERROR: " + err.message);
|
||||||
res.status(500).send("An error has occurred");
|
res.status(500).send("An error has occurred");
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
router.get('/games', async function(req, res, next) {
|
router.get('/games', async function(req, res, next) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -35,7 +35,7 @@ router.get('/index/dropdown', async function(req, res, next) {
|
||||||
seasonsData = await seasons.retrieveAll();
|
seasonsData = await seasons.retrieveAll();
|
||||||
sportsData = await sports.retrieveAll();
|
sportsData = await sports.retrieveAll();
|
||||||
gendersData = await genders.retrieveBySport(latestGame.sportID);
|
gendersData = await genders.retrieveBySport(latestGame.sportID);
|
||||||
divisionsData = await divisions.retrieve(latestGame.sportID);
|
divisionsData = await divisions.retrieve(latestGame.sportID, latestGame.gender);
|
||||||
teamsData = await teams.retrieve(latestGame.sportID);
|
teamsData = await teams.retrieve(latestGame.sportID);
|
||||||
} else {
|
} else {
|
||||||
seasonsData = await seasons.retrieveAll();
|
seasonsData = await seasons.retrieveAll();
|
||||||
|
@ -102,7 +102,7 @@ router.get('/submit', async function(req, res, next) {
|
||||||
seasonsData = await seasons.retrieveAll();
|
seasonsData = await seasons.retrieveAll();
|
||||||
sportsData = await sports.retrieveAll();
|
sportsData = await sports.retrieveAll();
|
||||||
gendersData = await genders.retrieveBySport(latestGame.sportID);
|
gendersData = await genders.retrieveBySport(latestGame.sportID);
|
||||||
divisionsData = await divisions.retrieve(latestGame.sportID);
|
divisionsData = await divisions.retrieve(latestGame.sportID, latestGame.gender);
|
||||||
teamsData = await teams.retrieve(latestGame.sportID);
|
teamsData = await teams.retrieve(latestGame.sportID);
|
||||||
} else {
|
} else {
|
||||||
seasonsData = await seasons.retrieveAll();
|
seasonsData = await seasons.retrieveAll();
|
||||||
|
@ -136,6 +136,18 @@ router.get('/manage/divisions', async function (req, res, next) {
|
||||||
res.json(data);
|
res.json(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/manage/division', async function (req, res, next) {
|
||||||
|
try {
|
||||||
|
const divisionID = req.query.division;
|
||||||
|
const data = await divisions.getFromID(divisionID);
|
||||||
|
data.sport = await sports.getFromID(data.sportID);
|
||||||
|
res.json(data);
|
||||||
|
} catch(err) {
|
||||||
|
console.error("ERROR: " + err.message);
|
||||||
|
res.status(500).send("An error has occurred");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/manage/teams', async function (req, res, next) {
|
router.get('/manage/teams', async function (req, res, next) {
|
||||||
const data = await teams.retrieve();
|
const data = await teams.retrieve();
|
||||||
|
|
||||||
|
@ -146,6 +158,18 @@ router.get('/manage/teams', async function (req, res, next) {
|
||||||
res.json(data);
|
res.json(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/manage/team', async function (req, res, next) {
|
||||||
|
try {
|
||||||
|
const teamID = req.query.team;
|
||||||
|
const data = await teams.getFromID(teamID);
|
||||||
|
data.sport = await sports.getFromID(data.sportID);
|
||||||
|
res.json(data);
|
||||||
|
} catch(err) {
|
||||||
|
console.error("ERROR: " + err.message);
|
||||||
|
res.status(500).send("An error has occurred");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/manage/games', checkLoginStatus.user, async function (req, res, next) {
|
router.get('/manage/games', checkLoginStatus.user, async function (req, res, next) {
|
||||||
try{
|
try{
|
||||||
const userIsAdmin = req.user[2];
|
const userIsAdmin = req.user[2];
|
||||||
|
|
Reference in New Issue