bug
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2024-04-04 13:14:04 +02:00
parent 0f3ff65605
commit a44b0ecf58

View File

@ -118,42 +118,33 @@ function updateRowWithNewData(row, weight, nutritionData) {
function removeSelectedRow() { function removeSelectedRow() {
const table = document.getElementById('nutrition-table'); const table = document.getElementById('nutrition-table');
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
// Durchgehen aller Zeilen, um zu prüfen, ob sie ausgewählt sind
Array.from(table.rows).forEach(row => { Array.from(table.rows).forEach(row => {
if (row.classList.contains('selected')) { if (row.classList.contains('selected')) {
// Annahme: Jede Zeile hat ein data-id Attribut, das dem Index im entries Array entspricht let rowData = {
const entryIndex = row.getAttribute('data-id'); food: row.cells[0].innerText,
weight: row.cells[1].innerText,
// Weitere Daten bei Bedarf
};
// Entfernen des Eintrags aus dem Array, falls vorhanden // Entfernen des Eintrags aus dem lokalen Speicher
if (entryIndex !== null) { removeEntryFromLocalStorage(rowData);
entries.splice(entryIndex, 1);
// Notwendig, um die IDs zu aktualisieren, da das Array jetzt kürzer ist
updateDataIds();
}
// Visuelles Entfernen der Zeile aus der Tabelle table.deleteRow(row.rowIndex);
row.parentNode.removeChild(row);
} }
}); });
updateRemoveButtonState();
// Aktualisieren des localStorage mit dem neuen Array ohne den entfernten Eintrag updateTotalNutrition();
localStorage.setItem('nutritionEntries', JSON.stringify(entries));
// Funktion, um die data-id Attribute der verbleibenden Zeilen zu aktualisieren
function updateDataIds() {
Array.from(table.rows).slice(1).forEach((row, index) => {
row.setAttribute('data-id', index.toString());
});
} }
}
function removeEntryFromLocalStorage(rowData) { function removeEntryFromLocalStorage(rowData) {
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || []; let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
entries = entries.filter(entry => entry.food !== rowData.food || entry.weight !== rowData.weight); // Konvertieren von rowData.weight in eine Zahl, um eine korrekte Vergleichsbasis zu schaffen
const weightToCompare = parseFloat(rowData.weight);
// Verwendung einer strikten Gleichheitsprüfung für beide Werte
entries = entries.filter(entry => entry.food !== rowData.food || parseFloat(entry.weight) !== weightToCompare);
localStorage.setItem('nutritionEntries', JSON.stringify(entries)); localStorage.setItem('nutritionEntries', JSON.stringify(entries));
} }
function updateRemoveButtonState() { function updateRemoveButtonState() {
const selectedRows = document.querySelectorAll('#nutrition-table .selected').length; const selectedRows = document.querySelectorAll('#nutrition-table .selected').length;