Merge pull request 'Added edit child functionality' (#31) from add-edit-child-functionality into main
Build and Push Docker Image / build-and-push (push) Successful in 25s
Python Code Quality / python-code-quality (push) Successful in 10s
Python Test / python-test (push) Successful in 18s

Reviewed-on: #31
This commit was merged in pull request #31.
This commit is contained in:
2025-11-12 17:28:48 +01:00
2 changed files with 24 additions and 129 deletions
+2 -2
View File
@@ -313,9 +313,9 @@
: "Child added successfully!",
"success",
);
// Redirect to home page after 1 second
// Redirect to settings page if editing, otherwise home page
setTimeout(() => {
window.location.href = "/";
window.location.href = isEditMode ? "/settings.html" : "/";
}, 1000);
} else {
showMessage(
+21 -126
View File
@@ -166,16 +166,6 @@
gap: 10px;
}
.shared-badge {
display: inline-block;
background: #4caf50;
color: white;
padding: 4px 10px;
border-radius: 12px;
font-size: 12px;
font-weight: 500;
}
.loading {
text-align: center;
padding: 40px;
@@ -478,75 +468,6 @@
</div>
</div>
<!-- Edit Child Modal -->
<div
class="modal"
id="editChildModal"
style="
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
justify-content: center;
align-items: center;
"
>
<div
style="
background: white;
padding: 30px;
border-radius: 12px;
max-width: 500px;
width: 90%;
max-height: 80vh;
overflow-y: auto;
"
>
<h2 style="margin-top: 0">✏️ Edit Child</h2>
<div style="margin-bottom: 20px">
<h3 style="color: #333; margin-bottom: 10px" id="editChildName"></h3>
<div style="color: #666; font-size: 14px">
<p>
<strong>Birth Date:</strong> <span id="editChildBirthDate"></span>
</p>
<p>
<strong>Birth Weight:</strong>
<span id="editChildBirthWeight"></span>g
</p>
</div>
</div>
<div id="sharedUsersSection" style="margin-bottom: 20px; display: none">
<h3 style="color: #333; font-size: 16px; margin-bottom: 10px">
👥 Shared With
</h3>
<div
id="sharedUsersList"
style="
background: #f8f9fa;
padding: 15px;
border-radius: 8px;
color: #666;
font-size: 14px;
"
></div>
</div>
<button
type="button"
class="button"
onclick="closeEditChildModal()"
style="width: 100%"
>
Close
</button>
</div>
</div>
<script src="/menu.js"></script>
<script>
const token = localStorage.getItem("access_token");
@@ -612,17 +533,23 @@
container.innerHTML = `
<div class="children-list">
${children
.map(
(child) => `
.map((child) => {
// Get list of other users (excluding current user)
const otherUsers =
child.parent_usernames && child.parent_usernames.length > 1
? child.parent_usernames.filter(
(username) => username !== currentUser.username,
)
: [];
return `
<div class="child-card">
<div style="display: flex; align-items: center; gap: 10px;">
<h3 style="margin: 0;">👶 ${child.name}</h3>
${child.parent_count > 1 ? '<span class="shared-badge">Shared</span>' : ""}
</div>
<div class="child-info">
<p><strong>Birth Date:</strong> ${formatDate(child.birth_time)}</p>
<p><strong>Birth Weight:</strong> ${child.birth_weight}g</p>
<p><strong>Added:</strong> ${formatDate(child.created_at)}</p>
${otherUsers.length > 0 ? `<p><strong>Shared with:</strong> ${otherUsers.join(", ")}</p>` : ""}
</div>
<div class="child-actions">
<button class="button secondary" onclick="editChild(${child.id})">
@@ -633,8 +560,8 @@
</button>
</div>
</div>
`,
)
`;
})
.join("")}
</div>
`;
@@ -653,46 +580,14 @@
const child = children.find((c) => c.id === childId);
if (!child) return;
// Populate modal with child information
document.getElementById("editChildName").textContent =
`👶 ${child.name}`;
document.getElementById("editChildBirthDate").textContent = formatDate(
child.birth_time,
);
document.getElementById("editChildBirthWeight").textContent =
child.birth_weight;
// Show shared users if child is shared
const sharedSection = document.getElementById("sharedUsersSection");
const sharedList = document.getElementById("sharedUsersList");
if (child.parent_usernames && child.parent_usernames.length > 1) {
// Filter out current user and show other users
const otherUsers = child.parent_usernames.filter(
(username) => username !== currentUser.username,
);
if (otherUsers.length > 0) {
sharedSection.style.display = "block";
sharedList.innerHTML = otherUsers
.map(
(username) =>
`<div style="padding: 5px 0;">• ${username}</div>`,
)
.join("");
} else {
sharedSection.style.display = "none";
}
} else {
sharedSection.style.display = "none";
}
// Show the modal
document.getElementById("editChildModal").style.display = "flex";
}
function closeEditChildModal() {
document.getElementById("editChildModal").style.display = "none";
// Redirect to add-child page with child data in query params
const params = new URLSearchParams({
id: child.id,
name: child.name,
birth_time: child.birth_time,
birth_weight: child.birth_weight,
});
window.location.href = `/add-child.html?${params.toString()}`;
}
async function shareChild(childId) {