Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
e66e54c424 | |||
0ad4c9e398 | |||
ce86d35b25 | |||
19552bf774 | |||
b74f136f81 | |||
b52dbaec57 | |||
2769d0a33a | |||
5ac1a9f5a9 | |||
ab3378ec4d | |||
5e4ab261a7 | |||
14227f0058 | |||
ed62772643 | |||
43b74dc3c2 | |||
1643aa65d4 | |||
a44b0ecf58 | |||
0f3ff65605 | |||
32df39efb8 | |||
b85b7957c6 | |||
bee94df6e6 | |||
79cf147345 | |||
c9d50b6018 | |||
8d853a8a43 | |||
3e6d743fd4 | |||
888f8717b5 | |||
eddd739c71 | |||
7213cb4757 | |||
204e2e4dd7 | |||
11469a2865 | |||
9a4160e4e1 | |||
54c67cf5c2 | |||
c7bf411f01
|
|||
67c4981cbe
|
|||
6211ea95a4
|
|||
3cee043e28
|
|||
6fe351e110
|
|||
7429d4a4f0
|
|||
515657b1fd
|
|||
605ddc00d0
|
|||
7e00994a37
|
|||
fb1249d37b
|
|||
d9195187f3
|
|||
161aea553c
|
|||
7c3ae15c67
|
|||
d535fe3743
|
|||
56ed58b6d4
|
|||
863fcef491
|
@ -2,7 +2,7 @@ steps:
|
|||||||
build:
|
build:
|
||||||
image: plugins/kaniko
|
image: plugins/kaniko
|
||||||
settings:
|
settings:
|
||||||
repo: gitea.hottis.de/moerp/elo-rezept-rechner
|
repo: ${FORGE_NAME}/${CI_REPO}
|
||||||
registry:
|
registry:
|
||||||
from_secret: container_registry
|
from_secret: container_registry
|
||||||
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
|
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
|
||||||
@ -17,6 +17,11 @@ steps:
|
|||||||
when:
|
when:
|
||||||
- event: [push, tag]
|
- event: [push, tag]
|
||||||
|
|
||||||
|
# scan_image:
|
||||||
|
# image: aquasec/trivy
|
||||||
|
# commands:
|
||||||
|
# - trivy image $FORGE_NAME/$CI_REPO:$CI_COMMIT_SHA --quiet --exit-code 1
|
||||||
|
|
||||||
deploytest:
|
deploytest:
|
||||||
image: portainer/kubectl-shell:latest
|
image: portainer/kubectl-shell:latest
|
||||||
secrets:
|
secrets:
|
||||||
|
@ -10,7 +10,8 @@ COPY start.sh ${APP_DIR}/
|
|||||||
WORKDIR ${APP_DIR}
|
WORKDIR ${APP_DIR}
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
apk add --no-cache build-base libpq-dev && \
|
apk add --no-cache build-base libpq-dev npm && \
|
||||||
|
pip install --upgrade pip && \
|
||||||
pip install -r requirements.txt && \
|
pip install -r requirements.txt && \
|
||||||
if [ "${VERSION_ID2}" != "" ]; then VERSION_ID=${VERSION_ID2}; else VERSION_ID=${VERSION_ID1}; fi && \
|
if [ "${VERSION_ID2}" != "" ]; then VERSION_ID=${VERSION_ID2}; else VERSION_ID=${VERSION_ID1}; fi && \
|
||||||
sed -i -e 's/VERSION_ID/'$VERSION_ID'/' ${APP_DIR}/templates/index.html && \
|
sed -i -e 's/VERSION_ID/'$VERSION_ID'/' ${APP_DIR}/templates/index.html && \
|
||||||
|
@ -36,7 +36,7 @@ kubectl create secret generic nutri-secrets \
|
|||||||
--from-literal=CLIENT_SECRETS="$CLIENT_SECRETS" \
|
--from-literal=CLIENT_SECRETS="$CLIENT_SECRETS" \
|
||||||
--from-literal=PGUSER="$PGUSER" \
|
--from-literal=PGUSER="$PGUSER" \
|
||||||
--from-literal=PGPASSWORD="$PGPASSWORD" \
|
--from-literal=PGPASSWORD="$PGPASSWORD" \
|
||||||
--from-literal=PGDATABASE="$PGDATABASE" \
|
--from-literal=PGDATABASE="$PGDATABASE$POSTFIX" \
|
||||||
--from-literal=PGHOST="timescaledb.database.svc.cluster.local" \
|
--from-literal=PGHOST="timescaledb.database.svc.cluster.local" \
|
||||||
--from-literal=PGSSLMODE="require" | \
|
--from-literal=PGSSLMODE="require" | \
|
||||||
kubectl apply -f - -n $NAMESPACE
|
kubectl apply -f - -n $NAMESPACE
|
||||||
|
28
src/Run.py
28
src/Run.py
@ -6,6 +6,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import logging
|
import logging
|
||||||
|
from math import ceil, floor
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.update({
|
app.config.update({
|
||||||
@ -21,6 +22,8 @@ app.config.update({
|
|||||||
oidc = OpenIDConnect(app)
|
oidc = OpenIDConnect(app)
|
||||||
app.logger.handlers = logging.getLogger('gunicorn.error').handlers
|
app.logger.handlers = logging.getLogger('gunicorn.error').handlers
|
||||||
|
|
||||||
|
datapw = 'dasrtwegdffgtewrt4335wferg'
|
||||||
|
|
||||||
def calculate_nutrition(food, weight):
|
def calculate_nutrition(food, weight):
|
||||||
try:
|
try:
|
||||||
conn = psycopg2.connect()
|
conn = psycopg2.connect()
|
||||||
@ -35,12 +38,12 @@ def calculate_nutrition(food, weight):
|
|||||||
# Runden und Berechnen der Nährwerte basierend auf dem Gewicht
|
# Runden und Berechnen der Nährwerte basierend auf dem Gewicht
|
||||||
kcal, ew, fett, kh, bst, ca = result
|
kcal, ew, fett, kh, bst, ca = result
|
||||||
nutrition_values = [
|
nutrition_values = [
|
||||||
round(kcal * weight / 100), # kcal gerundet auf ganze Zahl
|
schulrunden(kcal * weight / 100), # kcal gerundet auf ganze Zahl
|
||||||
round(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle
|
schulrunden(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle
|
||||||
round(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle
|
schulrunden(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle
|
||||||
round(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle
|
schulrunden(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle
|
||||||
round(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle
|
schulrunden(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle
|
||||||
round(ca * weight / 100) # CA gerundet auf ganze Zahl
|
schulrunden(ca * weight / 100) # CA gerundet auf ganze Zahl
|
||||||
]
|
]
|
||||||
return nutrition_values
|
return nutrition_values
|
||||||
else:
|
else:
|
||||||
@ -51,6 +54,19 @@ def calculate_nutrition(food, weight):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def schulrunden(zahl, stellen=0):
|
||||||
|
faktor = 10 ** stellen
|
||||||
|
zahl = zahl * faktor
|
||||||
|
basis = floor(zahl)
|
||||||
|
if zahl - basis >= 0.5:
|
||||||
|
gerundet = basis + 1
|
||||||
|
else:
|
||||||
|
gerundet = basis
|
||||||
|
return gerundet / faktor
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Index-Route
|
# Index-Route
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@oidc.require_login
|
@oidc.require_login
|
||||||
|
@ -231,4 +231,13 @@ button#cancel-button:disabled {
|
|||||||
|
|
||||||
button#cancel-button:not(:disabled):hover {
|
button#cancel-button:not(:disabled):hover {
|
||||||
background-color: #490000; /* Dunkleres Rot */
|
background-color: #490000; /* Dunkleres Rot */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-layout {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-row {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
cleanUpLocalStorage();
|
cleanUpLocalStorage();
|
||||||
|
restorePortions()
|
||||||
restoreTableFromLocalStorage();
|
restoreTableFromLocalStorage();
|
||||||
|
|
||||||
updateTotalNutrition();
|
updateTotalNutrition();
|
||||||
fetch('/get_products')
|
fetch('/get_products')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
@ -32,6 +34,65 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('portions').addEventListener('input', function() {
|
||||||
|
const portions = this.value;
|
||||||
|
localStorage.setItem('savedPortions', portions); // Speichern der Portionen im localStorage
|
||||||
|
recalculateTableBasedOnPortions(); // Bestehende Funktion, um die Tabelle zu aktualisieren
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function restorePortions() {
|
||||||
|
const savedPortions = localStorage.getItem('savedPortions');
|
||||||
|
if (savedPortions) {
|
||||||
|
document.getElementById('portions').value = savedPortions;
|
||||||
|
recalculateTableBasedOnPortions(); // Falls notwendig, um die Tabelle direkt zu aktualisieren
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function recalculateTableBasedOnPortions() {
|
||||||
|
const portions = parseInt(document.getElementById('portions').value, 10) || 1;
|
||||||
|
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
|
||||||
|
entries.forEach((entry, index) => {
|
||||||
|
const newWeight = Math.ceil(entry.weight / portions);
|
||||||
|
// Da die Server-Anfrage möglicherweise nicht sofort antwortet, passen wir den Index an, um die korrekte Zeile zu aktualisieren.
|
||||||
|
fetchUpdatedNutrition(entry.food, newWeight, index + 1); // +1, um den Kopfzeilenindex zu überspringen
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchUpdatedNutrition(food, weight, rowIndex) {
|
||||||
|
fetch(`/add_lm?food=${encodeURIComponent(food)}&weight=${encodeURIComponent(weight)}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
// Direktes Aktualisieren der Zeile mit den neuen Daten
|
||||||
|
const table = document.getElementById('nutrition-table');
|
||||||
|
if (table.rows[rowIndex]) {
|
||||||
|
updateRowWithNewData(table.rows[rowIndex], weight, data);
|
||||||
|
}
|
||||||
|
updateTotalNutrition(); // Aktualisiert die Gesamtnährwerte
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Fehler:', error);
|
||||||
|
// Behandlung spezifischer Fehler, z.B. Zurücksetzen der Werte oder Anzeigen einer Fehlermeldung
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateRowWithNewData(row, weight, nutritionData) {
|
||||||
|
if (nutritionData && row.cells.length > 7) {
|
||||||
|
row.cells[1].innerText = weight; // Aktualisiere Gewicht
|
||||||
|
row.cells[2].innerText = nutritionData.kcal;
|
||||||
|
row.cells[3].innerText = nutritionData.ew;
|
||||||
|
row.cells[4].innerText = nutritionData.fett;
|
||||||
|
row.cells[5].innerText = nutritionData.kh;
|
||||||
|
row.cells[6].innerText = nutritionData.bst;
|
||||||
|
row.cells[7].innerText = nutritionData.ca;
|
||||||
|
} else {
|
||||||
|
// Fehlerbehandlung, falls die Datenstruktur nicht wie erwartet ist
|
||||||
|
console.error('Unvollständige Daten erhalten: ', nutritionData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
@ -49,14 +110,14 @@
|
|||||||
const table = document.getElementById('nutrition-table');
|
const table = document.getElementById('nutrition-table');
|
||||||
const row = table.insertRow();
|
const row = table.insertRow();
|
||||||
|
|
||||||
row.insertCell(0).innerHTML = food;
|
row.insertCell(0).innerText = food;
|
||||||
row.insertCell(1).innerHTML = weight;
|
row.insertCell(1).innerText = weight;
|
||||||
row.insertCell(2).innerHTML = nutritionData.kcal;
|
row.insertCell(2).innerText = nutritionData.kcal;
|
||||||
row.insertCell(3).innerHTML = nutritionData.ew;
|
row.insertCell(3).innerText = nutritionData.ew;
|
||||||
row.insertCell(4).innerHTML = nutritionData.fett;
|
row.insertCell(4).innerText = nutritionData.fett;
|
||||||
row.insertCell(5).innerHTML = nutritionData.kh;
|
row.insertCell(5).innerText = nutritionData.kh;
|
||||||
row.insertCell(6).innerHTML = nutritionData.bst;
|
row.insertCell(6).innerText = nutritionData.bst;
|
||||||
row.insertCell(7).innerHTML = nutritionData.ca;
|
row.insertCell(7).innerText = nutritionData.ca;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -94,10 +155,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
localStorage.setItem('nutritionEntries', JSON.stringify(entries));
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function updateRemoveButtonState() {
|
function updateRemoveButtonState() {
|
||||||
const selectedRows = document.querySelectorAll('#nutrition-table .selected').length;
|
const selectedRows = document.querySelectorAll('#nutrition-table .selected').length;
|
||||||
@ -111,11 +176,18 @@
|
|||||||
document.getElementById('submit-button').disabled = !(food && weight);
|
document.getElementById('submit-button').disabled = !(food && weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function addProduct() {
|
function addProduct() {
|
||||||
const foodInput = document.getElementById('my_combobox');
|
const foodInput = document.getElementById('my_combobox');
|
||||||
const weightInput = document.getElementById('weight');
|
const weightInput = document.getElementById('weight');
|
||||||
|
const portionsInput = document.getElementById('portions');
|
||||||
const food = foodInput.value;
|
const food = foodInput.value;
|
||||||
const weight = weightInput.value;
|
let weight = parseFloat(weightInput.value);
|
||||||
|
const portions = portionsInput.value ? parseInt(portionsInput.value, 10) : 1;
|
||||||
|
|
||||||
|
// Teilen des Gewichts durch die Anzahl der Portionen und Aufrunden
|
||||||
|
weight = Math.ceil(weight / portions);
|
||||||
|
|
||||||
|
|
||||||
fetch(`/add_lm?food=${encodeURIComponent(food)}&weight=${encodeURIComponent(weight)}`)
|
fetch(`/add_lm?food=${encodeURIComponent(food)}&weight=${encodeURIComponent(weight)}`)
|
||||||
@ -124,14 +196,14 @@
|
|||||||
const table = document.getElementById('nutrition-table');
|
const table = document.getElementById('nutrition-table');
|
||||||
const row = table.insertRow();
|
const row = table.insertRow();
|
||||||
// Fügt die einzelnen Nährwerte zur neuen Zeile hinzu
|
// Fügt die einzelnen Nährwerte zur neuen Zeile hinzu
|
||||||
row.insertCell(0).innerHTML = food;
|
row.insertCell(0).innerText = food;
|
||||||
row.insertCell(1).innerHTML = weight;
|
row.insertCell(1).innerText = weight;
|
||||||
row.insertCell(2).innerHTML = data.kcal;
|
row.insertCell(2).innerText = data.kcal;
|
||||||
row.insertCell(3).innerHTML = data.ew;
|
row.insertCell(3).innerText = data.ew;
|
||||||
row.insertCell(4).innerHTML = data.fett;
|
row.insertCell(4).innerText = data.fett;
|
||||||
row.insertCell(5).innerHTML = data.kh;
|
row.insertCell(5).innerText = data.kh;
|
||||||
row.insertCell(6).innerHTML = data.bst;
|
row.insertCell(6).innerText = data.bst;
|
||||||
row.insertCell(7).innerHTML = data.ca;
|
row.insertCell(7).innerText = data.ca;
|
||||||
|
|
||||||
foodInput.value = ''; // Zurücksetzen des Lebensmittel-Eingabefeldes
|
foodInput.value = ''; // Zurücksetzen des Lebensmittel-Eingabefeldes
|
||||||
weightInput.value = ''; // Zurücksetzen des Gewicht-Eingabefeldes
|
weightInput.value = ''; // Zurücksetzen des Gewicht-Eingabefeldes
|
||||||
@ -187,15 +259,22 @@ function updateTotalNutrition() {
|
|||||||
|
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<form onsubmit="event.preventDefault(); addProduct();" id="product-form">
|
<form onsubmit="event.preventDefault(); addProduct();" id="product-form" class="form-layout">
|
||||||
<label for="my_combobox">Wählen Sie ein Lebensmittel</label>
|
<div class="form-row">
|
||||||
<input list="products" name="my_combobox" id="my_combobox" placeholder="Lebensmittel" oninput="updateButtonState()" autocomplete="off">
|
<label for="portions">Wählen Sie die Anzahl an Portionen</label>
|
||||||
<datalist id="products">
|
<input type="number" id="portions" name="portions" placeholder="Portionen" min="1" value="1" oninput="recalculateTableBasedOnPortions()">
|
||||||
<!-- Produkte werden hier dynamisch eingefügt -->
|
</div>
|
||||||
</datalist>
|
<div class="form-row">
|
||||||
<input type="number" id="weight" name="weight" placeholder="Gramm" oninput="updateButtonState()">
|
<label for="my_combobox">Wählen Sie ein Lebensmittel</label>
|
||||||
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
<input list="products" name="my_combobox" id="my_combobox" placeholder="Lebensmittel" oninput="updateButtonState()" autocomplete="off">
|
||||||
|
<datalist id="products">
|
||||||
|
<!-- Produkte werden hier dynamisch eingefügt -->
|
||||||
|
</datalist>
|
||||||
|
<input type="number" id="weight" name="weight" placeholder="Gramm" oninput="updateButtonState()">
|
||||||
|
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
<table id="nutrition-table">
|
<table id="nutrition-table">
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
<link rel="shortcut icon" href="../static/images/favicon.ico">
|
<link rel="shortcut icon" href="../static/images/favicon.ico">
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
let isEditing = false;
|
||||||
|
|
||||||
function updateSubmitButtonState() {
|
function updateSubmitButtonState() {
|
||||||
const inputs = document.querySelectorAll('#nutrition-form input');
|
const inputs = document.querySelectorAll('#nutrition-form input');
|
||||||
const allFilled = Array.from(inputs).every(input => input.value.trim() !== '');
|
const allFilled = Array.from(inputs).every(input => input.value.trim() !== '');
|
||||||
@ -57,15 +59,95 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function showPasswordPrompt(action) {
|
||||||
|
// Setze isEditing je nach Aktion
|
||||||
|
isEditing = (action === 'edit');
|
||||||
|
if (isEditing) {
|
||||||
|
// Deaktiviere Zeilenauswahl
|
||||||
|
document.getElementById('database-nutrition-table').removeEventListener('click', handleRowClick);
|
||||||
|
} else {
|
||||||
|
// Aktiviere Zeilenauswahl
|
||||||
|
document.getElementById('database-nutrition-table').addEventListener('click', handleRowClick);
|
||||||
|
}
|
||||||
|
document.getElementById('delete-row-button').style.display = action === 'edit' ? 'none' : 'block';
|
||||||
|
document.getElementById('edit-row-button').style.display = action === 'delete' ? 'none' : 'block';
|
||||||
|
document.getElementById('password-prompt').style.display = 'block';
|
||||||
|
document.getElementById('password-prompt').setAttribute('data-action', action);
|
||||||
|
// Deselektiere alle Zeilen
|
||||||
|
deselectAllRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deselectAllRows() {
|
||||||
|
document.querySelectorAll('#database-nutrition-table .selected').forEach(row => {
|
||||||
|
row.classList.remove('selected');
|
||||||
|
});
|
||||||
|
updateDeleteButtonState();
|
||||||
|
updateEditButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
function hidePasswordPrompt() {
|
||||||
|
document.getElementById('delete-row-button').style.display = 'block';
|
||||||
|
document.getElementById('edit-row-button').style.display = 'block';
|
||||||
|
document.getElementById('password-prompt').style.display = 'none';
|
||||||
|
// Setze isEditing zurück
|
||||||
|
isEditing = false;
|
||||||
|
// Deaktiviere Editierbarkeit aller Zellen und aktiviere Zeilenauswahl
|
||||||
|
setCellsEditable(false);
|
||||||
|
document.getElementById('database-nutrition-table').addEventListener('click', handleRowClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
function performActionIfPasswordCorrect() {
|
||||||
|
const password = document.getElementById('password-input').value;
|
||||||
|
if (password === 'geheim') {
|
||||||
|
const action = document.getElementById('password-prompt').getAttribute('data-action');
|
||||||
|
if (action === 'delete') {
|
||||||
|
deleteSelectedRows();
|
||||||
|
} else if (action === 'edit') {
|
||||||
|
// Mache Zellen editierbar
|
||||||
|
setCellsEditable(true);
|
||||||
|
hidePasswordPrompt();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert('Falsches Passwort!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCellsEditable(editable) {
|
||||||
|
document.querySelectorAll('#database-nutrition-table td').forEach(cell => {
|
||||||
|
cell.contentEditable = editable;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleRowClick(event) {
|
||||||
|
if (event.target.tagName === 'TD' && !isEditing) {
|
||||||
|
event.target.parentNode.classList.toggle('selected');
|
||||||
|
updateDeleteButtonState();
|
||||||
|
updateEditButtonState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateEditButtonState() {
|
||||||
|
// Diese Funktion soll ähnlich wie updateDeleteButtonState() implementiert werden,
|
||||||
|
// um den "Bearbeiten"-Button zu aktivieren/deaktivieren
|
||||||
|
const selectedRows = document.querySelectorAll('#database-nutrition-table .selected').length;
|
||||||
|
const editButton = document.getElementById('edit-row-button');
|
||||||
|
editButton.disabled = selectedRows === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Ergänze Event-Listener, um den Zustand des Bearbeiten-Buttons zu aktualisieren
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
document.getElementById('database-nutrition-table').addEventListener('click', handleRowClick);
|
||||||
const table = document.getElementById('database-nutrition-table');
|
const table = document.getElementById('database-nutrition-table');
|
||||||
table.addEventListener('click', function(e) {
|
table.addEventListener('click', function(e) {
|
||||||
if (e.target.tagName === 'TD') {
|
if (e.target.tagName === 'TD') {
|
||||||
e.target.parentNode.classList.toggle('selected');
|
e.target.parentNode.classList.toggle('selected');
|
||||||
updateDeleteButtonState();
|
updateDeleteButtonState();
|
||||||
|
updateEditButtonState();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateDeleteButtonState();
|
updateDeleteButtonState();
|
||||||
|
updateEditButtonState();
|
||||||
});
|
});
|
||||||
|
|
||||||
function deleteSelectedRows() {
|
function deleteSelectedRows() {
|
||||||
@ -98,15 +180,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function showPasswordPrompt() {
|
// function showPasswordPrompt() {
|
||||||
document.getElementById('delete-row-button').style.display = 'none';
|
// document.getElementById('delete-row-button').style.display = 'none';
|
||||||
document.getElementById('password-prompt').style.display = 'block';
|
// document.getElementById('password-prompt').style.display = 'block';
|
||||||
}
|
// }
|
||||||
|
|
||||||
function hidePasswordPrompt() {
|
// function hidePasswordPrompt() {
|
||||||
document.getElementById('delete-row-button').style.display = 'block';
|
// document.getElementById('delete-row-button').style.display = 'block';
|
||||||
document.getElementById('password-prompt').style.display = 'none';
|
// document.getElementById('password-prompt').style.display = 'none';
|
||||||
}
|
// }
|
||||||
|
|
||||||
function deleteRowsIfPasswordCorrect() {
|
function deleteRowsIfPasswordCorrect() {
|
||||||
const password = document.getElementById('password-input').value;
|
const password = document.getElementById('password-input').value;
|
||||||
@ -137,13 +219,13 @@
|
|||||||
tableBody.innerHTML = '';
|
tableBody.innerHTML = '';
|
||||||
data.forEach(entry => {
|
data.forEach(entry => {
|
||||||
const row = tableBody.insertRow();
|
const row = tableBody.insertRow();
|
||||||
row.insertCell(0).innerHTML = entry.food;
|
row.insertCell(0).innerText = entry.food;
|
||||||
row.insertCell(1).innerHTML = entry.kcal;
|
row.insertCell(1).innerText = entry.kcal;
|
||||||
row.insertCell(2).innerHTML = entry.ew;
|
row.insertCell(2).innerText = entry.ew;
|
||||||
row.insertCell(3).innerHTML = entry.fett;
|
row.insertCell(3).innerText = entry.fett;
|
||||||
row.insertCell(4).innerHTML = entry.kh;
|
row.insertCell(4).innerText = entry.kh;
|
||||||
row.insertCell(5).innerHTML = entry.bst;
|
row.insertCell(5).innerText = entry.bst;
|
||||||
row.insertCell(6).innerHTML = entry.ca;
|
row.insertCell(6).innerText = entry.ca;
|
||||||
|
|
||||||
// ... Fügen Sie weitere Zellen für die anderen Werte hinzu ...
|
// ... Fügen Sie weitere Zellen für die anderen Werte hinzu ...
|
||||||
});
|
});
|
||||||
@ -236,11 +318,12 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<button id="delete-row-button" onclick="showPasswordPrompt()">Zeilen löschen</button>
|
<button id="delete-row-button" onclick="showPasswordPrompt('delete')">Zeilen löschen</button>
|
||||||
|
<button id="edit-row-button" onclick="showPasswordPrompt('edit')">Bearbeiten</button>
|
||||||
|
|
||||||
<div id="password-prompt" style="display: none;">
|
<div id="password-prompt" style="display: none;">
|
||||||
<input type="password" id="password-input" placeholder="Passwort">
|
<input type="password" id="password-input" placeholder="Passwort">
|
||||||
<button id="ok-button" onclick="deleteRowsIfPasswordCorrect()">OK</button>
|
<button id="ok-button" onclick="performActionIfPasswordCorrect()">OK</button>
|
||||||
<button id="cancel-button" onclick="hidePasswordPrompt()">Abbrechen</button>
|
<button id="cancel-button" onclick="hidePasswordPrompt()">Abbrechen</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user