Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
f39c902ace | |||
ff26644f06 | |||
5f63092a67 | |||
1fc9dd70df | |||
794b50e041 | |||
5583bc2b60 |
@ -20,6 +20,7 @@ app.config.update({
|
|||||||
oidc = OpenIDConnect(app)
|
oidc = OpenIDConnect(app)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_nutrition(food, weight):
|
def calculate_nutrition(food, weight):
|
||||||
try:
|
try:
|
||||||
conn = psycopg2.connect()
|
conn = psycopg2.connect()
|
||||||
@ -133,6 +134,12 @@ def add_nutrition():
|
|||||||
def nutrition():
|
def nutrition():
|
||||||
return render_template('nutrition.html')
|
return render_template('nutrition.html')
|
||||||
|
|
||||||
|
@app.route('/get_token')
|
||||||
|
@oidc.require_login
|
||||||
|
def get_token():
|
||||||
|
return jsonify(token=oidc.get_access_token())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app = ProxyFix(app, x_for=1, x_host=1)
|
app = ProxyFix(app, x_for=1, x_host=1)
|
||||||
|
@ -72,7 +72,7 @@ tr:nth-child(even) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.selected, tr.selected {
|
.selected, tr.selected {
|
||||||
background-color: #e19595; /* Hervorhebung der Auswahl */
|
background-color: #e5b5b5; /* Hervorhebung der Auswahl */
|
||||||
}
|
}
|
||||||
|
|
||||||
tr:hover:not(.selected) {
|
tr:hover:not(.selected) {
|
||||||
|
@ -154,12 +154,12 @@ function updateTotalNutrition() {
|
|||||||
|
|
||||||
// Durchlaufen aller Zeilen in der Haupttabelle und Addition der Werte
|
// Durchlaufen aller Zeilen in der Haupttabelle und Addition der Werte
|
||||||
Array.from(document.getElementById('nutrition-table').rows).slice(1).forEach(row => {
|
Array.from(document.getElementById('nutrition-table').rows).slice(1).forEach(row => {
|
||||||
totalKcal += parseFloat(row.cells[2].innerText);
|
totalKcal += parseFloat(row.cells[4].innerText);
|
||||||
totalEw += parseFloat(row.cells[3].innerText);
|
totalEw += parseFloat(row.cells[4].innerText);
|
||||||
totalFett += parseFloat(row.cells[4].innerText);
|
totalFett += parseFloat(row.cells[5].innerText);
|
||||||
totalKh += parseFloat(row.cells[5].innerText);
|
totalKh += parseFloat(row.cells[6].innerText);
|
||||||
totalBst += parseFloat(row.cells[6].innerText);
|
totalBst += parseFloat(row.cells[7].innerText);
|
||||||
totalCa += parseFloat(row.cells[7].innerText);
|
totalCa += parseFloat(row.cells[8].innerText);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rundung und Aktualisierung der Gesamtwerte
|
// Rundung und Aktualisierung der Gesamtwerte
|
||||||
@ -220,8 +220,8 @@ function updateTotalNutrition() {
|
|||||||
<th>CA</th>
|
<th>CA</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<t>Gesamtwerte</td>
|
<td>Gesamtwerte</td>
|
||||||
<td></td>-</td>
|
<td>-</td>
|
||||||
<td id="total-kcal">0</td>
|
<td id="total-kcal">0</td>
|
||||||
<td id="total-ew">0</td>
|
<td id="total-ew">0</td>
|
||||||
<td id="total-fett">0</td>
|
<td id="total-fett">0</td>
|
||||||
|
@ -13,31 +13,46 @@
|
|||||||
document.getElementById('submit-button').disabled = !allFilled;
|
document.getElementById('submit-button').disabled = !allFilled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getBearerToken(callback) {
|
||||||
|
fetch('/get_token')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
callback(data.token);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Fehler beim Abrufen des Tokens:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function addNutritionEntry() {
|
function addNutritionEntry() {
|
||||||
|
getBearerToken(token => {
|
||||||
|
const form = document.getElementById('nutrition-form');
|
||||||
|
const formData = new FormData(form);
|
||||||
|
|
||||||
const form = document.getElementById('nutrition-form');
|
fetch('/add_nutrition', {
|
||||||
const formData = new FormData(form);
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + token
|
||||||
|
},
|
||||||
|
body: formData
|
||||||
|
}).then(response => {
|
||||||
|
// Behandlung der Serverantwort
|
||||||
|
// Beispielsweise das Formular zurücksetzen
|
||||||
|
form.reset();
|
||||||
|
updateSubmitButtonState();
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('Fehler:', error);
|
||||||
|
});
|
||||||
|
// ... Code, um den Eintrag zur Datenbank hinzuzufügen
|
||||||
|
|
||||||
fetch('/add_nutrition', {
|
// Nach dem Hinzufügen, setze alle Eingabefelder zurück
|
||||||
method: 'POST',
|
document.querySelectorAll('#nutrition-form input').forEach(input => {
|
||||||
body: formData
|
input.value = ''; // Setzt den Wert jedes Eingabefeldes zurück
|
||||||
}).then(response => {
|
});
|
||||||
// Behandlung der Serverantwort
|
|
||||||
// Beispielsweise das Formular zurücksetzen
|
// Deaktiviere den "Hinzufügen"-Button wieder
|
||||||
form.reset();
|
document.getElementById('submit-button').disabled = true;
|
||||||
updateSubmitButtonState();
|
|
||||||
}).catch(error => {
|
|
||||||
console.error('Fehler:', error);
|
|
||||||
});
|
});
|
||||||
// ... Code, um den Eintrag zur Datenbank hinzuzufügen
|
|
||||||
|
|
||||||
// Nach dem Hinzufügen, setze alle Eingabefelder zurück
|
|
||||||
document.querySelectorAll('#nutrition-form input').forEach(input => {
|
|
||||||
input.value = ''; // Setzt den Wert jedes Eingabefeldes zurück
|
|
||||||
});
|
|
||||||
|
|
||||||
// Deaktiviere den "Hinzufügen"-Button wieder
|
|
||||||
document.getElementById('submit-button').disabled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user