UI
This commit is contained in:
@@ -393,17 +393,15 @@ def api_exercise_create(pid: str):
|
||||
return jsonify({"error": "name required"}), 400
|
||||
|
||||
def mutate(cfg: dict[str, Any]) -> dict[str, Any]:
|
||||
progressions = body.get("progressions") if isinstance(body.get("progressions"), list) else []
|
||||
exercise = {
|
||||
"id": stable_id("exercise", cfg.get("plan_id"), len(cfg.get("exercises", [])), name),
|
||||
"name": name,
|
||||
"progressions": progressions,
|
||||
}
|
||||
for key in ("cue", "description", "equipment", "notes"):
|
||||
value = str(body.get(key) or "").strip()
|
||||
if value:
|
||||
exercise[key] = value
|
||||
tags = body.get("tags")
|
||||
if isinstance(tags, list):
|
||||
exercise["tags"] = [str(tag).strip() for tag in tags if str(tag).strip()]
|
||||
current_progression_id = str(body.get("current_progression_id") or "").strip()
|
||||
if current_progression_id:
|
||||
exercise["current_progression_id"] = current_progression_id
|
||||
cfg.setdefault("exercises", []).append(exercise)
|
||||
return exercise
|
||||
|
||||
@@ -424,15 +422,15 @@ def api_exercise_update(pid: str, exercise_id: str):
|
||||
if not exercise:
|
||||
return None
|
||||
updated = deepcopy(exercise)
|
||||
for key in ("name", "cue", "description", "equipment", "notes"):
|
||||
for key in ("name", "current_progression_id"):
|
||||
if key in body:
|
||||
value = str(body.get(key) or "").strip()
|
||||
if value:
|
||||
updated[key] = value
|
||||
else:
|
||||
updated.pop(key, None)
|
||||
if isinstance(body.get("tags"), list):
|
||||
updated["tags"] = [str(tag).strip() for tag in body["tags"] if str(tag).strip()]
|
||||
if isinstance(body.get("progressions"), list):
|
||||
updated["progressions"] = body["progressions"]
|
||||
_replace_list_item(exercises, exercise_id, updated)
|
||||
return updated
|
||||
|
||||
@@ -514,7 +512,7 @@ def api_day_update(pid: str, day_id: str):
|
||||
if not day:
|
||||
return None
|
||||
updated = deepcopy(day)
|
||||
for key in ("name", "focus", "notes"):
|
||||
for key in ("name",):
|
||||
if key in body:
|
||||
value = str(body.get(key) or "").strip()
|
||||
if value:
|
||||
@@ -576,13 +574,6 @@ def api_day_exercise_add(pid: str, day_id: str):
|
||||
"id": stable_id("day-exercise", day_id, exercise_id, len(day.get("exercises", []))),
|
||||
"exercise_id": exercise_id,
|
||||
}
|
||||
for key in ("sets", "duration_seconds"):
|
||||
if body.get(key):
|
||||
item[key] = int(body[key])
|
||||
for key in ("reps", "tempo", "rest", "notes"):
|
||||
value = str(body.get(key) or "").strip()
|
||||
if value:
|
||||
item[key] = value
|
||||
day.setdefault("exercises", []).append(item)
|
||||
return item
|
||||
|
||||
@@ -614,20 +605,6 @@ def api_day_exercise_update(pid: str, day_id: str, item_id: str):
|
||||
if not _find_by_id(cfg.get("exercises", []), exercise_id):
|
||||
return "exercise"
|
||||
updated["exercise_id"] = exercise_id
|
||||
for key in ("sets", "duration_seconds"):
|
||||
if key in body:
|
||||
value = int(body.get(key) or 0)
|
||||
if value > 0:
|
||||
updated[key] = value
|
||||
else:
|
||||
updated.pop(key, None)
|
||||
for key in ("reps", "tempo", "rest", "notes"):
|
||||
if key in body:
|
||||
value = str(body.get(key) or "").strip()
|
||||
if value:
|
||||
updated[key] = value
|
||||
else:
|
||||
updated.pop(key, None)
|
||||
_replace_list_item(day["exercises"], item_id, updated)
|
||||
return updated
|
||||
|
||||
|
||||
Reference in New Issue
Block a user