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.
This commit is contained in:
Kumi 2024-07-30 13:56:30 +02:00
parent 303258ce10
commit 0f530dc401
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -483,4 +483,33 @@ class Kanblendar {
section.style.height = `${maxNonTimedHeight}px`; 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();
}
} }