diff options
| author | stilbruch <stilbruch@protonail.com> | 2022-05-04 19:09:29 -0500 |
|---|---|---|
| committer | stilbruch <stilbruch@protonail.com> | 2022-05-04 19:09:29 -0500 |
| commit | ac0463db9a00b8d5fcd570d18e86c9ba62851365 (patch) | |
| tree | 9c71cf6ad0c9c6a11b01779a76bc864f5741e575 | |
| parent | 6a92fe73a176164197706965c82ea98b08bbc2bd (diff) | |
| download | Strengthy-ac0463db9a00b8d5fcd570d18e86c9ba62851365.tar.xz Strengthy-ac0463db9a00b8d5fcd570d18e86c9ba62851365.zip | |
Progress on progress api endpoint
| -rw-r--r-- | app/routes/api.py | 33 | ||||
| -rw-r--r-- | app/routes/progress.py | 8 | ||||
| -rw-r--r-- | app/routes/workout.py | 1 | ||||
| -rw-r--r-- | app/static/js/chart.js | 9 | ||||
| -rw-r--r-- | app/templates/progress/exercise.html | 22 | ||||
| -rw-r--r-- | app/templates/workout/record.html | 1 |
6 files changed, 39 insertions, 35 deletions
diff --git a/app/routes/api.py b/app/routes/api.py index 6a95ca2..77ebdcf 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -1,7 +1,7 @@ from app import app, db from flask import redirect, request, jsonify from flask_login import current_user, login_required -from tables import Workout +from tables import Exercise, SetRecord, Workout, WorkoutRecord @app.route("/api/workout/delete", methods=["GET"]) @@ -20,11 +20,30 @@ def api_workout_delete(): return redirect("/home") -@app.route("/api/progress/exercise", methods=["GET"]) +@app.route("/api/progress/exercise/<exercise_id>", methods=["GET"]) @login_required -def api_progress_exercise(): - if "id" not in request.args: - return redirect("/home") +def api_progress_exercise(exercise_id=None): + # Get exercise from database NOTE: consider adding userid to exercise + exercise = ( + db.session.query(Exercise) + .filter_by(id=exercise_id) + .join(Workout, Workout.user_id == current_user.id) + .first() + ) + if not exercise: + return redirect(url_for("home")) + + results = ( + db.session.query(WorkoutRecord.id, db.func.max(SetRecord.lbs)) + # .join(SetRecord.workout_record_id == WorkoutRecord.id) + .filter( + SetRecord.exercise_id == exercise_id, + WorkoutRecord.user_id == current_user.id, + SetRecord.workout_record_id == WorkoutRecord.id, + ).group_by(WorkoutRecord.id) + ).all() + + print(results) - # FIXME - return jsonify() + # TODO doesnt work + return jsonify(results) diff --git a/app/routes/progress.py b/app/routes/progress.py index 8040fdc..7b451ed 100644 --- a/app/routes/progress.py +++ b/app/routes/progress.py @@ -7,12 +7,10 @@ from tables import Exercise, Workout @app.route("/progress/exercise/<exercise_id>") @login_required def progress_exercise(exercise_id=None): - # FIXME - exercise = ( - db.session.query(Workout, Exercise) - .filter(Exercise.id == exercise_id) - .filter(Workout.user_id == current_user.id) + db.session.query(Exercise) + .filter_by(id=exercise_id) + .join(Workout, Workout.user_id == current_user.id) .first() ) if not exercise: diff --git a/app/routes/workout.py b/app/routes/workout.py index 5eb18d9..8f58aa3 100644 --- a/app/routes/workout.py +++ b/app/routes/workout.py @@ -131,6 +131,7 @@ def workout_record(workout_id=None): return redirect(url_for("home")) else: + print(form.errors) # Populate form with data for exercise in workout.exercises: form.exercises.append_entry( diff --git a/app/static/js/chart.js b/app/static/js/chart.js index d72d415..06edc4d 100644 --- a/app/static/js/chart.js +++ b/app/static/js/chart.js @@ -1,7 +1,6 @@ - -function fillChart(id) { - const ctx = document.getElementById(id) - new Chart(document.getElementById('exercise_chart'), { +function exercise_chart(elem_id, exercise_id) { + // Create initial chart + let chart = new Chart(document.getElementById(elem_id), { type: 'line', data: { cubicInterpolationMode: 'monotone', @@ -18,4 +17,6 @@ function fillChart(id) { } } }); + + // Load chart data for exercise } diff --git a/app/templates/progress/exercise.html b/app/templates/progress/exercise.html index 51149fc..e66618f 100644 --- a/app/templates/progress/exercise.html +++ b/app/templates/progress/exercise.html @@ -1,11 +1,10 @@ {% extends 'base/layout.html' %} -{% block title %}{{ exercise.name }} Progress{% endblock %} - {% block content %} <div class="container"> <div class="columns is-centered"> <div class="column"> + <h1 class="title is-2">{{ exercise.name }}</h1> <div class="box"> <canvas id="exercise_chart"></canvas> </div> @@ -13,24 +12,9 @@ </div> </div> +<script type="text/javascript" src="/static/js/chart.js"></script> <script> - new Chart(document.getElementById('exercise_chart'), { - type: 'line', - data: { - cubicInterpolationMode: 'monotone', - tension: 0.4, - pointStyle: 'circle', - pointRadius: 5, - pointHoverRadius: 10, - }, - option: { - scales: { - y: { - beginAtZero: true - } - } - } - }); + exercise_chart('exercise_chart', {{ exercise.id }}); </script> {% endblock %} diff --git a/app/templates/workout/record.html b/app/templates/workout/record.html index 9e93805..9b10f2d 100644 --- a/app/templates/workout/record.html +++ b/app/templates/workout/record.html @@ -5,6 +5,7 @@ {% block form %} <div> {% for exercise in workout.exercises %} + {{ form.exercises.entries[loop.index0]['id'] }} <h1 class="title is-4 has-text-black">{{ exercise.name }}</h1> <div> <table class="table is-fullwidth is-hoverable"> |
