aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.html12
-rw-r--r--src/data.js32
-rw-r--r--src/main.js28
-rw-r--r--src/manage.js8
-rw-r--r--src/style.css4
5 files changed, 55 insertions, 29 deletions
diff --git a/index.html b/index.html
index 0b0e641..7a47a8d 100644
--- a/index.html
+++ b/index.html
@@ -11,7 +11,7 @@
<ul><li><img src="icon.svg"></li></ul>
<ul>
<li>
- <fieldset role="group">
+ <fieldset id="timer" role="group">
<button id="timer-dec"><i class="fa-solid fa-minus"></i></button>
<input id="timer-display" type="text" readonly></input>
<button id="timer-inc"><i class="fa-solid fa-plus"></i></button>
@@ -24,8 +24,8 @@
</header>
<main class="container">
<section>
- <h1 class="title" id="Game_description"></h1>
- <div id="Game_list" class="grid-container"></div>
+ <h1 class="title" id="Game-description"></h1>
+ <div id="Game-list" class="grid-container"></div>
</section>
<section>
<fieldset role="group">
@@ -44,21 +44,21 @@
<h2>Courts</h2>
<p>Reserve courts for training or competition.</p>
</hgroup>
- <div id="Court_list" class="grid-container"></div>
+ <div id="Court-list" class="grid-container"></div>
</section>
<section>
<hgroup>
<h2>Regulars</h2>
<p>Check in and check out club members.</p>
</hgroup>
- <div id="Regular_list" class="grid-container"></div>
+ <div id="Regular-list" class="grid-container"></div>
</section>
<section>
<hgroup>
<h2>Guests</h2>
<p>Add guests to the pool.</p>
</hgroup>
- <div id="Guest_list" class="grid-container"></div>
+ <div id="Guest-list" class="grid-container"></div>
</section>
<section>
<hgroup>
diff --git a/src/data.js b/src/data.js
index 6abad81..3e133ee 100644
--- a/src/data.js
+++ b/src/data.js
@@ -1,9 +1,9 @@
class Switch {
- constructor(id, description, status) {
+ constructor(id, status) {
this.id = id;
this.status = typeof status !== "undefined" ? status : false;
- this.description = description;
- this.name = description + " " + (id + 1);
+ this.description = this.constructor.name;
+ this.name = this.description + " " + (id + 1);
}
toggle() {
this.status = !this.status;
@@ -22,18 +22,18 @@ class Switch {
export class Court extends Switch {
constructor(id, status) {
- super(id, "Court", status);
+ super(id, status);
}
}
export class Regular extends Switch {
constructor(id, status, level, games, firstName, lastName) {
- super(id, "Regular", status);
- console.log(this.constructor.name);
+ super(id, status);
this.level = typeof level !== "undefined" ? level : 1;
this.games = typeof games !== "undefined" ? games : 0;
- this.firstName = typeof firstName !== "undefined" ? firstName : this.description;
- this.lastName = typeof lastName !== "undefined" ? lastName : ( this.id + 1 );
+ this.firstName =
+ typeof firstName !== "undefined" ? firstName : this.description;
+ this.lastName = typeof lastName !== "undefined" ? lastName : this.id + 1;
this.name = this.firstName + " " + this.lastName;
}
}
@@ -49,7 +49,7 @@ export class Guest extends Switch {
categoryCount = 3;
constructor(id, status, games) {
- super(id, "Guest", status);
+ super(id, status);
const categoryId = Math.floor(id / this.maxCount) || 0;
this.level = guestCategories[categoryId].level;
this.games = typeof games !== "undefined" ? games : 0;
@@ -83,20 +83,26 @@ export class Team {
export class Game extends Switch {
constructor(id, status, teamOne, teamTwo) {
- super(id, "Game", status);
+ super(id, status);
this.teamOne = teamOne;
this.teamTwo = teamTwo;
}
print() {
- const teamOne = this.teamOne.playerOne.firstName + " and " + this.teamOne.playerTwo.firstName;
- const teamTwo = this.teamTwo.playerOne.firstName + " and " + this.teamTwo.playerTwo.firstName;
+ const teamOne =
+ this.teamOne.playerOne.firstName +
+ " and " +
+ this.teamOne.playerTwo.firstName;
+ const teamTwo =
+ this.teamTwo.playerOne.firstName +
+ " and " +
+ this.teamTwo.playerTwo.firstName;
console.log(
"Game " + this.id + ": " + teamOne + " is playing against " + teamTwo
);
}
render() {
const blockedState = this.teamOne.playerOne.firstName === "RESERVED";
- const playerState = this.teamOne.render() + "<hr>"+ this.teamTwo.render();
+ const playerState = this.teamOne.render() + "<hr>" + this.teamTwo.render();
const type = blockedState ? `<h5>Reserved</p>` : playerState;
return `<article>
<h4>Court ${this.id + 1}</h4><hr>
diff --git a/src/main.js b/src/main.js
index 6d8f35b..3732e51 100644
--- a/src/main.js
+++ b/src/main.js
@@ -19,14 +19,17 @@ export class GameManager extends Manager {
this.render();
addGameBehaviour(this);
}
- createItem(i, description) {
+ createItem(i, description, status) {
if (typeof description === "undefined") {
description = "---";
}
+ if (typeof status === "undefined") {
+ status = true;
+ }
let player = new Regular(null, null, null, null, description, "");
console.log(player);
let team = new Team(player, player);
- return new Game(i, true, team, team);
+ return new Game(i, status, team, team);
}
loadItem(data) {
let id = Number(data.id);
@@ -37,21 +40,22 @@ export class GameManager extends Manager {
}
addBehaviour() {
let confirmedStatus = this.data[0].status;
+
let description = confirmedStatus ? "Round " + this.round : "Proposal";
- document.getElementById("Game_description").innerHTML = description;
+ document.getElementById("Game-description").innerHTML = description;
}
addBlockedGames() {
const inactiveCourts = this.courts.inactive();
console.log("Total reserved courts are " + inactiveCourts.length + ".");
for (let court of inactiveCourts) {
- this.data.push(this.createItem(court.id, "RESERVED"));
+ this.data.push(this.createItem(court.id, "RESERVED", false));
}
}
addInactiveGames(possibleMatches) {
const activeCourts = this.courts.active();
const unusedCourts = activeCourts.slice(possibleMatches + 1);
for (let court of unusedCourts) {
- this.data.push(this.createItem(court.id));
+ this.data.push(this.createItem(court.id, "---", false));
}
}
addActiveGames(possibleMatches) {
@@ -92,7 +96,7 @@ export class GameManager extends Manager {
p.print();
});
const shuffledPlayers = shuffle(activePlayers);
- shuffledPlayers.sort((a, b) => a.totalPlayed - b.totalPlayed);
+ shuffledPlayers.sort((a, b) => a.games - b.games);
const selectedPlayers = shuffledPlayers.slice(0, count);
selectedPlayers.sort((a, b) => a.level - b.level);
console.log("Selected players are:");
@@ -128,6 +132,18 @@ export class GameManager extends Manager {
this.data[i].status = true;
}
// Increment the number of games played
+ let selectedPlayers = [];
+ for (let game of this.data) {
+ console.log(game);
+ if ( game.teamOne.playerOne.name !== "RESERVED" ){
+ selectedPlayers.push(game.teamOne.playerOne.name);
+ selectedPlayers.push(game.teamOne.playerTwo.name);
+ selectedPlayers.push(game.teamTwo.playerOne.name);
+ selectedPlayers.push(game.teamTwo.playerTwo.name);
+ }
+ }
+ this.regulars.incrementGames(selectedPlayers);
+ this.guests.incrementGames(selectedPlayers);
this.store();
this.render();
document.getElementById("timer-start").click();
diff --git a/src/manage.js b/src/manage.js
index f8fe220..6ed58bd 100644
--- a/src/manage.js
+++ b/src/manage.js
@@ -38,7 +38,7 @@ export class Manager {
return i.render();
})
.join("");
- let elementId = this.data[0].description + "_list";
+ let elementId = this.data[0].description + "-list";
document.getElementById(elementId).innerHTML = renderedHTML;
this.addBehaviour();
}
@@ -111,12 +111,14 @@ export class GuestManager extends Manager {
active() {
return normalize(super.active());
}
- update(list) {
+ incrementGames(list) {
for (let index = 0; index < this.data.length; index++ ){
- if (this.data[index].name in list) {
+ if (list.includes(this.data[index].name)) {
+ console.log("Added game count to " + this.data[index].name);
this.data[index].games += 1;
}
}
+ this.store();
}
}
diff --git a/src/style.css b/src/style.css
index 197597b..d6ea4de 100644
--- a/src/style.css
+++ b/src/style.css
@@ -7,7 +7,9 @@
text-align: center;
width: 100px;
}
-
+#timer {
+ margin: 0;
+}
@media (min-width: 900px) {
#Regular_list button {
height: 100px;