Add page with only scores for non-admins

main
sudoer777 2021-11-25 18:29:18 -07:00
parent 4a108f606b
commit d351885375
3 changed files with 145 additions and 1 deletions

View File

@ -0,0 +1,127 @@
import * as Data from "./../data.js";
const gamesListTable = document.getElementById('games-list');
const addNewButton = document.getElementById('add-new-button');
function getGenderLetter(genderName) {
return genderName == "female" ? "F" : "M";
}
async function listGameHeaders() {
const headerRow = document.createElement('tr');
const teamsHeader = document.createElement('th');
teamsHeader.textContent = "Teams";
headerRow.appendChild(teamsHeader);
const scoreHeader = document.createElement('th');
headerRow.appendChild(scoreHeader);
const spacerHeader = document.createElement('th');
spacerHeader.classList.add('spacer-column');
headerRow.appendChild(spacerHeader);
const sportNameHeader = document.createElement('th');
sportNameHeader.textContent = "Sport";
headerRow.appendChild(sportNameHeader);
const dateHeader = document.createElement('th');
dateHeader.textContent = "Date";
headerRow.appendChild(dateHeader);
gamesListTable.appendChild(headerRow);
}
function listGame(game, row) {
const teamsCell = document.createElement('td');
const team1NameSpan = document.createElement('span');
Data.getTeam(game.team1ID)
.then(data => team1NameSpan.textContent = data.name);
teamsCell.appendChild(team1NameSpan);
const team2NameSpan = document.createElement('span');
Data.getTeam(game.team2ID)
.then(data => team2NameSpan.textContent = data.name);
teamsCell.appendChild(team2NameSpan);
row.appendChild(teamsCell);
const scoresCell = document.createElement('td');
const team1ScoreSpan = document.createElement('span');
team1ScoreSpan.textContent = game.team1Score;
scoresCell.appendChild(team1ScoreSpan);
const team2ScoreSpan = document.createElement('span');
team2ScoreSpan.textContent = game.team2Score;
scoresCell.appendChild(team2ScoreSpan);
row.appendChild(scoresCell);
const spacerCell = document.createElement('td');
row.appendChild(spacerCell);
const sportCell = document.createElement('td');
const sportSpan = document.createElement('span');
const divisionSpan = document.createElement('span');
divisionSpan.classList.add('flat-content');
const divisionNameSpan = document.createElement('span');
const divisionGenderSpan = document.createElement('span');
divisionSpan.appendChild(divisionNameSpan);
divisionSpan.appendChild(divisionGenderSpan);
Data.getDivision(game.divisionID)
.then(data => {
Data.getSportName(data.sportID)
.then(data => sportSpan.textContent = data);
divisionNameSpan.textContent = data.name;
divisionGenderSpan.textContent = getGenderLetter(data.gender.name);
});
sportCell.appendChild(sportSpan);
sportCell.appendChild(divisionSpan);
row.appendChild(sportCell);
const dateCell = document.createElement('td');
const yearSpan = document.createElement('span');
yearSpan.textContent = game.date.slice(0,4);
dateCell.appendChild(yearSpan);
const dateSpan = document.createElement('span');
dateSpan.textContent = game.date.slice(5);
dateCell.appendChild(dateSpan);
row.appendChild(dateCell);
}
async function addGame() {
window.location.href = "/manage/game";
}
async function editGame(id) {
window.location.href = `/manage/game?game=${id}`;
}
async function listItems() {
const gamesList = await Data.getGames();
await listGameHeaders();
gamesList.forEach(game => {
const row = document.createElement('tr');
listGame(game, row);
const manageCell = document.createElement('td');
const editSpan = document.createElement('span');
const editButton = document.createElement('button');
editButton.textContent = "E";
editButton.addEventListener('click', () => {
editGame(game.id);
});
editSpan.appendChild(editButton);
manageCell.appendChild(editSpan);
row.appendChild(manageCell);
gamesListTable.appendChild(row);
});
}
listItems();
addNewButton.addEventListener('click', () => addGame());

View File

@ -30,7 +30,8 @@ function adminLoggedIn(req, res, next) {
router.get('/' ,userLoggedIn, function(req, res, next) {
res.render('manage', { title: 'Score Management' });
if(req.user[2]) res.render('manage', { title: 'Score Management' });
else res.render('manage/manage-nonadmin', { title: "Manage Games" });
});
router.get('/game', userLoggedIn, function(req, res, next) {

View File

@ -0,0 +1,16 @@
extends layout
block stylesheets
link(rel='stylesheet', href='/stylesheets/manage.css')
link(rel='stylesheet', href='/stylesheets/form.css')
block content
div#mobile-view
h1 #{title}
div
h2#table-header
table#games-list
button#add-new-button Add new...
block scripts
script(src='/scripts/manage/manage-nonadmin.js' type="module")