aboutsummaryrefslogtreecommitdiff
path: root/court.mjs
diff options
context:
space:
mode:
authorKaran Jayachandra <karan.jayachandra@nxp.com>2025-11-12 14:18:36 +0100
committerKaran Jayachandra <karan.jayachandra@nxp.com>2025-11-12 14:18:36 +0100
commit3a4a0f6f2bf9aff14c00c6acee637319d7458bbb (patch)
tree8f136ad7fcaad95d7b3028138ed092a07ed10162 /court.mjs
parentca3e550fb59af89a2ddc0e1e0e59a3025edbece7 (diff)
Memory added
Diffstat (limited to 'court.mjs')
-rw-r--r--court.mjs42
1 files changed, 32 insertions, 10 deletions
diff --git a/court.mjs b/court.mjs
index e252cb5..cb895f0 100644
--- a/court.mjs
+++ b/court.mjs
@@ -1,8 +1,10 @@
-export class Court {
- constructor(id) {
+import { Manager } from "./utils.mjs";
+
+class Court {
+ constructor(id, status) {
this.id = id;
+ this.status = typeof status !== 'undefined' ? status : true;
this.name = "Court " + (id + 1);
- this.status = true;
}
toggle() {
this.status = !this.status;
@@ -13,16 +15,36 @@ export class Court {
console.log(this.name + " is currently " + status);
}
render() {
- let type = this.status ? `class="button is-medium is-success"` : 'class="button is-medium is-dark"';
+ let type = this.status ? `class="button is-success"` : 'class="button is-danger"';
return `<button id=${"court_" + this.id} ${type}>${this.name}</button>`;
}
}
-export function generateCourts() {
- let courts = [];
- const totalCourts = 12;
- for (let i = 0; i < totalCourts; i++) {
- courts.push(new Court(i));
+export class CourtManager extends Manager {
+ maxCourtCount = 12;
+
+ constructor() {
+ super("court", []);
+ console.log("Loading court data.");
+ let data = JSON.parse(localStorage.getItem(this.description));
+ if (data === null || data.length != this.maxCourtCount) {
+ console.log("Court data unavailable: " + data);
+ this.generate();
+ return;
+ }
+ for (let i = 0; i < this.maxCourtCount; i++) {
+ this.listData.push(new Court(data[i].id, data[i].status));
+ }
+ console.log("Loaded " + this.listData.length + " courts.");
+ this.render();
+ }
+ generate() {
+ console.log("Generating court data.");
+ for (let i = 0; i < this.maxCourtCount; i++) {
+ this.listData.push(new Court(i));
+ }
+ console.log("Generated data for " + this.listData.length + " courts");
+ this.store();
+ this.render();
}
- return courts;
} \ No newline at end of file