Skip to content

Commit 6f1f725

Browse files
ui
1 parent 658e7ea commit 6f1f725

26 files changed

+4445
-1241
lines changed

poetry.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rb-api/pyproject.toml

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ typer = "*"
1515

1616
rescuebox = { path = "../../", develop = true }
1717
rb-lib = { path = "../rb-lib", develop = true }
18-
anytree = "^2.12.1"
19-
loguru = "^0.7.2"
2018

2119

2220
[build-system]

src/rb-api/rb/api/routes/cli.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
This router contains dynamic routes only! Do not add static routes here.
3+
"""
4+
15
import inspect
26
from typing import Callable, Generator, Optional
37

src/rb-api/rb/api/routes/ui.py

+4-53
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import json
12
import os
23

3-
import typer
4-
from anytree import Node, RenderTree
54
from fastapi import APIRouter, Request
65
from fastapi.templating import Jinja2Templates
7-
from loguru import logger
6+
from rb.lib.typer import typer_app_to_tree
87

98
from rescuebox.main import app as rescuebox_app
109

@@ -17,55 +16,7 @@
1716

1817
@ui_router.get("/")
1918
async def interface(request: Request):
20-
tree = _typer_app_to_tree(rescuebox_app)
19+
tree = typer_app_to_tree(rescuebox_app)
2120
return templates.TemplateResponse(
22-
"index.html.j2", {"request": request, "tree": tree}
21+
"index.html.j2", {"request": request, "tree": json.dumps(tree)}
2322
)
24-
25-
26-
def _typer_app_to_tree(app: typer.Typer) -> dict:
27-
# Create root node
28-
root = Node("rescuebox", command=None, is_group=True)
29-
30-
def add_commands_to_node(typer_app: typer.Typer, parent_node: Node):
31-
# Add groups recursively
32-
for group in getattr(typer_app, "registered_groups", []):
33-
group_node = Node(
34-
group.name,
35-
parent=parent_node,
36-
command=None,
37-
is_group=True,
38-
)
39-
# Recursively add any nested groups/commands
40-
add_commands_to_node(group.typer_instance, group_node)
41-
42-
# Add commands at this level
43-
for command in getattr(typer_app, "registered_commands", []):
44-
command_name = getattr(command, "name", None) or command.callback.__name__
45-
46-
Node(
47-
command_name,
48-
parent=parent_node,
49-
command=command,
50-
is_group=False,
51-
)
52-
53-
# Build the full tree structure
54-
add_commands_to_node(app, root)
55-
56-
# Debug print the tree
57-
for pre, fill, node in RenderTree(root):
58-
logger.debug("%s%s" % (pre, node.name))
59-
60-
def node_to_dict(node: Node) -> dict:
61-
result = {"name": node.name, "command": node.command, "is_group": node.is_group}
62-
if not node.is_group:
63-
# the endpoint is the path without the rescuebox root
64-
result["endpoint"] = "/" + "/".join([_.name for _ in node.path][1:])
65-
if node.children:
66-
result["children"] = [node_to_dict(child) for child in node.children]
67-
return result
68-
69-
# Convert the entire tree to dictionary format
70-
tree_dict = node_to_dict(root)
71-
return tree_dict

src/rb-api/rb/api/static/copy_to_clipboard.js

-8
This file was deleted.

src/rb-api/rb/api/static/index/main.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rb-api/rb/api/static/index/main.js

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rb-api/rb/api/static/open_form.js

-36
This file was deleted.

src/rb-api/rb/api/static/panes.css

-45
This file was deleted.

src/rb-api/rb/api/static/panes.js

-12
This file was deleted.

src/rb-api/rb/api/static/post_and_read.js

-131
This file was deleted.

src/rb-api/rb/api/static/pure.css

-11
This file was deleted.

0 commit comments

Comments
 (0)