aboutsummaryrefslogtreecommitdiff
path: root/src/court.mjs
diff options
context:
space:
mode:
authorKaran Jayachandra <karan.jayachandra@nxp.com>2025-11-14 15:58:36 +0100
committerKaran Jayachandra <karan.jayachandra@nxp.com>2025-11-14 15:58:36 +0100
commite4b599e57e076bef7caa8f5825bbca17540b571d (patch)
tree6c86ebeec49161bd459b7a79f7278e7e817bfc53 /src/court.mjs
parent51cf65e4d3e928a37b542acfb3de439c42907a9f (diff)
Unified the data classes
Diffstat (limited to 'src/court.mjs')
-rw-r--r--src/court.mjs41
1 files changed, 10 insertions, 31 deletions
diff --git a/src/court.mjs b/src/court.mjs
index 713c488..d85f05e 100644
--- a/src/court.mjs
+++ b/src/court.mjs
@@ -1,53 +1,32 @@
+import { Court } from "./data";
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);
- }
- toggle() {
- this.status = !this.status;
- this.print();
- }
- print() {
- let status = this.status ? "active" : "inactive";
- console.log(this.name + " is currently " + status);
- }
- render() {
- let color = this.status ? "is-success" : "is-danger";
- let type = `class="button is-medium ${color}"`;
- return `<button id=${"court_" + this.id} ${type}>${this.name}</button>`;
- }
-}
-
export class CourtManager extends Manager {
maxCourtCount = 12;
constructor() {
- super("court", []);
+ super();
console.log("Loading court data.");
- let data = JSON.parse(localStorage.getItem(this.description));
+ let tempCourt = new Court();
+ let data = JSON.parse(localStorage.getItem(tempCourt.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));
+ let id = Number(data[i].id);
+ let status = Boolean(Number(data[i].status));
+ this.data.push(new Court(id, status));
}
- console.log("Loaded " + this.listData.length + " courts.");
+ console.log("Loaded " + this.data.length + " courts.");
this.render();
- this.addBehaviour();
}
generate() {
- console.log("Generating court data.");
for (let i = 0; i < this.maxCourtCount; i++) {
- this.listData.push(new Court(i));
+ this.data.push(new Court(i, true));
}
- console.log("Generated data for " + this.listData.length + " courts");
+ console.log("Generated data for " + this.data.length + " courts");
this.store();
this.render();
- this.addBehaviour();
}
}