aboutsummaryrefslogtreecommitdiff
path: root/utils.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'utils.mjs')
-rw-r--r--utils.mjs93
1 files changed, 54 insertions, 39 deletions
diff --git a/utils.mjs b/utils.mjs
index afe200c..b21539e 100644
--- a/utils.mjs
+++ b/utils.mjs
@@ -1,47 +1,62 @@
export class Manager {
- constructor(description, listData) {
- this.description = description;
- this.listData = listData;
- this.count = listData.length;
- }
- store() {
- let stringData = JSON.stringify(this.listData);
- localStorage.setItem(this.description, stringData);
- }
- render() {
- let renderedHTML = this.listData.map((i) => {return i.render();}).join('');
- let elementId = this.description + '_list';
- document.getElementById(elementId).innerHTML = renderedHTML;
- this.addToggleBehaviour();
- }
- addToggleBehaviour() {
- for (let idx = 0; idx < this.listData.length; ++idx) {
- const elementId = this.description + "_" + this.listData[idx].id;
- const p = document.getElementById(elementId);
- p.addEventListener("click", () => {
- this.listData[idx].toggle();
- this.store();
- p.classList.toggle('is-success');
- p.classList.toggle('is-danger');
- });
- }
+ constructor(description, listData) {
+ this.description = description;
+ this.listData = listData;
+ this.count = listData.length;
+ }
+ store() {
+ let stringData = JSON.stringify(this.listData);
+ localStorage.setItem(this.description, stringData);
+ }
+ render() {
+ let renderedHTML = this.listData
+ .map((i) => {
+ return i.render();
+ })
+ .join("");
+ let elementId = this.description + "_list";
+ document.getElementById(elementId).innerHTML = renderedHTML;
+ this.addToggleBehaviour();
+ }
+ addToggleBehaviour() {
+ for (let idx = 0; idx < this.listData.length; ++idx) {
+ const elementId = this.description + "_" + this.listData[idx].id;
+ const p = document.getElementById(elementId);
+ p.addEventListener("click", () => {
+ this.listData[idx].toggle();
+ this.store();
+ p.classList.toggle("is-success");
+ p.classList.toggle("is-danger");
+ });
}
+ }
}
export function getMatchCount(regulars, courts) {
- const activeCourts = courts.filter(function (c) { return c.status });
- console.log("There are a total of " + activeCourts.length + " courts available.");
- const activePlayers = regulars.filter(function (p) { return p.status;});
- console.log("There are a total of " + activePlayers.length + " players available.");
- var possibleMatches = Math.floor(activePlayers.length / 4);
- possibleMatches = possibleMatches > activeCourts.length ? activeCourts.length : possibleMatches;
- return possibleMatches;
+ const activeCourts = courts.filter(function (c) {
+ return c.status;
+ });
+ console.log(
+ "There are a total of " + activeCourts.length + " courts available."
+ );
+ const activePlayers = regulars.filter(function (p) {
+ return p.status;
+ });
+ console.log(
+ "There are a total of " + activePlayers.length + " players available."
+ );
+ var possibleMatches = Math.floor(activePlayers.length / 4);
+ possibleMatches =
+ possibleMatches > activeCourts.length
+ ? activeCourts.length
+ : possibleMatches;
+ return possibleMatches;
}
export function shuffle(array) {
- for (let i = array.length - 1; i > 0; i--) {
- const j = Math.floor(Math.random() * (i + 1));
- [array[i], array[j]] = [array[j], array[i]];
- }
- return array;
-} \ No newline at end of file
+ for (let i = array.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1));
+ [array[i], array[j]] = [array[j], array[i]];
+ }
+ return array;
+}