aboutsummaryrefslogtreecommitdiff
path: root/src/court.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/court.mjs')
-rw-r--r--src/court.mjs53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/court.mjs b/src/court.mjs
new file mode 100644
index 0000000..713c488
--- /dev/null
+++ b/src/court.mjs
@@ -0,0 +1,53 @@
+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", []);
+ 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();
+ this.addBehaviour();
+ }
+ 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();
+ this.addBehaviour();
+ }
+}