Add section grouping to shared note tabs
Notes can now be clustered into named sections in the tab bar: each tab gets a 🏷 button to assign it to a section, and clicking a section's label renames (or, given an empty name, ungroups) every page in it. note_pages gains a `section` column. Since the app has no migration framework, database.py adds the column to existing SQLite files at startup via PRAGMA table_info + ALTER TABLE. core/notes.set_section() keeps same-section pages contiguous by renumbering position whenever a page's section changes, so the tab bar and the AI-facing title list (now grouped under "## section" headings) can both treat "adjacent" as "same group" without a separate ordering field. Also fixes a bug in the tab rename input: ref="renameInput" sits inside a nested v-for, which Vue 3 binds as an array rather than a single element, so renameInput.value?.select() was throwing on every rename. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy.orm import Session as DBSession
|
||||
|
||||
from app.core.notes import next_position
|
||||
from app.core.notes import next_position, rename_section, set_section
|
||||
from app.db.database import get_db
|
||||
from app.db.models import NotePage
|
||||
|
||||
@@ -16,6 +16,7 @@ class NotePageResponse(BaseModel):
|
||||
title: str
|
||||
content: str
|
||||
position: int
|
||||
section: str | None
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
@@ -25,11 +26,18 @@ class NotePageResponse(BaseModel):
|
||||
class NotePageCreate(BaseModel):
|
||||
title: str = "新しいページ"
|
||||
content: str = ""
|
||||
section: str | None = None
|
||||
|
||||
|
||||
class NotePageUpdate(BaseModel):
|
||||
title: str | None = None
|
||||
content: str | None = None
|
||||
section: str | None = None
|
||||
|
||||
|
||||
class SectionRenameRequest(BaseModel):
|
||||
old_name: str
|
||||
new_name: str | None = None
|
||||
|
||||
|
||||
@router.get("", response_model=list[NotePageResponse])
|
||||
@@ -44,9 +52,18 @@ def create_page(req: NotePageCreate, db: DBSession = Depends(get_db)):
|
||||
db.add(page)
|
||||
db.commit()
|
||||
db.refresh(page)
|
||||
if req.section is not None and req.section.strip():
|
||||
page = set_section(db, page.id, req.section)
|
||||
return page
|
||||
|
||||
|
||||
@router.post("/sections/rename")
|
||||
def rename_section_endpoint(req: SectionRenameRequest, db: DBSession = Depends(get_db)):
|
||||
"""old_name セクションに属する全ページを new_name セクションへ一括で付け替える。new_name が空ならグループ解除。"""
|
||||
count = rename_section(db, req.old_name, req.new_name)
|
||||
return {"renamed": count}
|
||||
|
||||
|
||||
@router.patch("/{page_id}", response_model=NotePageResponse)
|
||||
def update_page(page_id: int, req: NotePageUpdate, db: DBSession = Depends(get_db)):
|
||||
page = db.get(NotePage, page_id)
|
||||
@@ -61,6 +78,11 @@ def update_page(page_id: int, req: NotePageUpdate, db: DBSession = Depends(get_d
|
||||
page.content = req.content
|
||||
db.commit()
|
||||
db.refresh(page)
|
||||
|
||||
# section はページの並び順にも影響するため、変更があれば専用ロジックで反映する
|
||||
if "section" in req.model_fields_set:
|
||||
page = set_section(db, page_id, req.section)
|
||||
|
||||
return page
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user