Mehrere Auswahlen in einem Objekt speichern

- 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 <noreply@anthropic.com>
This commit is contained in:
2026-04-25 21:23:22 +02:00
parent 8219a5445c
commit 807c733770
4 changed files with 14 additions and 15 deletions

2
app.py
View File

@@ -79,7 +79,7 @@ def directus_objects():
token = request.headers.get("Authorization", "") token = request.headers.get("Authorization", "")
if request.method == "GET": if request.method == "GET":
picture_id = request.args.get("picture_id", "") 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" path = f"/items/objects?filter[picture][_eq]={picture_id}&fields={fields}&sort=date_created"
data, status = _directus("GET", path, token) data, status = _directus("GET", path, token)
return jsonify(data), status return jsonify(data), status

View File

@@ -47,6 +47,7 @@ export async function createDirectusObject(payload: {
picture: string picture: string
bbox: BBox | null bbox: BBox | null
polygon: Point[] | null polygon: Point[] | null
selections: import('./types').Selection[] | null
user_notes: string | null user_notes: string | null
parent: string | null parent: string | null
}, token: string): Promise<DirectusObject> { }, token: string): Promise<DirectusObject> {

View File

@@ -88,24 +88,21 @@ export default function DrawIt() {
if (!currentPicture || !token || currentSelections.length === 0) return if (!currentPicture || !token || currentSelections.length === 0) return
setSaving(true) setSaving(true)
try { try {
// Save one object per selection const first = currentSelections[0]
const newObjs: DirectusObject[] = []
for (const sel of currentSelections) {
const obj = await createDirectusObject({ const obj = await createDirectusObject({
picture: currentPicture.id, picture: currentPicture.id,
bbox: sel.mode === 'rect' ? (sel.bbox ?? null) : null, bbox: first.mode === 'rect' ? (first.bbox ?? null) : null,
polygon: sel.mode === 'polygon' ? (sel.polygon ?? null) : null, polygon: first.mode === 'polygon' ? (first.polygon ?? null) : null,
selections: currentSelections,
user_notes: userNotes.trim() || null, user_notes: userNotes.trim() || null,
parent: parentId, parent: parentId,
}, token) }, token)
newObjs.push({ ...obj, visible: true }) setObjects(prev => [...prev, { ...obj, visible: true }])
}
setObjects(prev => [...prev, ...newObjs])
setCurrentSelections([]) setCurrentSelections([])
setUserNotes('') setUserNotes('')
setParentId(null) setParentId(null)
canvasRef.current?.resetSelection() canvasRef.current?.resetSelection()
showStatus(`${newObjs.length} Objekt(e) gespeichert.`) showStatus('Objekt gespeichert.')
} catch (e) { } catch (e) {
showStatus(e instanceof Error ? e.message : 'Fehler beim Speichern.', true) showStatus(e instanceof Error ? e.message : 'Fehler beim Speichern.', true)
} finally { } finally {

View File

@@ -42,6 +42,7 @@ export interface DirectusObject {
picture: string picture: string
bbox: BBox | null bbox: BBox | null
polygon: Point[] | null polygon: Point[] | null
selections: Selection[] | null
user_notes: string | null user_notes: string | null
parent: string | null parent: string | null
visible?: boolean // local UI state only visible?: boolean // local UI state only