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; } 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"); }); } } active() { return this.listData.filter(function (c) { return c.status; }); } inactive() { return this.listData.filter(function (c) { return !c.status; }); } } 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; }