Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
f39c902ace | |||
ff26644f06 | |||
5f63092a67 | |||
1fc9dd70df | |||
794b50e041 | |||
5583bc2b60 | |||
5f34449601
|
|||
8bc3857482
|
|||
5c7fe128c8
|
@ -20,6 +20,7 @@ app.config.update({
|
||||
oidc = OpenIDConnect(app)
|
||||
|
||||
|
||||
|
||||
def calculate_nutrition(food, weight):
|
||||
try:
|
||||
conn = psycopg2.connect()
|
||||
@ -104,7 +105,7 @@ def convert_decimal(value):
|
||||
|
||||
|
||||
@app.route('/add_nutrition', methods=['POST'])
|
||||
@oidc.require_login
|
||||
@oidc.accept_token(True)
|
||||
def add_nutrition():
|
||||
food = request.form.get('food')
|
||||
kcal = convert_decimal(request.form.get('kcal'))
|
||||
@ -133,6 +134,12 @@ def add_nutrition():
|
||||
def nutrition():
|
||||
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)
|
||||
|
@ -72,7 +72,7 @@ tr:nth-child(even) {
|
||||
}
|
||||
|
||||
.selected, tr.selected {
|
||||
background-color: #e19595; /* Hervorhebung der Auswahl */
|
||||
background-color: #e5b5b5; /* Hervorhebung der Auswahl */
|
||||
}
|
||||
|
||||
tr:hover:not(.selected) {
|
||||
|
@ -154,12 +154,12 @@ function updateTotalNutrition() {
|
||||
|
||||
// Durchlaufen aller Zeilen in der Haupttabelle und Addition der Werte
|
||||
Array.from(document.getElementById('nutrition-table').rows).slice(1).forEach(row => {
|
||||
totalKcal += parseFloat(row.cells[2].innerText);
|
||||
totalEw += parseFloat(row.cells[3].innerText);
|
||||
totalFett += parseFloat(row.cells[4].innerText);
|
||||
totalKh += parseFloat(row.cells[5].innerText);
|
||||
totalBst += parseFloat(row.cells[6].innerText);
|
||||
totalCa += parseFloat(row.cells[7].innerText);
|
||||
totalKcal += parseFloat(row.cells[4].innerText);
|
||||
totalEw += parseFloat(row.cells[4].innerText);
|
||||
totalFett += parseFloat(row.cells[5].innerText);
|
||||
totalKh += parseFloat(row.cells[6].innerText);
|
||||
totalBst += parseFloat(row.cells[7].innerText);
|
||||
totalCa += parseFloat(row.cells[8].innerText);
|
||||
});
|
||||
|
||||
// Rundung und Aktualisierung der Gesamtwerte
|
||||
@ -220,8 +220,8 @@ function updateTotalNutrition() {
|
||||
<th>CA</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<t>Gesamtwerte</td>
|
||||
<td></td>-</td>
|
||||
<td>Gesamtwerte</td>
|
||||
<td>-</td>
|
||||
<td id="total-kcal">0</td>
|
||||
<td id="total-ew">0</td>
|
||||
<td id="total-fett">0</td>
|
||||
|
@ -13,13 +13,27 @@
|
||||
document.getElementById('submit-button').disabled = !allFilled;
|
||||
}
|
||||
|
||||
function addNutritionEntry() {
|
||||
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() {
|
||||
getBearerToken(token => {
|
||||
const form = document.getElementById('nutrition-form');
|
||||
const formData = new FormData(form);
|
||||
|
||||
fetch('/add_nutrition', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + token
|
||||
},
|
||||
body: formData
|
||||
}).then(response => {
|
||||
// Behandlung der Serverantwort
|
||||
@ -38,6 +52,7 @@
|
||||
|
||||
// Deaktiviere den "Hinzufügen"-Button wieder
|
||||
document.getElementById('submit-button').disabled = true;
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user