Merge pull request 'add-sleep-entry-page' (#38) from add-sleep-entry-page into main
Reviewed-on: #38
This commit was merged in pull request #38.
This commit is contained in:
@@ -506,8 +506,8 @@
|
|||||||
ID: ${user.id} • Created: ${new Date(user.created_at).toLocaleDateString()}
|
ID: ${user.id} • Created: ${new Date(user.created_at).toLocaleDateString()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
class="delete-user-btn"
|
class="delete-user-btn"
|
||||||
onclick="showDeleteModal(${user.id}, '${user.username}', ${user.is_admin})"
|
onclick="showDeleteModal(${user.id}, '${user.username}', ${user.is_admin})"
|
||||||
${user.is_admin ? 'disabled title="Cannot delete admin users"' : ""}
|
${user.is_admin ? 'disabled title="Cannot delete admin users"' : ""}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -510,7 +510,7 @@
|
|||||||
</button>
|
</button>
|
||||||
`
|
`
|
||||||
: `
|
: `
|
||||||
<button class="feeding-button" onclick="showStartFeedingModal()">
|
<button class="feeding-button" onclick="window.location.href='/log-feeding.html'">
|
||||||
🍼 Started Feeding
|
🍼 Started Feeding
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
@@ -547,7 +547,7 @@
|
|||||||
// Build diaper card
|
// Build diaper card
|
||||||
const diaperCard = lastDiaperChange
|
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="icon">🧷</div>
|
||||||
<div class="type">Last Diaper</div>
|
<div class="type">Last Diaper</div>
|
||||||
<div class="time">${formatTime(lastDiaperChange.change_time)}</div>
|
<div class="time">${formatTime(lastDiaperChange.change_time)}</div>
|
||||||
@@ -556,19 +556,19 @@
|
|||||||
${lastDiaperChange.poop_amount && lastDiaperChange.pee_amount ? " • " : ""}
|
${lastDiaperChange.poop_amount && lastDiaperChange.pee_amount ? " • " : ""}
|
||||||
${lastDiaperChange.pee_amount ? `💧 ${lastDiaperChange.pee_amount}` : ""}
|
${lastDiaperChange.pee_amount ? `💧 ${lastDiaperChange.pee_amount}` : ""}
|
||||||
</div>
|
</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="icon">🧷</div>
|
||||||
<div class="type">No diaper changes yet</div>
|
<div class="type">No diaper changes yet</div>
|
||||||
</div>
|
</a>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Build feeding card
|
// Build feeding card
|
||||||
const feedingCard = lastFeeding
|
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="icon">🍼</div>
|
||||||
<div class="type">Last Feeding</div>
|
<div class="type">Last Feeding</div>
|
||||||
<div class="time">${formatTime(lastFeeding.start_time)}</div>
|
<div class="time">${formatTime(lastFeeding.start_time)}</div>
|
||||||
@@ -576,32 +576,32 @@
|
|||||||
${formatFeedingType(lastFeeding.feeding_type)}
|
${formatFeedingType(lastFeeding.feeding_type)}
|
||||||
${lastFeeding.end_time ? ` • ${calculateDuration(lastFeeding.start_time, lastFeeding.end_time)}` : " (ongoing)"}
|
${lastFeeding.end_time ? ` • ${calculateDuration(lastFeeding.start_time, lastFeeding.end_time)}` : " (ongoing)"}
|
||||||
</div>
|
</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="icon">🍼</div>
|
||||||
<div class="type">No feedings yet</div>
|
<div class="type">No feedings yet</div>
|
||||||
</div>
|
</a>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Build sleep card
|
// Build sleep card
|
||||||
const sleepCard = lastSleep
|
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="icon">😴</div>
|
||||||
<div class="type">Last Sleep</div>
|
<div class="type">Last Sleep</div>
|
||||||
<div class="time">${formatTime(lastSleep.start_time)}</div>
|
<div class="time">${formatTime(lastSleep.start_time)}</div>
|
||||||
<div class="details">
|
<div class="details">
|
||||||
${lastSleep.end_time ? calculateDuration(lastSleep.start_time, lastSleep.end_time) : "ongoing"}
|
${lastSleep.end_time ? calculateDuration(lastSleep.start_time, lastSleep.end_time) : "ongoing"}
|
||||||
</div>
|
</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="icon">😴</div>
|
||||||
<div class="type">No sleep sessions yet</div>
|
<div class="type">No sleep sessions yet</div>
|
||||||
</div>
|
</a>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
return `
|
return `
|
||||||
@@ -802,42 +802,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function showStartSleepModal() {
|
function showStartSleepModal() {
|
||||||
const modal = document.getElementById("startSleepModal");
|
window.location.href = "/log-sleep.html";
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeStartSleepModal() {
|
function closeStartSleepModal() {
|
||||||
|
|||||||
@@ -336,6 +336,29 @@
|
|||||||
lastDiaperChange.child_id;
|
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 {
|
} else {
|
||||||
showMessage("Failed to load children", "error");
|
showMessage("Failed to load children", "error");
|
||||||
|
|||||||
@@ -303,6 +303,22 @@
|
|||||||
// If editing, load the feeding data
|
// If editing, load the feeding data
|
||||||
if (isEditMode) {
|
if (isEditMode) {
|
||||||
loadFeedingData();
|
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 {
|
} else {
|
||||||
showMessage("Failed to load children", "error");
|
showMessage("Failed to load children", "error");
|
||||||
|
|||||||
@@ -390,7 +390,7 @@
|
|||||||
readonly
|
readonly
|
||||||
style="background-color: #f5f5f5; cursor: default; padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px;"
|
style="background-color: #f5f5f5; cursor: default; padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px;"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<label for="timeRangeFilter">Time Range:</label>
|
<label for="timeRangeFilter">Time Range:</label>
|
||||||
<select id="timeRangeFilter">
|
<select id="timeRangeFilter">
|
||||||
<option value="1">Last 24 hours</option>
|
<option value="1">Last 24 hours</option>
|
||||||
@@ -1104,6 +1104,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="sleep-duration">${durationText}</div>
|
<div class="sleep-duration">${durationText}</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="sleep-actions">
|
||||||
|
<button class="edit-button" onclick="window.location.href='/log-sleep.html?id=${sleep.id}'">Edit</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user