improve: add setting button to pathnode

This commit is contained in:
h z
2025-03-20 18:37:13 +00:00
parent e7000f0b2e
commit 6626fac452
3 changed files with 10 additions and 15 deletions

View File

@@ -15,24 +15,18 @@ tree_bp = Blueprint('tree', __name__, url_prefix='/api/tree')
def build_tree(db: Session, parent_id: int = None):
path_nodes = db.query(Path).filter(Path.parent_id == parent_id).all()
md_nodes = db.query(Markdown.id, Markdown.title, Markdown.order, Markdown.shortcut).filter(Markdown.path_id == parent_id).all()
md_nodes = db.query(Markdown.id, Markdown.title, Markdown.order, Markdown.shortcut, Markdown.setting_id).filter(Markdown.path_id == parent_id).all()
t0 = [
{
"type": "markdown",
"id": node.id,
"title": node.title,
"order": node.order,
"shortcut": node.shortcut
"setting_id": node.setting_id,
"type": "markdown"
} for node in md_nodes
]
t1 = [
{
"type": "path",
"id": node.id,
"name": node.name,
"order": node.order,
"children": build_tree(db, node.id)
} for node in path_nodes
{**node.to_dict(), "type": "path", "children": build_tree(db, node.id)} for node in path_nodes
]
for node in t1:
for child in node["children"]:
@@ -47,11 +41,12 @@ def build_tree(db: Session, parent_id: int = None):
def get_tree():
with get_db() as session:
children = build_tree(session, 1)
root = session.query(Path).get(1)
return jsonify(
{
**root.to_dict(),
"type": "path",
"id": 1,
"name": "Root",
"index": any("title" in child.keys() and child["title"] == "index" for child in children),
"children": children
}