parent
5c8f057843
commit
ce38d6cf24
@ -13,7 +13,8 @@ RUN \
|
||||
apk add --no-cache build-base libpq-dev && \
|
||||
pip install -r requirements.txt && \
|
||||
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 \
|
||||
sed -i -e 's/VERSION_ID/'$VERSION_ID'/' ${APP_DIR}/templates/nutrition.html
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
26
src/Run.py
26
src/Run.py
@ -175,8 +175,30 @@ def get_database_entries():
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
|
||||
@app.route('/delete_nutrition', methods=['POST'])
|
||||
@oidc.accept_token(['openid'])
|
||||
def delete_nutrition():
|
||||
data = request.get_json()
|
||||
foodNames = data['foodNames']
|
||||
|
||||
if not foodNames:
|
||||
return jsonify({'error': 'Keine Lebensmittel zum Löschen angegeben'}), 400
|
||||
|
||||
try:
|
||||
conn = psycopg2.connect()
|
||||
with conn.cursor() as cursor:
|
||||
query = "DELETE FROM nutrition_table WHERE name = ANY(%s)"
|
||||
cursor.execute(query, (foodNames,))
|
||||
conn.commit()
|
||||
return jsonify({'message': 'Erfolgreich gelöscht'}), 200
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
|
||||
exposed_app = ProxyFix(app, x_for=1, x_host=1)
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -70,13 +70,33 @@
|
||||
|
||||
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
|
||||
const selectedRows = Array.from(table.querySelectorAll('tr.selected'));
|
||||
const foodNames = selectedRows.map(row => row.cells[0].innerText); // Annahme, der Name des Lebensmittels befindet sich in der ersten Zelle
|
||||
|
||||
if (foodNames.length > 0) {
|
||||
// Holen des Tokens und Senden einer Anfrage an das Backend, um die Einträge zu löschen
|
||||
getBearerToken(token => {
|
||||
fetch('/delete_nutrition', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + token
|
||||
},
|
||||
body: JSON.stringify({foodNames: foodNames})
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
// Erfolgreich gelöscht, entferne Zeilen aus der Tabelle
|
||||
selectedRows.forEach(row => {
|
||||
table.deleteRow(row.rowIndex);
|
||||
});
|
||||
} else {
|
||||
console.error('Fehler beim Löschen der Datenbank-Einträge');
|
||||
}
|
||||
}).catch(error => console.error('Fehler:', error));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function showPasswordPrompt() {
|
||||
document.getElementById('delete-row-button').style.display = 'none';
|
||||
|
Loading…
x
Reference in New Issue
Block a user