From 807c7337705e4bdb3156d39c6d4d93db62a26190 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 25 Apr 2026 21:23:22 +0200 Subject: [PATCH] Mehrere Auswahlen in einem Objekt speichern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Neues JSON-Feld 'selections' in Directus objects-Collection - Alle Auswahlen (bbox/polygon) landen in einem einzigen Objekt - Erste Auswahl bleibt weiterhin in bbox/polygon für Kompatibilität - GET-Proxy liefert selections-Feld mit aus Co-Authored-By: Claude Sonnet 4.6 --- app.py | 2 +- frontend/src/api.ts | 1 + frontend/src/pages/DrawIt.tsx | 25 +++++++++++-------------- frontend/src/types.ts | 1 + 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app.py b/app.py index accb8f9..3a450db 100644 --- a/app.py +++ b/app.py @@ -79,7 +79,7 @@ def directus_objects(): token = request.headers.get("Authorization", "") if request.method == "GET": picture_id = request.args.get("picture_id", "") - fields = "id,bbox,polygon,user_notes,parent,status,picture" + fields = "id,bbox,polygon,selections,user_notes,parent,status,picture" path = f"/items/objects?filter[picture][_eq]={picture_id}&fields={fields}&sort=date_created" data, status = _directus("GET", path, token) return jsonify(data), status diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 203897d..45c10bb 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -47,6 +47,7 @@ export async function createDirectusObject(payload: { picture: string bbox: BBox | null polygon: Point[] | null + selections: import('./types').Selection[] | null user_notes: string | null parent: string | null }, token: string): Promise { diff --git a/frontend/src/pages/DrawIt.tsx b/frontend/src/pages/DrawIt.tsx index fc56d7b..ef86229 100644 --- a/frontend/src/pages/DrawIt.tsx +++ b/frontend/src/pages/DrawIt.tsx @@ -88,24 +88,21 @@ export default function DrawIt() { if (!currentPicture || !token || currentSelections.length === 0) return setSaving(true) try { - // Save one object per selection - const newObjs: DirectusObject[] = [] - for (const sel of currentSelections) { - const obj = await createDirectusObject({ - picture: currentPicture.id, - bbox: sel.mode === 'rect' ? (sel.bbox ?? null) : null, - polygon: sel.mode === 'polygon' ? (sel.polygon ?? null) : null, - user_notes: userNotes.trim() || null, - parent: parentId, - }, token) - newObjs.push({ ...obj, visible: true }) - } - setObjects(prev => [...prev, ...newObjs]) + const first = currentSelections[0] + const obj = await createDirectusObject({ + picture: currentPicture.id, + bbox: first.mode === 'rect' ? (first.bbox ?? null) : null, + polygon: first.mode === 'polygon' ? (first.polygon ?? null) : null, + selections: currentSelections, + user_notes: userNotes.trim() || null, + parent: parentId, + }, token) + setObjects(prev => [...prev, { ...obj, visible: true }]) setCurrentSelections([]) setUserNotes('') setParentId(null) canvasRef.current?.resetSelection() - showStatus(`${newObjs.length} Objekt(e) gespeichert.`) + showStatus('Objekt gespeichert.') } catch (e) { showStatus(e instanceof Error ? e.message : 'Fehler beim Speichern.', true) } finally { diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 876bee7..560559f 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -42,6 +42,7 @@ export interface DirectusObject { picture: string bbox: BBox | null polygon: Point[] | null + selections: Selection[] | null user_notes: string | null parent: string | null visible?: boolean // local UI state only