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:
2
app.py
2
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
|
||||
|
||||
@@ -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<DirectusObject> {
|
||||
|
||||
@@ -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 first = currentSelections[0]
|
||||
const obj = await createDirectusObject({
|
||||
picture: currentPicture.id,
|
||||
bbox: sel.mode === 'rect' ? (sel.bbox ?? null) : null,
|
||||
polygon: sel.mode === 'polygon' ? (sel.polygon ?? null) : null,
|
||||
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)
|
||||
newObjs.push({ ...obj, visible: true })
|
||||
}
|
||||
setObjects(prev => [...prev, ...newObjs])
|
||||
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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user