Improve project/task/sub-task workflows across backend and web
Backend: - notes.py: add parent_id filter to list_notes() - routes/notes.py: expose project_id, milestone_id, parent_id, type query params on GET /api/notes - milestones.py: add find_milestone_by_title() (cross-project search) - tools.py: list_notes project filter + updated_at; list_tasks milestone without project; tag_mode default add; fail-fast project resolution Web frontend: - TaskEditorView: add sub-tasks section (fetch, toggle, create inline); pre-fill projectId/milestoneId/parentId from URL query params on new task - ProjectView: add + button in Todo kanban column header linking to /tasks/new?projectId=X&milestoneId=Y for quick task creation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -54,8 +54,21 @@ async def list_notes_route():
|
||||
elif request.args.get("is_task", "").lower() == "true":
|
||||
is_task = True
|
||||
|
||||
project_id = request.args.get("project_id", type=int)
|
||||
milestone_id = request.args.get("milestone_id", type=int)
|
||||
parent_id = request.args.get("parent_id", type=int)
|
||||
|
||||
# type= shorthand used by web frontend (?type=task or ?type=note)
|
||||
type_param = request.args.get("type")
|
||||
if type_param == "task":
|
||||
is_task = True
|
||||
elif type_param == "note":
|
||||
is_task = False
|
||||
|
||||
notes, total = await list_notes(
|
||||
uid, q=q, tags=tag or None, is_task=is_task, sort=sort, order=order, limit=limit, offset=offset
|
||||
uid, q=q, tags=tag or None, is_task=is_task, sort=sort, order=order,
|
||||
limit=limit, offset=offset,
|
||||
project_id=project_id, milestone_id=milestone_id, parent_id=parent_id,
|
||||
)
|
||||
return jsonify({"notes": [n.to_dict() for n in notes], "total": total})
|
||||
|
||||
|
||||
@@ -53,6 +53,18 @@ async def get_milestone_by_title(user_id: int, project_id: int, title: str) -> M
|
||||
return result.scalars().first()
|
||||
|
||||
|
||||
async def find_milestone_by_title(user_id: int, title: str) -> Milestone | None:
|
||||
"""Find a milestone by title across ALL projects for this user (case-insensitive)."""
|
||||
async with async_session() as session:
|
||||
result = await session.execute(
|
||||
select(Milestone).where(
|
||||
Milestone.user_id == user_id,
|
||||
func.lower(Milestone.title) == func.lower(title.strip()),
|
||||
).order_by(Milestone.id).limit(1)
|
||||
)
|
||||
return result.scalars().first()
|
||||
|
||||
|
||||
async def get_or_create_milestone(user_id: int, project_id: int, title: str) -> Milestone:
|
||||
milestone = await get_milestone_by_title(user_id, project_id, title)
|
||||
if milestone:
|
||||
|
||||
@@ -71,6 +71,7 @@ async def list_notes(
|
||||
due_after: date | None = None,
|
||||
project_id: int | None = None,
|
||||
milestone_id: int | None = None,
|
||||
parent_id: int | None = None,
|
||||
sort: str = "updated_at",
|
||||
order: str = "desc",
|
||||
limit: int = 50,
|
||||
@@ -131,6 +132,10 @@ async def list_notes(
|
||||
query = query.where(Note.milestone_id == milestone_id)
|
||||
count_query = count_query.where(Note.milestone_id == milestone_id)
|
||||
|
||||
if parent_id is not None:
|
||||
query = query.where(Note.parent_id == parent_id)
|
||||
count_query = count_query.where(Note.parent_id == parent_id)
|
||||
|
||||
sort_col = getattr(Note, sort, Note.updated_at)
|
||||
if order == "asc":
|
||||
query = query.order_by(sort_col.asc())
|
||||
|
||||
@@ -216,7 +216,7 @@ _CORE_TOOLS = [
|
||||
"name": "list_notes",
|
||||
"description": (
|
||||
"Browse the user's notes (not tasks). Use this when the user asks to see, list, or browse "
|
||||
"their notes — by recency, keyword, or tag. For tasks, use list_tasks instead."
|
||||
"their notes — by recency, keyword, tag, or project. For tasks, use list_tasks instead."
|
||||
),
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
@@ -230,6 +230,10 @@ _CORE_TOOLS = [
|
||||
"items": {"type": "string"},
|
||||
"description": "Filter notes that have ALL of these tags",
|
||||
},
|
||||
"project": {
|
||||
"type": "string",
|
||||
"description": "Filter notes by project name",
|
||||
},
|
||||
"sort": {
|
||||
"type": "string",
|
||||
"enum": ["updated_at", "created_at", "title"],
|
||||
@@ -904,6 +908,7 @@ async def execute_tool(user_id: int, tool_name: str, arguments: dict) -> dict:
|
||||
project_id = None
|
||||
milestone_id = None
|
||||
project_name = arguments.get("project")
|
||||
milestone_name = arguments.get("milestone")
|
||||
if project_name:
|
||||
from fabledassistant.services.projects import get_project_by_title, list_projects as _lp
|
||||
proj = await get_project_by_title(user_id, project_name)
|
||||
@@ -914,12 +919,17 @@ async def execute_tool(user_id: int, tool_name: str, arguments: dict) -> dict:
|
||||
proj = matches[0]
|
||||
if proj:
|
||||
project_id = proj.id
|
||||
milestone_name = arguments.get("milestone")
|
||||
if milestone_name:
|
||||
from fabledassistant.services.milestones import get_milestone_by_title
|
||||
ms = await get_milestone_by_title(user_id, proj.id, milestone_name)
|
||||
if ms:
|
||||
milestone_id = ms.id
|
||||
elif milestone_name:
|
||||
# No project specified — search milestone by name across all projects
|
||||
from fabledassistant.services.milestones import find_milestone_by_title
|
||||
ms = await find_milestone_by_title(user_id, milestone_name)
|
||||
if ms:
|
||||
milestone_id = ms.id
|
||||
notes, total = await list_notes(
|
||||
user_id=user_id,
|
||||
is_task=True,
|
||||
@@ -1097,11 +1107,24 @@ async def execute_tool(user_id: int, tool_name: str, arguments: dict) -> dict:
|
||||
elif tool_name == "list_notes":
|
||||
tags_raw = arguments.get("tags")
|
||||
tags = tags_raw if isinstance(tags_raw, list) else None
|
||||
project_id = None
|
||||
project_name = arguments.get("project")
|
||||
if project_name:
|
||||
from fabledassistant.services.projects import get_project_by_title as _gpbt, list_projects as _lp
|
||||
proj = await _gpbt(user_id, project_name)
|
||||
if proj is None:
|
||||
all_p = await _lp(user_id)
|
||||
matches = [p for p in all_p if project_name.lower() in p.title.lower()]
|
||||
proj = matches[0] if matches else None
|
||||
if proj is None:
|
||||
return {"success": False, "error": f"Project '{project_name}' not found."}
|
||||
project_id = proj.id
|
||||
notes, total = await list_notes(
|
||||
user_id=user_id,
|
||||
q=arguments.get("q") or arguments.get("query"),
|
||||
tags=tags,
|
||||
is_task=False,
|
||||
project_id=project_id,
|
||||
sort=arguments.get("sort", "updated_at"),
|
||||
order="desc",
|
||||
limit=int(arguments.get("limit", 10)),
|
||||
@@ -1111,6 +1134,7 @@ async def execute_tool(user_id: int, tool_name: str, arguments: dict) -> dict:
|
||||
"id": n.id,
|
||||
"title": n.title,
|
||||
"tags": n.tags or [],
|
||||
"updated_at": n.updated_at.isoformat(),
|
||||
"preview": (n.body[:200] + "...") if n.body and len(n.body) > 200 else (n.body or ""),
|
||||
}
|
||||
for n in notes
|
||||
|
||||
Reference in New Issue
Block a user