Merge branch 'submit-game-adjustments' into 'develop'
Add adjustments to develop branch See merge request sudoer777/score-tracker!10main
commit
17dbe8088f
12
.env.example
12
.env.example
|
@ -6,9 +6,9 @@ PGPASSWORD=dbuserpassword
|
|||
PGDATABASE=mydatabase
|
||||
PGPORT=5432
|
||||
|
||||
MAIL_FROM=fromaddress@example.com
|
||||
MAIL_HOST=smtp.smtphost.net
|
||||
MAIL_PORT=465
|
||||
MAIL_SECURE=true
|
||||
MAIL_USER=username
|
||||
MAIL_PASS=password
|
||||
#MAIL_FROM=fromaddress@example.com
|
||||
#MAIL_HOST=smtp.smtphost.net
|
||||
#MAIL_PORT=465
|
||||
#MAIL_SECURE=true
|
||||
#MAIL_USER=username
|
||||
#MAIL_PASS=password
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# Automatically deploy testing branch to Dokku test server on commit
|
||||
# https://cvcs-score-tracker.dokku.sudoer.ch
|
||||
|
||||
image: dokku/ci-docker-image
|
||||
|
||||
stages:
|
||||
- deploy
|
||||
|
||||
variables:
|
||||
GIT_DEPTH: 0
|
||||
|
||||
deploy:
|
||||
stage: deploy
|
||||
only:
|
||||
- testing
|
||||
variables:
|
||||
GIT_REMOTE_URL: ssh://dokku@ssh.dokku.sudoer.ch:1337/score-tracker
|
||||
GIT_SSH_COMMAND: 'ssh -o StrictHostKeyChecking=no'
|
||||
script:
|
||||
- dokku-deploy
|
||||
after_script:
|
||||
- dokku-unlock
|
|
@ -10,6 +10,5 @@ RUN npm install
|
|||
|
||||
COPY . /usr/src/app
|
||||
|
||||
ENV PORT 5000
|
||||
EXPOSE $PORT
|
||||
EXPOSE 5000
|
||||
CMD [ "npm", "start" ]
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
||||
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.edit = edit;
|
||||
exports.getFromID = getFromID;
|
||||
exports.getLatest = getLatest;
|
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,7 @@
|
|||
"version": "1.0.0-pre",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node ./bin/www",
|
||||
"start": "node ./bin/www"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "^3.2.2",
|
||||
|
@ -20,10 +20,6 @@
|
|||
"passport": "^0.5.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"pg": "^8.7.1",
|
||||
"pug": "2.0.0-beta11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^5.1.1",
|
||||
"supertest": "^3.0.0"
|
||||
"pug": "^3.0.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,14 @@ export async function getGame(gameID) {
|
|||
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() {
|
||||
const response = await fetch(`/data/accounts`);
|
||||
const accounts = await response.json();
|
||||
|
|
|
@ -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 = "";
|
||||
|
||||
if(selectedSportID) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as Data from "./data.js";
|
||||
import * as Form from "./form.js";
|
||||
|
||||
const sportDropdown = document.getElementById('sport-dropdown');
|
||||
const seasonDropdown = document.getElementById('year-dropdown');
|
||||
|
@ -15,93 +16,48 @@ const manageButton = document.getElementById('manage-button');
|
|||
|
||||
|
||||
|
||||
async function listSeasons() {
|
||||
seasonDropdown.innerHTML = "";
|
||||
async function initializeForm() {
|
||||
let latestGame;
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
});
|
||||
try {
|
||||
latestGame = await Data.getLatestGame();
|
||||
} catch {
|
||||
latestGame = null;
|
||||
}
|
||||
|
||||
listDivisions();
|
||||
}
|
||||
if(latestGame) {
|
||||
Form.populateSeasons(seasonDropdown, latestGame.seasonID);
|
||||
|
||||
async function listDivisions() {
|
||||
divisionDropdown.innerHTML = "";
|
||||
|
||||
const selectedSportID = sportDropdown.value;
|
||||
const selectedGender = genderDropdown.value;
|
||||
|
||||
if(selectedGender) {
|
||||
const divisionsList = await Data.getDivisions(selectedSportID, selectedGender);
|
||||
|
||||
divisionsList.forEach(division => {
|
||||
const option = document.createElement('option');
|
||||
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);
|
||||
});
|
||||
const division = await Data.getDivision(latestGame.divisionID);
|
||||
await Form.populateSports(sportDropdown, division.sportID);
|
||||
await Form.populateGenders(genderDropdown, sportDropdown.value, division.gender.name);
|
||||
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value, latestGame.divisionID);
|
||||
await Form.populateTeams(teamDropdown, sportDropdown.value, latestGame.team1ID);
|
||||
} else {
|
||||
Form.populateSeasons(seasonDropdown);
|
||||
await Form.populateSports(sportDropdown);
|
||||
await Form.populateGenders(genderDropdown, sportDropdown.value);
|
||||
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||
await Form.populateTeams(teamDropdown, sportDropdown.value);
|
||||
}
|
||||
|
||||
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 = "";
|
||||
gamesTableHeader.textContent = "";
|
||||
noScoresMessage.textContent = "";
|
||||
|
@ -136,6 +92,7 @@ async function listGames() {
|
|||
|
||||
const dateCell = document.createElement('td');
|
||||
dateCell.textContent = game.date;
|
||||
dateCell.style['white-space'] = 'nowrap';
|
||||
row.appendChild(dateCell);
|
||||
|
||||
gamesTable.appendChild(row);
|
||||
|
@ -146,8 +103,8 @@ async function listGames() {
|
|||
}
|
||||
}
|
||||
}
|
||||
async function setupGamesTableHeaders() {
|
||||
|
||||
async function setupGamesTableHeaders() {
|
||||
const row = document.createElement('tr');
|
||||
|
||||
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) {
|
||||
addScoreButton.addEventListener('click', () => {
|
||||
window.location.href = '/manage/game';
|
||||
|
|
|
@ -40,12 +40,24 @@ async function initializeForm() {
|
|||
team2ScoreTextbox.value = game.team2Score;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
const game = await Data.getLatestGame(true);
|
||||
|
||||
Form.populateSeasons(seasonDropdown, game.seasonID);
|
||||
const data = await Data.getDivision(game.divisionID)
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -122,7 +122,13 @@ router.get('/games', async function(req, res, next) {
|
|||
router.get('/game', async function(req, res, next) {
|
||||
try {
|
||||
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);
|
||||
} catch(err) {
|
||||
console.error("ERROR: " + err.message);
|
||||
|
|
|
@ -14,7 +14,7 @@ var checkLoginStatus = require('./checkLoginStatus');
|
|||
|
||||
|
||||
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 });
|
||||
});
|
||||
|
||||
|
|
Reference in New Issue