change table
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
moerp 2024-04-04 12:41:41 +02:00
parent c9d50b6018
commit 79cf147345

View File

@ -32,6 +32,24 @@
}); });
}); });
function recalculateTableBasedOnPortions() {
const portions = parseInt(document.getElementById('portions').value, 10) || 1;
const table = document.getElementById('nutrition-table');
Array.from(table.rows).slice(1).forEach(row => {
const weightCell = row.cells[1];
const originalWeight = parseInt(weightCell.getAttribute('data-original-weight'), 10) || parseInt(weightCell.innerText, 10);
const newWeight = Math.ceil(originalWeight / portions);
weightCell.innerText = newWeight;
// Optional: Speichern des ursprünglichen Gewichts, falls noch nicht geschehen
if (!weightCell.hasAttribute('data-original-weight')) {
weightCell.setAttribute('data-original-weight', originalWeight.toString());
}
});
// Trigger die Neuberechnung der Gesamtnährwerte
updateTotalNutrition();
}
function restoreTableFromLocalStorage() { function restoreTableFromLocalStorage() {
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || []; let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
let oneHourAgo = new Date().getTime() - (60 * 60 * 1000); let oneHourAgo = new Date().getTime() - (60 * 60 * 1000);
@ -194,6 +212,7 @@ function updateTotalNutrition() {
<div class="content"> <div class="content">
<form onsubmit="event.preventDefault(); addProduct();" id="product-form"> <form onsubmit="event.preventDefault(); addProduct();" id="product-form">
<input type="number" id="portions" name="portions" placeholder="Portionen" min="1" value="1" oninput="recalculateTableBasedOnPortions()">
<label for="my_combobox">Wählen Sie ein Lebensmittel</label> <label for="my_combobox">Wählen Sie ein Lebensmittel</label>
<input list="products" name="my_combobox" id="my_combobox" placeholder="Lebensmittel" oninput="updateButtonState()" autocomplete="off"> <input list="products" name="my_combobox" id="my_combobox" placeholder="Lebensmittel" oninput="updateButtonState()" autocomplete="off">
<datalist id="products"> <datalist id="products">
@ -202,7 +221,7 @@ function updateTotalNutrition() {
<input type="number" id="weight" name="weight" placeholder="Gramm" oninput="updateButtonState()"> <input type="number" id="weight" name="weight" placeholder="Gramm" oninput="updateButtonState()">
<button type="submit" id="submit-button" disabled>Hinzufügen</button> <button type="submit" id="submit-button" disabled>Hinzufügen</button>
<input type="number" id="portions" name="portions" placeholder="Portionen" min="1" value="1">
</form> </form>