Add games list to manage page

main
sudoer777 2021-11-22 16:58:36 -07:00
parent 1f55ba3ff9
commit 54bef98312
1 changed files with 45 additions and 19 deletions

View File

@ -3,6 +3,11 @@ import * as Data from "./data.js";
const categoryDropdown = document.getElementById('category-dropdown'); const categoryDropdown = document.getElementById('category-dropdown');
const itemsListTable = document.getElementById('items-list'); const itemsListTable = document.getElementById('items-list');
function getGenderLetter(genderName) {
return genderName == "female" ? "F" : "M";
}
class Category { class Category {
constructor(name, getItems, listHeaders, listItem, addItem, submitItem, editItem) { constructor(name, getItems, listHeaders, listItem, addItem, submitItem, editItem) {
this.name = name; this.name = name;
@ -105,7 +110,7 @@ CATEGORIES.push(new Category(
row.appendChild(nameCell); row.appendChild(nameCell);
const genderCell = document.createElement('td'); const genderCell = document.createElement('td');
const gender = division.gender.name == "female" ? "F" : "M"; const gender = getGenderLetter(division.gender.name);
genderCell.textContent = gender; genderCell.textContent = gender;
row.appendChild(genderCell); row.appendChild(genderCell);
@ -183,12 +188,6 @@ CATEGORIES.push(new Category(
sportNameHeader.textContent = "Sport"; sportNameHeader.textContent = "Sport";
headerRow.appendChild(sportNameHeader); headerRow.appendChild(sportNameHeader);
const divisionNameHeader = document.createElement('th');
headerRow.appendChild(divisionNameHeader);
const divisionGenderHeader = document.createElement('th');
headerRow.appendChild(divisionGenderHeader);
const dateHeader = document.createElement('th'); const dateHeader = document.createElement('th');
dateHeader.textContent = "Date"; dateHeader.textContent = "Date";
headerRow.appendChild(dateHeader); headerRow.appendChild(dateHeader);
@ -217,9 +216,32 @@ CATEGORIES.push(new Category(
row.appendChild(scoresCell); row.appendChild(scoresCell);
const sportCell = document.createElement('td'); const sportCell = document.createElement('td');
Data.getSportName(team.sportID) const sportSpan = document.createElement('span');
.then(data => sportCell.textContent = data); 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); 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() { async function addSeason() {
// //
@ -246,22 +268,26 @@ async function listItems(category) {
category.listItem(item, row); category.listItem(item, row);
const editCell = document.createElement('td'); const manageCell = document.createElement('td');
const editButton = document.createElement('button');
editButton.textContent = "edit";
editCell.appendChild(editButton);
row.appendChild(editCell);
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'); const removeButton = document.createElement('button');
removeButton.textContent = "remove"; removeButton.textContent = "D";
removeCell.appendChild(removeButton); removeSpan.appendChild(removeButton);
row.appendChild(removeCell); manageCell.appendChild(removeSpan);
row.appendChild(manageCell);
itemsListTable.appendChild(row); itemsListTable.appendChild(row);
}); });
} }
listItems(CATEGORIES[0]); listItems(CATEGORIES[categoryDropdown.selectedIndex]);