Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c318cd21e0 | |||
224e6a9147 | |||
8f15a05a4e | |||
f0fcbc3c56
|
27
src/Run.py
27
src/Run.py
@ -140,7 +140,34 @@ def get_token():
|
|||||||
return jsonify(token=oidc.get_access_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)
|
app = ProxyFix(app, x_for=1, x_host=1)
|
||||||
|
|
||||||
|
@ -152,3 +152,25 @@ tr:hover:not(.selected) {
|
|||||||
overflow-x: auto; /* Ermöglicht horizontales Scrollen auf kleinen Bildschirmen */
|
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;
|
||||||
|
}
|
||||||
|
@ -55,6 +55,71 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 showPasswordPrompt() {
|
||||||
|
document.getElementById('delete-row-button').style.display = 'none';
|
||||||
|
document.getElementById('password-prompt').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
function hidePasswordPrompt() {
|
||||||
|
document.getElementById('delete-row-button').style.display = 'block';
|
||||||
|
document.getElementById('password-prompt').style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteRowsIfPasswordCorrect() {
|
||||||
|
const password = document.getElementById('password-input').value;
|
||||||
|
if (password === 'wowmuchsecurity') {
|
||||||
|
deleteSelectedRows(); // Funktion, die die ausgewählten Zeilen löscht
|
||||||
|
hidePasswordPrompt();
|
||||||
|
} else {
|
||||||
|
alert('Falsches Passwort!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
row.insertCell(2).innerHTML = entry.ew;
|
||||||
|
row.insertCell(3).innerHTML = entry.fett;
|
||||||
|
row.insertCell(4).innerHTML = entry.kh;
|
||||||
|
row.insertCell(5).innerHTML = entry.bst;
|
||||||
|
row.insertCell(6).innerHTML = entry.ca;
|
||||||
|
|
||||||
|
// ... Fügen Sie weitere Zellen für die anderen Werte hinzu ...
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => console.error('Fehler:', error));
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', loadDatabaseEntries);
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -90,6 +155,34 @@
|
|||||||
</table>
|
</table>
|
||||||
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<div id="table-container">
|
||||||
|
<table id="database-nutrition-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Lebensmittel</th>
|
||||||
|
<th>kcal</th>
|
||||||
|
<th>EW</th>
|
||||||
|
<th>Fett</th>
|
||||||
|
<th>KH</th>
|
||||||
|
<th>BST</th>
|
||||||
|
<th>CA</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<!-- Die Zeilen werden dynamisch aus der Datenbank geladen -->
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<button id="delete-row-button" onclick="showPasswordPrompt()">Zeilen löschen</button>
|
||||||
|
|
||||||
|
<div id="password-prompt" style="display: none;">
|
||||||
|
<input type="password" id="password-input" placeholder="Passwort">
|
||||||
|
<button onclick="deleteRowsIfPasswordCorrect()">OK</button>
|
||||||
|
<button onclick="hidePasswordPrompt()">Abbrechen</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user