From 54bef983121f6e467a7eaf0198da0338a873a5b7 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Mon, 22 Nov 2021 16:58:36 -0700 Subject: [PATCH] Add games list to manage page --- public/scripts/manage.js | 64 ++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/public/scripts/manage.js b/public/scripts/manage.js index 83920f0..b609171 100644 --- a/public/scripts/manage.js +++ b/public/scripts/manage.js @@ -3,6 +3,11 @@ import * as Data from "./data.js"; const categoryDropdown = document.getElementById('category-dropdown'); const itemsListTable = document.getElementById('items-list'); + +function getGenderLetter(genderName) { + return genderName == "female" ? "F" : "M"; +} + class Category { constructor(name, getItems, listHeaders, listItem, addItem, submitItem, editItem) { this.name = name; @@ -105,7 +110,7 @@ CATEGORIES.push(new Category( row.appendChild(nameCell); const genderCell = document.createElement('td'); - const gender = division.gender.name == "female" ? "F" : "M"; + const gender = getGenderLetter(division.gender.name); genderCell.textContent = gender; row.appendChild(genderCell); @@ -183,12 +188,6 @@ CATEGORIES.push(new Category( sportNameHeader.textContent = "Sport"; headerRow.appendChild(sportNameHeader); - const divisionNameHeader = document.createElement('th'); - headerRow.appendChild(divisionNameHeader); - - const divisionGenderHeader = document.createElement('th'); - headerRow.appendChild(divisionGenderHeader); - const dateHeader = document.createElement('th'); dateHeader.textContent = "Date"; headerRow.appendChild(dateHeader); @@ -217,9 +216,32 @@ CATEGORIES.push(new Category( row.appendChild(scoresCell); const sportCell = document.createElement('td'); - Data.getSportName(team.sportID) - .then(data => sportCell.textContent = data); + const sportSpan = document.createElement('span'); + const divisionSpan = document.createElement('span'); + divisionSpan.classList.add('division-span'); + 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 addSeason() { // @@ -246,22 +268,26 @@ async function listItems(category) { category.listItem(item, row); - const editCell = document.createElement('td'); - const editButton = document.createElement('button'); - editButton.textContent = "edit"; - editCell.appendChild(editButton); - row.appendChild(editCell); + const manageCell = document.createElement('td'); - const removeCell = document.createElement('td'); + const editSpan = document.createElement('span'); + const editButton = document.createElement('button'); + editButton.textContent = "E"; + editSpan.appendChild(editButton); + manageCell.appendChild(editSpan); + + const removeSpan = document.createElement('remove'); const removeButton = document.createElement('button'); - removeButton.textContent = "remove"; - removeCell.appendChild(removeButton); - row.appendChild(removeCell); + removeButton.textContent = "D"; + removeSpan.appendChild(removeButton); + manageCell.appendChild(removeSpan); + + row.appendChild(manageCell); itemsListTable.appendChild(row); }); } -listItems(CATEGORIES[0]); +listItems(CATEGORIES[categoryDropdown.selectedIndex]);