UI
This commit is contained in:
@@ -10,7 +10,7 @@ from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable
|
||||
|
||||
from flask import Flask, jsonify, request, send_file
|
||||
from flask import Flask, Response, jsonify, request, send_file
|
||||
|
||||
from schema_contract import default_config, normalize_training_config, stable_id, validate_training_config
|
||||
from storage import atomic_json_write, utc_now
|
||||
@@ -21,6 +21,7 @@ PLANS_DIR = DATA_DIR / "plans"
|
||||
ACTIVE_FILE = DATA_DIR / "active.txt"
|
||||
LEGACY_CONFIG = DATA_DIR / "config.json"
|
||||
BACKUPS_DIR = DATA_DIR / "backups"
|
||||
STATIC_DIR = BASE_DIR / "static"
|
||||
PLANS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
BACKUPS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@@ -160,6 +161,10 @@ def public_wrapper(wrapper: dict[str, Any], *, draft: bool = True) -> dict[str,
|
||||
|
||||
|
||||
def _save_draft(pid: str, wrapper: dict[str, Any], config: dict[str, Any]) -> dict[str, Any]:
|
||||
meta = config.get("meta") if isinstance(config.get("meta"), dict) else {}
|
||||
title = str(meta.get("title") or "").strip()
|
||||
if title:
|
||||
wrapper["name"] = title
|
||||
wrapper["draft"] = normalize_training_config(config, plan_id=wrapper["plan_id"])
|
||||
wrapper["draft"]["meta"]["title"] = str(wrapper["name"])
|
||||
wrapper["revision"] += 1
|
||||
@@ -172,7 +177,7 @@ def _mutate_draft(pid: str, mutator: Callable[[dict[str, Any]], Any]) -> tuple[d
|
||||
wrapper = read_plan(pid)
|
||||
draft = deepcopy(wrapper["draft"])
|
||||
result = mutator(draft)
|
||||
if isinstance(result, str) and result in {"day", "exercise", "item", "used"}:
|
||||
if result is None or result is False or (isinstance(result, str) and result in {"day", "exercise", "item", "used"}):
|
||||
return wrapper, result
|
||||
saved = _save_draft(pid, wrapper, draft)
|
||||
return saved, result
|
||||
@@ -201,7 +206,7 @@ ensure_seed()
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return jsonify({"name": "Trainingsplan-Backend", "status": "ok"})
|
||||
return Response((STATIC_DIR / "index.html").read_text(encoding="utf-8"), mimetype="text/html")
|
||||
|
||||
|
||||
@app.route("/api/plans", methods=["GET"])
|
||||
|
||||
Reference in New Issue
Block a user