My portfolio, where I cook up projects.
A collection of games, books and resources I enjoy.
About me - what fuels my journey.
The Problem - We had to write down every repair and every correction into paper notebook.
Solution - Created a simple Repair Diary, that automatically records start and end time. It also provides the ability to add notes about what was repaired. Current code saves everything to local storage.
let repairs = JSON.parse(localStorage.getItem("repairs")) || [];
let activeRepair = null;
function formatDateTime(date) {
if (!(date instanceof Date) || isNaN(date)) return "";
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
const year = date.getFullYear();
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${day}.${month}.${year} ${hours}:${minutes}:${seconds}`;
}
function renderTable() {
const table = document.getElementById("repairTable");
table.innerHTML = "";
repairs.forEach((repair, index) => {
const row = document.createElement("tr");
const startDateTime = repair.start ? formatDateTime(new Date(repair.start)) : "";
const [startDate, startTime] = startDateTime ? startDateTime.split(" ") : ["", ""];
const endDateTime = repair.end ? formatDateTime(new Date(repair.end)) : "";
const [endDate, endTime] = endDateTime ? endDateTime.split(" ") : ["", ""];
row.innerHTML = `
${startDate}
${startTime}
${endDate ? endDate + "
" + endTime : ""}
${repair.notes || ""}
`;
table.appendChild(row);
});
}
function saveRepairs() {
localStorage.setItem("repairs", JSON.stringify(repairs));
renderTable();
}
function startRepair() {
if (activeRepair) {
alert("Finish a repair before starting another one.");
return;
}
activeRepair = {
start: new Date(),
end: null,
notes: ""
};
repairs.push(activeRepair);
saveRepairs();
renderTable();
}
function endRepair() {
if (!activeRepair) {
alert("No active repair to end.");
return;
}
activeRepair.end = new Date();
const notes = prompt("What was repaired?");
activeRepair.notes = notes?.trim() || "";
activeRepair = null;
saveRepairs();
renderTable();
}
function displayRepairInfo() {
if (activeRepair) {
const startDateTime = formatDateTime(activeRepair.start);
const [startDate, startTime] = startDateTime.split(' ');
document.getElementById('repair-start-date').textContent = startDate;
document.getElementById('repair-start-time').textContent = startTime;
}
if (activeRepair && activeRepair.end) {
const endDateTime = formatDateTime(activeRepair.end);
const [endDate, endTime] = endDateTime.split(' ');
document.getElementById('repair-end-date').textContent = endDate;
document.getElementById('repair-end-time').textContent = endTime;
}
}
function editRepair(index, field, value) {
repairs[index][field] = value;
saveRepairs();
}
function deleteRepair(index) {
if (confirm("Are you sure you want to delete this repair entry?")) {
repairs.splice(index, 1);
saveRepairs();
}
}
renderTable();
Start of Repair | End of Repair | What Was Repaired | Actions |
---|