From 0f530dc401eacf25b54ca12d3763ecd2c519bfed Mon Sep 17 00:00:00 2001 From: Kumi Date: Tue, 30 Jul 2024 13:56:30 +0200 Subject: [PATCH] feat: add serialization and deserialization for tasks Introduced methods to serialize and deserialize tasks to enable saving and loading Kanblendar state. This addition facilitates persistence and recovery of task data, ensuring continuity. Adjusted task element creation and placement to maintain task integrity during deserialization. --- kanblendar.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/kanblendar.js b/kanblendar.js index 8297cc2..e76021d 100644 --- a/kanblendar.js +++ b/kanblendar.js @@ -483,4 +483,33 @@ class Kanblendar { section.style.height = `${maxNonTimedHeight}px`; }); } + + serialize() { + const tasksArray = Array.from(this.tasks.values()).map(task => ({ + id: task.id, + title: task.title, + description: task.description, + dueTime: task.dueTime, + column: task.column, + notifyBefore: task.notifyBefore + })); + return JSON.stringify(tasksArray); + } + + deserialize(serializedData) { + const tasksArray = JSON.parse(serializedData); + tasksArray.forEach(taskData => { + const { id, title, description, dueTime, column, notifyBefore } = taskData; + const taskElement = this.createTaskElement(title, description, dueTime, column, notifyBefore); + taskElement.id = id; // Restore original ID + this.tasks.set(id, { title, description, dueTime, notifyBefore }); + this.moveTaskToColumn(taskElement, column); + if (dueTime) { + this.updateTaskLocation(taskElement, dueTime); + } else { + this.moveTaskToNonTimedSection(taskElement, column); + } + }); + this.adjustTimeSlotHeights(); + } } \ No newline at end of file