diff --git a/src/Run.py b/src/Run.py index 260b8fe..06c1c15 100644 --- a/src/Run.py +++ b/src/Run.py @@ -140,6 +140,34 @@ def get_token(): return jsonify(token=oidc.get_access_token()) +@app.route('/get_database_entries') +def get_database_entries(): + try: + # Ersetzen Sie diese Werte mit Ihren Datenbank-Verbindungsinformationen + conn = psycopg2.connect() + cursor = conn.cursor() + with conn.cursor() as cursor: + cursor.execute("SELECT name, kcal, ew, fett, kh, bst, ca FROM nutrition_table") + entries = cursor.fetchall() + + # Umwandeln der Daten in ein JSON-freundliches Format + entries_list = [] + for entry in entries: + entries_list.append({ + "food": entry[0], + "kcal": entry[1], + "ew": entry[2], + "fett": entry[3], + "kh": entry[4], + "bst": entry[5], + "ca": entry[6] + }) + return jsonify(entries_list) + except Exception as e: + return jsonify({"error": str(e)}), 500 + finally: + if conn: + conn.close() app = ProxyFix(app, x_for=1, x_host=1) diff --git a/src/static/style.css b/src/static/style.css index 3c1c3e7..f1b7707 100644 --- a/src/static/style.css +++ b/src/static/style.css @@ -152,3 +152,25 @@ tr:hover:not(.selected) { overflow-x: auto; /* Ermöglicht horizontales Scrollen auf kleinen Bildschirmen */ } } + +#table-container { + overflow-y: auto; + max-height: 400px; /* Passen Sie die Höhe nach Bedarf an */ + border-radius: 10px; + margin-top: 20px; +} + +#database-nutrition-table { + width: 100%; + border-collapse: collapse; +} + +#database-nutrition-table th, #database-nutrition-table td { + border: 1px solid #ddd; + padding: 8px; + text-align: left; +} + +#database-nutrition-table tr.selected { + background-color: #f0e68c; +} diff --git a/src/templates/nutrition.html b/src/templates/nutrition.html index b5793ea..4a61f45 100644 --- a/src/templates/nutrition.html +++ b/src/templates/nutrition.html @@ -55,6 +55,44 @@ }); } + + document.addEventListener('DOMContentLoaded', function() { + const table = document.getElementById('database-nutrition-table'); + table.addEventListener('click', function(e) { + if (e.target.tagName === 'TD') { + e.target.parentNode.classList.toggle('selected'); + } + }); + }); + + function deleteSelectedRows() { + const table = document.getElementById('database-nutrition-table'); + Array.from(table.rows).forEach(row => { + if (row.classList.contains('selected')) { + // Logik zum Löschen der Zeile aus der Datenbank + table.deleteRow(row.rowIndex); + } + }); + } + + function loadDatabaseEntries() { + fetch('/get_database_entries') // Pfad zur entsprechenden Flask-Route + .then(response => response.json()) + .then(data => { + const tableBody = document.getElementById('database-nutrition-table').getElementsByTagName('tbody')[0]; + data.forEach(entry => { + const row = tableBody.insertRow(); + row.insertCell(0).innerHTML = entry.food; + row.insertCell(1).innerHTML = entry.kcal; + // ... Fügen Sie weitere Zellen für die anderen Werte hinzu ... + }); + }) + .catch(error => console.error('Fehler:', error)); + } + +document.addEventListener('DOMContentLoaded', loadDatabaseEntries); + + @@ -90,6 +128,27 @@ + +
+ + + + + + + + + + + + + + + +
LebensmittelkcalEWFettKHBSTCA
+
+ +