Skip to content

Commit

Permalink
create rete editor from worktreeData
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Dec 10, 2023
1 parent be7ded0 commit 608960d
Show file tree
Hide file tree
Showing 6 changed files with 1,730 additions and 74 deletions.
25 changes: 16 additions & 9 deletions aiida_worktree/web/backend/app/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def worktree_to_json(wtdata):
"""Export a worktree to a JSON serializable dictionary."""
def worktree_to_short_json(wtdata):
"""Export a worktree to a rete js editor data."""
wtdata_short = {
"name": wtdata["name"],
"uuid": wtdata["uuid"],
Expand All @@ -9,12 +9,19 @@ def worktree_to_json(wtdata):
}
for name, node in wtdata["nodes"].items():
wtdata_short["nodes"][name] = {
"name": node["name"],
"identifier": node["metadata"]["identifier"],
"node_type": node["metadata"]["node_type"],
"uuid": node["uuid"],
"state": node["state"],
"action": node["action"],
"inputs": node["inputs"],
"label": node["name"],
"inputs": [],
"outputs": [],
}
for link in wtdata["links"]:
wtdata_short["nodes"][link["to_node"]]["inputs"].append(
{
"name": link["to_socket"],
}
)
wtdata_short["nodes"][link["from_node"]]["outputs"].append(
{
"name": link["from_socket"],
}
)
return wtdata_short
4 changes: 2 additions & 2 deletions aiida_worktree/web/backend/app/worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def read_worktree_data(search: str = Query(None)):

@router.get("/worktree/{id}")
async def read_worktree_item(id: int):
from .utils import worktree_to_json
from .utils import worktree_to_short_json

try:
node = orm.load_node(id)
Expand All @@ -45,7 +45,7 @@ async def read_worktree_item(id: int):
print("No worktree data found in the node.")
return
wtdata = deserialize_unsafe(wtdata)
content = worktree_to_json(wtdata)
content = worktree_to_short_json(wtdata)
return content
except KeyError:
raise HTTPException(status_code=404, detail=f"Worktree {id} not found")
Loading

0 comments on commit 608960d

Please sign in to comment.