add-sleep-entry-page #38
@@ -506,8 +506,8 @@
|
||||
ID: ${user.id} • Created: ${new Date(user.created_at).toLocaleDateString()}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
class="delete-user-btn"
|
||||
<button
|
||||
class="delete-user-btn"
|
||||
onclick="showDeleteModal(${user.id}, '${user.username}', ${user.is_admin})"
|
||||
${user.is_admin ? 'disabled title="Cannot delete admin users"' : ""}
|
||||
>
|
||||
|
||||
@@ -510,7 +510,7 @@
|
||||
</button>
|
||||
`
|
||||
: `
|
||||
<button class="feeding-button" onclick="showStartFeedingModal()">
|
||||
<button class="feeding-button" onclick="window.location.href='/log-feeding.html'">
|
||||
🍼 Started Feeding
|
||||
</button>
|
||||
`;
|
||||
@@ -547,7 +547,7 @@
|
||||
// Build diaper card
|
||||
const diaperCard = lastDiaperChange
|
||||
? `
|
||||
<div class="activity-card">
|
||||
<a href="/diapers.html" class="activity-card" style="text-decoration:none; color:inherit;">
|
||||
<div class="icon">🧷</div>
|
||||
<div class="type">Last Diaper</div>
|
||||
<div class="time">${formatTime(lastDiaperChange.change_time)}</div>
|
||||
@@ -556,19 +556,19 @@
|
||||
${lastDiaperChange.poop_amount && lastDiaperChange.pee_amount ? " • " : ""}
|
||||
${lastDiaperChange.pee_amount ? `💧 ${lastDiaperChange.pee_amount}` : ""}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
`
|
||||
: `
|
||||
<div class="activity-card empty">
|
||||
<a href="/diapers.html" class="activity-card empty" style="text-decoration:none; color:inherit;">
|
||||
<div class="icon">🧷</div>
|
||||
<div class="type">No diaper changes yet</div>
|
||||
</div>
|
||||
</a>
|
||||
`;
|
||||
|
||||
// Build feeding card
|
||||
const feedingCard = lastFeeding
|
||||
? `
|
||||
<div class="activity-card">
|
||||
<a href="/feedings.html" class="activity-card" style="text-decoration:none; color:inherit;">
|
||||
<div class="icon">🍼</div>
|
||||
<div class="type">Last Feeding</div>
|
||||
<div class="time">${formatTime(lastFeeding.start_time)}</div>
|
||||
@@ -576,32 +576,32 @@
|
||||
${formatFeedingType(lastFeeding.feeding_type)}
|
||||
${lastFeeding.end_time ? ` • ${calculateDuration(lastFeeding.start_time, lastFeeding.end_time)}` : " (ongoing)"}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
`
|
||||
: `
|
||||
<div class="activity-card empty">
|
||||
<a href="/feedings.html" class="activity-card empty" style="text-decoration:none; color:inherit;">
|
||||
<div class="icon">🍼</div>
|
||||
<div class="type">No feedings yet</div>
|
||||
</div>
|
||||
</a>
|
||||
`;
|
||||
|
||||
// Build sleep card
|
||||
const sleepCard = lastSleep
|
||||
? `
|
||||
<div class="activity-card">
|
||||
<a href="/sleep.html" class="activity-card" style="text-decoration:none; color:inherit;">
|
||||
<div class="icon">😴</div>
|
||||
<div class="type">Last Sleep</div>
|
||||
<div class="time">${formatTime(lastSleep.start_time)}</div>
|
||||
<div class="details">
|
||||
${lastSleep.end_time ? calculateDuration(lastSleep.start_time, lastSleep.end_time) : "ongoing"}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
`
|
||||
: `
|
||||
<div class="activity-card empty">
|
||||
<a href="/sleep.html" class="activity-card empty" style="text-decoration:none; color:inherit;">
|
||||
<div class="icon">😴</div>
|
||||
<div class="type">No sleep sessions yet</div>
|
||||
</div>
|
||||
</a>
|
||||
`;
|
||||
|
||||
return `
|
||||
@@ -802,42 +802,7 @@
|
||||
}
|
||||
|
||||
function showStartSleepModal() {
|
||||
const modal = document.getElementById("startSleepModal");
|
||||
const childSelect = document.getElementById("modalSleepChildId");
|
||||
|
||||
// Clear and populate child select or show single child
|
||||
if (userChildren.length === 1) {
|
||||
// Single child: replace dropdown with text display
|
||||
const child = userChildren[0];
|
||||
const formGroup = childSelect.parentElement;
|
||||
formGroup.innerHTML = `
|
||||
<label for="modalSleepChildName">Child</label>
|
||||
<input
|
||||
type="text"
|
||||
id="modalSleepChildName"
|
||||
value="${child.name}"
|
||||
readonly
|
||||
style="background-color: #f5f5f5; cursor: default;"
|
||||
/>
|
||||
<input type="hidden" id="modalSleepChildId" value="${child.id}" />
|
||||
`;
|
||||
} else {
|
||||
// Multiple children: show dropdown
|
||||
childSelect.innerHTML = '<option value="">Select a child</option>';
|
||||
userChildren.forEach((child) => {
|
||||
const option = document.createElement("option");
|
||||
option.value = child.id;
|
||||
option.textContent = child.name;
|
||||
childSelect.appendChild(option);
|
||||
});
|
||||
|
||||
// Set default based on last sleep
|
||||
if (lastSleep) {
|
||||
childSelect.value = lastSleep.child_id;
|
||||
}
|
||||
}
|
||||
|
||||
modal.classList.add("show");
|
||||
window.location.href = "/log-sleep.html";
|
||||
}
|
||||
|
||||
function closeStartSleepModal() {
|
||||
|
||||
@@ -336,6 +336,29 @@
|
||||
lastDiaperChange.child_id;
|
||||
}
|
||||
}
|
||||
|
||||
// Prepopulate poop and pee fields from most recent entry
|
||||
try {
|
||||
const response = await fetch("/api/diaper-changes", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
if (response.ok) {
|
||||
const changes = await response.json();
|
||||
if (changes.length > 0) {
|
||||
const last = changes[0];
|
||||
document.getElementById("poopAmount").value =
|
||||
last.poop_amount || "";
|
||||
document.getElementById("poopColor").value =
|
||||
last.poop_color || "";
|
||||
document.getElementById("peeAmount").value =
|
||||
last.pee_amount || "";
|
||||
document.getElementById("peeColor").value =
|
||||
last.pee_color || "";
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Ignore error, just use default
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showMessage("Failed to load children", "error");
|
||||
|
||||
@@ -303,6 +303,22 @@
|
||||
// If editing, load the feeding data
|
||||
if (isEditMode) {
|
||||
loadFeedingData();
|
||||
} else {
|
||||
// Set default feeding type to most recent log entry
|
||||
try {
|
||||
const response = await fetch("/api/feedings", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
if (response.ok) {
|
||||
const feedings = await response.json();
|
||||
if (feedings.length > 0) {
|
||||
document.getElementById("feedingType").value =
|
||||
feedings[0].feeding_type;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Ignore error, just use default
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showMessage("Failed to load children", "error");
|
||||
|
||||
@@ -390,7 +390,7 @@
|
||||
readonly
|
||||
style="background-color: #f5f5f5; cursor: default; padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px;"
|
||||
/>
|
||||
|
||||
|
||||
<label for="timeRangeFilter">Time Range:</label>
|
||||
<select id="timeRangeFilter">
|
||||
<option value="1">Last 24 hours</option>
|
||||
@@ -1104,6 +1104,9 @@
|
||||
</div>
|
||||
<div class="sleep-duration">${durationText}</div>
|
||||
</div>
|
||||
<div class="sleep-actions">
|
||||
<button class="edit-button" onclick="window.location.href='/log-sleep.html?id=${sleep.id}'">Edit</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user