feat: BLS-Stammdaten, FDDB-Mapping und Item-Tagebuch (#106)
Katalog, lernendes Mapping ohne KI, optionale Items und Import-Policy. Playwright-Smoke und Issue-Audit um Ernährung/Zuordnen/API ergänzt. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
72d101415f
commit
919c77fcf8
39 files changed
+2648
-47
No files matched your search
@@ -57,6 +57,14 @@ import CustomGoalsPage from './pages/CustomGoalsPage'
|
||||
import UniversalCsvImportPage from './pages/UniversalCsvImportPage'
|
||||
import AdminCsvTemplatesPage from './pages/AdminCsvTemplatesPage'
|
||||
import AdminCsvTemplateEditorPage from './pages/AdminCsvTemplateEditorPage'
|
||||
import AdminBlsImportPage from './pages/AdminBlsImportPage'
|
||||
import AdminBlsFoodsPage from './pages/AdminBlsFoodsPage'
|
||||
import AdminFoodMappingsPage from './pages/AdminFoodMappingsPage'
|
||||
import AdminFoodAttributesPage from './pages/AdminFoodAttributesPage'
|
||||
import AdminBlsImportPage from './pages/AdminBlsImportPage'
|
||||
import AdminBlsFoodsPage from './pages/AdminBlsFoodsPage'
|
||||
import AdminFoodMappingsPage from './pages/AdminFoodMappingsPage'
|
||||
import AdminFoodAttributesPage from './pages/AdminFoodAttributesPage'
|
||||
import WorkflowEditorPage from './pages/WorkflowEditorPage'
|
||||
import DesktopSidebar from './components/DesktopSidebar'
|
||||
import { getMainNavItems } from './config/appNav'
|
||||
@@ -267,6 +275,10 @@ function AppShell() {
|
||||
<Route path="reference-value-types" element={<AdminReferenceValueTypesPage/>}/>
|
||||
<Route path="csv-templates" element={<AdminCsvTemplatesPage />} />
|
||||
<Route path="csv-templates/:id" element={<AdminCsvTemplateEditorPage />} />
|
||||
<Route path="bls-import" element={<AdminBlsImportPage />} />
|
||||
<Route path="bls-foods" element={<AdminBlsFoodsPage />} />
|
||||
<Route path="food-attributes" element={<AdminFoodAttributesPage />} />
|
||||
<Route path="food-mappings" element={<AdminFoodMappingsPage />} />
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path="/workflow-editor/:id" element={<WorkflowEditorPage/>}/>
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
|
||||
export default function NutritionFoodMap({ onChanged }) {
|
||||
const [unmapped, setUnmapped] = useState([])
|
||||
const [learned, setLearned] = useState([])
|
||||
const [error, setError] = useState(null)
|
||||
const [query, setQuery] = useState({})
|
||||
const [hits, setHits] = useState({})
|
||||
const [saving, setSaving] = useState(null)
|
||||
|
||||
const load = async () => {
|
||||
try {
|
||||
const [u, m] = await Promise.all([api.listUnmappedFoods(), api.listMyFoodMappings()])
|
||||
setUnmapped(u)
|
||||
setLearned(m)
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => { load() }, [])
|
||||
|
||||
const search = async (key, q) => {
|
||||
setQuery((s) => ({ ...s, [key]: q }))
|
||||
if (!q || q.length < 2) {
|
||||
setHits((s) => ({ ...s, [key]: [] }))
|
||||
return
|
||||
}
|
||||
try {
|
||||
const rows = await api.searchBlsFoods(q)
|
||||
setHits((s) => ({ ...s, [key]: rows }))
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const assign = async (sourceName, foodId, key) => {
|
||||
setSaving(key)
|
||||
setError(null)
|
||||
try {
|
||||
await api.upsertMyFoodMapping({ source_name: sourceName, food_id: foodId })
|
||||
setHits((s) => ({ ...s, [key]: [] }))
|
||||
await load()
|
||||
onChanged?.()
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
} finally {
|
||||
setSaving(null)
|
||||
}
|
||||
}
|
||||
|
||||
const remove = async (id) => {
|
||||
if (!confirm('Zuordnung wirklich löschen?')) return
|
||||
try {
|
||||
await api.deleteMyFoodMapping(id)
|
||||
await load()
|
||||
onChanged?.()
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card section-gap">
|
||||
<div className="card-title">Lebensmittel zuordnen</div>
|
||||
<p style={{ fontSize: 13, color: 'var(--text2)', lineHeight: 1.6, marginBottom: 12 }}>
|
||||
Einmal bestätigt, bleibt die Zuordnung erhalten und gilt für spätere Importe.
|
||||
Du kannst sie jederzeit ändern oder löschen. Keine automatische KI-Zuordnung.
|
||||
</p>
|
||||
{error && <div style={{ color: 'var(--danger)', fontSize: 13, marginBottom: 10 }}>{error}</div>}
|
||||
|
||||
<h3 style={{ fontSize: 14, margin: '12px 0 8px' }}>Offen ({unmapped.length})</h3>
|
||||
{unmapped.length === 0 && <p className="muted">Keine ungemappten Bezeichner.</p>}
|
||||
{unmapped.map((u) => {
|
||||
const key = u.source_name_normalized
|
||||
return (
|
||||
<div key={key} style={{ borderTop: '1px solid var(--border)', padding: '10px 0' }}>
|
||||
<div style={{ fontWeight: 600 }}>{u.source_name_raw}</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text3)' }}>
|
||||
{u.count}× · {u.first_date} – {u.last_date}
|
||||
</div>
|
||||
<input
|
||||
className="form-input"
|
||||
style={{ marginTop: 6 }}
|
||||
placeholder="BLS-Code oder Name suchen…"
|
||||
value={query[key] || ''}
|
||||
onChange={(e) => search(key, e.target.value)}
|
||||
/>
|
||||
{(hits[key] || []).map((h) => (
|
||||
<button
|
||||
key={h.id}
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
style={{ marginTop: 6, marginRight: 6 }}
|
||||
disabled={saving === key}
|
||||
onClick={() => assign(u.source_name_raw, h.id, key)}
|
||||
>
|
||||
{h.bls_code ? `${h.bls_code} · ` : ''}{h.name_de}
|
||||
{h.catalog_kind !== 'official_bls' ? ' (manuell)' : ''}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
<h3 style={{ fontSize: 14, margin: '20px 0 8px' }}>Gelernt ({learned.length})</h3>
|
||||
{learned.map((m) => (
|
||||
<div key={m.id} style={{ display: 'flex', justifyContent: 'space-between', gap: 8, padding: '8px 0', borderTop: '1px solid var(--border)' }}>
|
||||
<div>
|
||||
<div style={{ fontWeight: 500 }}>{m.source_name_raw}</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text3)' }}>
|
||||
→ {m.bls_code ? `${m.bls_code} · ` : ''}{m.food_name_de}
|
||||
{m.catalog_kind !== 'official_bls' ? ' (manuell)' : ''}
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" className="btn btn-secondary" onClick={() => remove(m.id)}>Löschen</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function DayMarkButtons({ date, markType, onChanged }) {
|
||||
const setMark = async (type) => {
|
||||
try {
|
||||
if (markType === type) await api.deleteNutritionDayMark(date)
|
||||
else await api.putNutritionDayMark(date, { mark_type: type })
|
||||
onChanged?.()
|
||||
} catch (e) {
|
||||
alert(e.message)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<span style={{ display: 'inline-flex', gap: 4 }}>
|
||||
<button type="button" className="btn btn-secondary" style={{ fontSize: 11, padding: '4px 8px' }} onClick={() => setMark('fasting')}>
|
||||
{markType === 'fasting' ? '✓ Fasten' : 'Fasten'}
|
||||
</button>
|
||||
<button type="button" className="btn btn-secondary" style={{ fontSize: 11, padding: '4px 8px' }} onClick={() => setMark('incomplete')}>
|
||||
{markType === 'incomplete' ? '✓ Lücke' : 'Lücke'}
|
||||
</button>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -115,6 +115,33 @@ export const ADMIN_GROUPS = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'nutrition',
|
||||
label: 'Ernährung',
|
||||
description: 'BLS-Stammdaten, Attribute und FDDB-Mappings.',
|
||||
items: [
|
||||
{
|
||||
to: '/admin/bls-import',
|
||||
label: 'BLS importieren',
|
||||
description: 'Offizielle BLS-4.0-XLSX (Components + Daten).',
|
||||
},
|
||||
{
|
||||
to: '/admin/bls-foods',
|
||||
label: 'Lebensmittelkatalog',
|
||||
description: 'Suche inkl. BLS-Code, manuelle Einträge.',
|
||||
},
|
||||
{
|
||||
to: '/admin/food-attributes',
|
||||
label: 'Stoffe & Attribute',
|
||||
description: 'BLS-Komponenten und Erweiterungen (Histamin, Gluten).',
|
||||
},
|
||||
{
|
||||
to: '/admin/food-mappings',
|
||||
label: 'FDDB-Mappings',
|
||||
description: 'Globale Standardzuordnungen und Coverage.',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'system',
|
||||
label: 'Basiseinstellungen',
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { useState } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
|
||||
export default function AdminBlsFoodsPage() {
|
||||
const [q, setQ] = useState('')
|
||||
const [rows, setRows] = useState([])
|
||||
const [detail, setDetail] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const search = async () => {
|
||||
try {
|
||||
setRows(await api.adminBlsFoods(q))
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card">
|
||||
<h1 className="page-title">Lebensmittelkatalog</h1>
|
||||
{error && <p style={{ color: 'var(--danger)' }}>{error}</p>}
|
||||
<div className="form-row">
|
||||
<input className="form-input" value={q} onChange={(e) => setQ(e.target.value)} placeholder="Name oder BLS-Code" />
|
||||
<button type="button" className="btn btn-primary" onClick={search}>Suchen</button>
|
||||
</div>
|
||||
{rows.map((r) => (
|
||||
<button
|
||||
key={r.id}
|
||||
type="button"
|
||||
className="btn btn-secondary btn-full"
|
||||
style={{ marginTop: 6, textAlign: 'left' }}
|
||||
onClick={() => api.adminBlsFoodDetail(r.id).then(setDetail).catch((e) => setError(e.message))}
|
||||
>
|
||||
{r.bls_code ? `${r.bls_code} · ` : ''}{r.name_de}
|
||||
{r.catalog_kind !== 'official_bls' ? ' · manuell' : ''}
|
||||
</button>
|
||||
))}
|
||||
{detail && (
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<h3>{detail.bls_code} {detail.name_de}</h3>
|
||||
<p style={{ fontSize: 12, color: 'var(--text3)' }}>{detail.catalog_kind} · {detail.bls_version || '—'}</p>
|
||||
<table style={{ width: '100%', fontSize: 12 }}>
|
||||
<tbody>
|
||||
{(detail.attributes || []).filter((a) => a.value_num != null || a.is_trace).slice(0, 40).map((a) => (
|
||||
<tr key={a.attr_key}>
|
||||
<td>{a.attr_key}</td>
|
||||
<td>{a.name_de}</td>
|
||||
<td>{a.is_trace ? 'Spuren' : a.value_num} {a.unit || ''}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
|
||||
export default function AdminBlsImportPage() {
|
||||
const [status, setStatus] = useState(null)
|
||||
const [msg, setMsg] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const load = () => {
|
||||
api.adminBlsStatus().then(setStatus).catch((e) => setError(e.message))
|
||||
}
|
||||
useEffect(() => { load() }, [])
|
||||
|
||||
const run = async (kind, file, dry) => {
|
||||
setError(null)
|
||||
setMsg(dry ? 'Prüfe…' : 'Importiere…')
|
||||
try {
|
||||
const fn = kind === 'components' ? api.adminBlsImportComponents : api.adminBlsImportFoods
|
||||
const res = await fn(file, dry)
|
||||
setMsg(JSON.stringify(res, null, 2))
|
||||
if (!dry) load()
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
setMsg(null)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card">
|
||||
<h1 className="page-title">BLS 4.0 importieren</h1>
|
||||
<p style={{ fontSize: 13, color: 'var(--text2)', lineHeight: 1.6 }}>
|
||||
Offizielle Dateien von blsdb.de (frei verfügbar, MRI). Codes bleiben erhalten.
|
||||
Zuerst Components, dann die Datendatei. Immer zuerst „Prüfen“.
|
||||
</p>
|
||||
{status && (
|
||||
<p style={{ fontSize: 13 }}>
|
||||
{status.official_foods} offizielle Lebensmittel · {status.official_attributes} Stoffe ·
|
||||
{status.manual_foods} manuell · {status.source}
|
||||
</p>
|
||||
)}
|
||||
{error && <p style={{ color: 'var(--danger)' }}>{error}</p>}
|
||||
<div className="form-row" style={{ marginTop: 16 }}>
|
||||
<label className="form-label">Components XLSX</label>
|
||||
<input type="file" accept=".xlsx" onChange={(e) => e.target.files[0] && run('components', e.target.files[0], true)} />
|
||||
<input type="file" accept=".xlsx" onChange={(e) => e.target.files[0] && run('components', e.target.files[0], false)} />
|
||||
</div>
|
||||
<p style={{ fontSize: 12, color: 'var(--text3)' }}>Erstes Feld = prüfen, zweites = anwenden.</p>
|
||||
<div className="form-row">
|
||||
<label className="form-label">Daten XLSX</label>
|
||||
<input type="file" accept=".xlsx" onChange={(e) => e.target.files[0] && run('foods', e.target.files[0], true)} />
|
||||
<input type="file" accept=".xlsx" onChange={(e) => e.target.files[0] && run('foods', e.target.files[0], false)} />
|
||||
</div>
|
||||
{msg && <pre style={{ whiteSpace: 'pre-wrap', fontSize: 12, background: 'var(--surface2)', padding: 12, borderRadius: 8 }}>{msg}</pre>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
|
||||
export default function AdminFoodAttributesPage() {
|
||||
const [rows, setRows] = useState([])
|
||||
const [form, setForm] = useState({ attr_key: '', name_de: '', unit: '', data_type: 'num_per_100g' })
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const load = () => api.adminBlsAttributes().then(setRows).catch((e) => setError(e.message))
|
||||
useEffect(() => { load() }, [])
|
||||
|
||||
return (
|
||||
<div className="card">
|
||||
<h1 className="page-title">Stoffe & Attribute</h1>
|
||||
<p style={{ fontSize: 13, color: 'var(--text2)' }}>
|
||||
Offizielle BLS-Codes kommen aus dem Import. Erweiterungen (Histamin, Gluten, …) hier anlegen — ohne Migration.
|
||||
</p>
|
||||
{error && <p style={{ color: 'var(--danger)' }}>{error}</p>}
|
||||
<div className="form-row">
|
||||
<input className="form-input" placeholder="KEY" value={form.attr_key} onChange={(e) => setForm({ ...form, attr_key: e.target.value })} />
|
||||
<input className="form-input" placeholder="Name DE" value={form.name_de} onChange={(e) => setForm({ ...form, name_de: e.target.value })} />
|
||||
<input className="form-input" placeholder="Einheit" value={form.unit} onChange={(e) => setForm({ ...form, unit: e.target.value })} />
|
||||
<select className="form-input" value={form.data_type} onChange={(e) => setForm({ ...form, data_type: e.target.value })}>
|
||||
<option value="num_per_100g">Zahl / 100g</option>
|
||||
<option value="boolean">Ja/Nein</option>
|
||||
<option value="text">Text</option>
|
||||
<option value="enum">Auswahl</option>
|
||||
</select>
|
||||
<button type="button" className="btn btn-primary" onClick={async () => {
|
||||
try {
|
||||
await api.adminCreateBlsAttribute(form)
|
||||
setForm({ attr_key: '', name_de: '', unit: '', data_type: 'num_per_100g' })
|
||||
load()
|
||||
} catch (e) { setError(e.message) }
|
||||
}}>Anlegen</button>
|
||||
</div>
|
||||
{rows.map((r) => (
|
||||
<div key={r.id} style={{ fontSize: 13, padding: '6px 0', borderTop: '1px solid var(--border)' }}>
|
||||
<strong>{r.attr_key}</strong> · {r.name_de} · {r.data_type} · {r.origin}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
|
||||
export default function AdminFoodMappingsPage() {
|
||||
const [rows, setRows] = useState([])
|
||||
const [coverage, setCoverage] = useState(null)
|
||||
const [name, setName] = useState('')
|
||||
const [foodQ, setFoodQ] = useState('')
|
||||
const [hits, setHits] = useState([])
|
||||
const [foodId, setFoodId] = useState('')
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const load = () => {
|
||||
Promise.all([api.adminListFoodMappings(false), api.adminFoodMappingCoverage()])
|
||||
.then(([m, c]) => { setRows(m); setCoverage(c) })
|
||||
.catch((e) => setError(e.message))
|
||||
}
|
||||
useEffect(() => { load() }, [])
|
||||
|
||||
return (
|
||||
<div className="card">
|
||||
<h1 className="page-title">FDDB→BLS Mappings</h1>
|
||||
{error && <p style={{ color: 'var(--danger)' }}>{error}</p>}
|
||||
{coverage && (
|
||||
<p style={{ fontSize: 13 }}>
|
||||
{coverage.mapped_items}/{coverage.total_items} Zeilen gemappt ·
|
||||
{coverage.unmapped_names} ungemappte Namen
|
||||
</p>
|
||||
)}
|
||||
<div className="form-row">
|
||||
<input className="form-input" placeholder="FDDB-Bezeichner" value={name} onChange={(e) => setName(e.target.value)} />
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<input className="form-input" placeholder="Lebensmittel suchen" value={foodQ} onChange={async (e) => {
|
||||
setFoodQ(e.target.value)
|
||||
if (e.target.value.length > 1) setHits(await api.searchBlsFoods(e.target.value))
|
||||
}} />
|
||||
</div>
|
||||
{hits.map((h) => (
|
||||
<button key={h.id} type="button" className="btn btn-secondary" style={{ margin: 4 }} onClick={() => { setFoodId(h.id); setFoodQ(h.name_de) }}>
|
||||
{h.bls_code} {h.name_de}
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary"
|
||||
disabled={!name || !foodId}
|
||||
onClick={async () => {
|
||||
try {
|
||||
await api.adminCreateFoodMapping({ source_name: name, food_id: foodId })
|
||||
setName(''); setFoodId(''); setFoodQ(''); load()
|
||||
} catch (e) { setError(e.message) }
|
||||
}}
|
||||
>
|
||||
Globales Mapping anlegen
|
||||
</button>
|
||||
{rows.map((r) => (
|
||||
<div key={r.id} style={{ display: 'flex', justifyContent: 'space-between', padding: '8px 0', borderTop: '1px solid var(--border)' }}>
|
||||
<div>
|
||||
{r.source_name_raw} → {r.bls_code} {r.food_name_de}
|
||||
<div style={{ fontSize: 11, color: 'var(--text3)' }}>{r.profile_id ? 'user' : 'global'}</div>
|
||||
</div>
|
||||
<button type="button" className="btn btn-secondary" onClick={async () => { await api.adminDeleteFoodMapping(r.id); load() }}>Löschen</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { Upload, CheckCircle, TrendingUp, Info } from 'lucide-react'
|
||||
import UsageBadge from '../components/UsageBadge'
|
||||
import NutritionFoodMap, { DayMarkButtons } from '../components/NutritionFoodMap'
|
||||
import {
|
||||
LineChart, Line, BarChart, Bar, XAxis, YAxis, Tooltip,
|
||||
ResponsiveContainer, CartesianGrid, Legend, ReferenceLine, ScatterChart, Scatter
|
||||
@@ -324,9 +325,13 @@ function DataTab({ entries, onUpdate }) {
|
||||
</div>
|
||||
{e.source && (
|
||||
<div style={{fontSize:10, color:'var(--text3)', marginTop:4}}>
|
||||
Quelle: {e.source}
|
||||
Quelle: {e.source}{e.macro_origin ? ` · Makros: ${e.macro_origin}` : ''}
|
||||
{e.mark_type ? ` · ${e.mark_type === 'fasting' ? 'Fastentag' : 'unvollständig'}` : ''}
|
||||
</div>
|
||||
)}
|
||||
<div style={{marginTop:8}}>
|
||||
<DayMarkButtons date={e.date} markType={e.mark_type} onChanged={onUpdate} />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
@@ -441,15 +446,18 @@ function ImportPanel({ onImported, usage = null }) {
|
||||
const [dragging,setDragging]= useState(false)
|
||||
const [tab, setTab] = useState('file') // 'file' | 'paste'
|
||||
const [pasteText, setPasteText] = useState('')
|
||||
const [overwrite, setOverwrite] = useState(false)
|
||||
const [conflicts, setConflicts] = useState([])
|
||||
const atLimit = usage && !usage.allowed
|
||||
|
||||
const runImport = async (file) => {
|
||||
if (atLimit) return
|
||||
setStatus('loading'); setError(null)
|
||||
setStatus('loading'); setError(null); setConflicts([])
|
||||
try {
|
||||
const result = await nutritionApi.importCsv(file)
|
||||
const result = await nutritionApi.importCsv(file, overwrite)
|
||||
if (result.days_imported === undefined) throw new Error(JSON.stringify(result))
|
||||
setStatus(result)
|
||||
setConflicts(result.conflicts || [])
|
||||
onImported()
|
||||
} catch(err) {
|
||||
setError('Import fehlgeschlagen: ' + err.message)
|
||||
@@ -485,7 +493,12 @@ function ImportPanel({ onImported, usage = null }) {
|
||||
</div>
|
||||
<p style={{fontSize:13,color:'var(--text2)',marginBottom:10,lineHeight:1.6}}>
|
||||
In FDDB: <strong>Mein Tagebuch → Exportieren → CSV</strong> — dann hier importieren.
|
||||
Zeilen (Name, Menge, Uhrzeit) werden gespeichert, wenn die CSV sie enthält.
|
||||
</p>
|
||||
<label style={{display:'flex',alignItems:'center',gap:8,fontSize:13,marginBottom:10}}>
|
||||
<input type="checkbox" checked={overwrite} onChange={(e)=>setOverwrite(e.target.checked)} />
|
||||
Vorhandene Tagesmakros überschreiben (Initialimport)
|
||||
</label>
|
||||
|
||||
{/* Tab switcher */}
|
||||
<div style={{display:'flex',gap:6,marginBottom:12}}>
|
||||
@@ -567,7 +580,7 @@ function ImportPanel({ onImported, usage = null }) {
|
||||
<div style={{display:'flex',alignItems:'center',gap:6,marginBottom:4}}>
|
||||
<CheckCircle size={15}/><strong>Import erfolgreich</strong>
|
||||
</div>
|
||||
<div>{status.days_imported} Tage importiert · {status.rows_parsed} Einträge verarbeitet</div>
|
||||
<div>{status.days_imported} Tage · {status.rows_parsed} Zeilen{status.items_written ? ` · ${status.items_written} Items` : ''}</div>
|
||||
{status.date_range?.from && (
|
||||
<div style={{fontSize:11,marginTop:2}}>
|
||||
{dayjs(status.date_range.from).format('DD.MM.YYYY')} – {dayjs(status.date_range.to).format('DD.MM.YYYY')}
|
||||
@@ -575,6 +588,45 @@ function ImportPanel({ onImported, usage = null }) {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{conflicts.length > 0 && (
|
||||
<ConflictDialog conflicts={conflicts} onDone={() => { setConflicts([]); onImported() }} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ConflictDialog({ conflicts, onDone }) {
|
||||
const [choices, setChoices] = useState({})
|
||||
const [busy, setBusy] = useState(false)
|
||||
const setC = (date, choice) => setChoices((s) => ({ ...s, [date]: choice }))
|
||||
const save = async () => {
|
||||
setBusy(true)
|
||||
try {
|
||||
const decisions = conflicts.map((c) => ({ date: c.date, choice: choices[c.date] || 'existing' }))
|
||||
await nutritionApi.resolveNutritionConflicts(decisions)
|
||||
onDone()
|
||||
} catch (e) {
|
||||
alert(e.message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div style={{marginTop:12,padding:12,border:'1px solid var(--border)',borderRadius:8}}>
|
||||
<strong>Abweichende Tagesmakros</strong>
|
||||
{conflicts.map((c) => (
|
||||
<div key={c.date} style={{marginTop:10,fontSize:12}}>
|
||||
<div>{c.date}</div>
|
||||
<div>Ist {c.existing?.kcal} · FDDB {c.fddb?.kcal} · Katalog {c.catalog?.kcal} kcal</div>
|
||||
{['existing','fddb','catalog'].map((k) => (
|
||||
<label key={k} style={{marginRight:10}}>
|
||||
<input type="radio" name={`c-${c.date}`} checked={(choices[c.date]||'existing')===k} onChange={()=>setC(c.date,k)} />
|
||||
{k === 'existing' ? 'behalten' : k === 'fddb' ? 'FDDB' : 'Katalog'}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
<button type="button" className="btn btn-primary" style={{marginTop:10}} disabled={busy} onClick={save}>Übernehmen</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -837,6 +889,9 @@ export default function NutritionPage() {
|
||||
<button className={'tab'+(inputTab==='import'?' active':'')} onClick={()=>setInputTab('import')}>
|
||||
📥 Import
|
||||
</button>
|
||||
<button className={'tab'+(inputTab==='map'?' active':'')} onClick={()=>setInputTab('map')}>
|
||||
Zuordnen
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Entry Form */}
|
||||
@@ -853,6 +908,8 @@ export default function NutritionPage() {
|
||||
</>
|
||||
)}
|
||||
|
||||
{inputTab==='map' && <NutritionFoodMap onChanged={load} />}
|
||||
|
||||
{loading && <div className="empty-state"><div className="spinner"/></div>}
|
||||
|
||||
{!loading && !hasData && (
|
||||
|
||||
@@ -458,6 +458,33 @@ export default function SettingsPage() {
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="card section-gap">
|
||||
<div className="card-title">Ernährungs-Import</div>
|
||||
<p style={{ fontSize: 13, color: 'var(--text2)', marginBottom: 12, lineHeight: 1.6 }}>
|
||||
Wenn für einen Tag schon Makros existieren: nachfragen, Katalog-/FDDB-Summe schreiben oder die bestehenden Werte behalten.
|
||||
Für den einmaligen FDDB-Reimport kannst du auch die Checkbox am Import nutzen.
|
||||
</p>
|
||||
<select
|
||||
className="form-input"
|
||||
value={activeProfile?.nutrition_import_conflict_policy || 'prompt'}
|
||||
onChange={async (e) => {
|
||||
try {
|
||||
await api.updateActiveProfile({ nutrition_import_conflict_policy: e.target.value })
|
||||
await refreshProfiles()
|
||||
setSaved(true)
|
||||
setTimeout(() => setSaved(false), 2000)
|
||||
} catch (err) {
|
||||
setProfileErr(err.message)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<option value="prompt">Bei Abweichung nachfragen</option>
|
||||
<option value="overwrite_catalog">Immer Katalog-/BLS-Summe</option>
|
||||
<option value="overwrite_fddb">Immer FDDB-Rohsumme</option>
|
||||
<option value="keep_existing">Bestehende Makros behalten</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Auth actions */}
|
||||
<div className="card section-gap">
|
||||
<div className="card-title">🔐 Konto</div>
|
||||
|
||||
@@ -210,11 +210,43 @@ export const api = {
|
||||
},
|
||||
|
||||
// Nutrition
|
||||
importCsv: async(file)=>{
|
||||
importCsv: async(file, overwriteExisting=false)=>{
|
||||
const fd=new FormData();fd.append('file',file)
|
||||
const r=await fetch(`${BASE}/nutrition/import-csv`,{method:'POST',body:fd,headers:hdrs()})
|
||||
const qs = overwriteExisting ? '?overwrite_existing=true' : ''
|
||||
const r=await fetch(`${BASE}/nutrition/import-csv${qs}`,{method:'POST',body:fd,headers:hdrs()})
|
||||
const d=await r.json();if(!r.ok)throw new Error(formatFastApiDetail(d.detail, JSON.stringify(d)));return d
|
||||
},
|
||||
listNutritionItems: (date) => req(date ? `/nutrition/items?date=${date}` : '/nutrition/items'),
|
||||
listUnmappedFoods: () => req('/nutrition/unmapped'),
|
||||
listNutritionMarks: () => req('/nutrition/marks'),
|
||||
putNutritionDayMark: (date, d) => req(`/nutrition/days/${date}/mark`, jput(d)),
|
||||
deleteNutritionDayMark: (date) => req(`/nutrition/days/${date}/mark`, {method:'DELETE'}),
|
||||
resolveNutritionConflicts: (decisions) => req('/nutrition/import-conflicts/resolve', json({decisions})),
|
||||
searchBlsFoods: (q, limit=20) => req(`/bls/foods?q=${encodeURIComponent(q||'')}&limit=${limit}`),
|
||||
createUserFood: (d) => req('/bls/foods/manual', json(d)),
|
||||
listMyFoodMappings: () => req('/bls/mappings'),
|
||||
upsertMyFoodMapping: (d) => req('/bls/mappings', json(d)),
|
||||
deleteMyFoodMapping: (id) => req(`/bls/mappings/${id}`, {method:'DELETE'}),
|
||||
adminBlsStatus: () => req('/admin/bls/status'),
|
||||
adminBlsImportComponents: async (file, dryRun=true) => {
|
||||
const fd=new FormData();fd.append('file',file)
|
||||
const r=await fetch(`${BASE}/admin/bls/import/components?dry_run=${dryRun}`,{method:'POST',body:fd,headers:hdrs()})
|
||||
const d=await r.json();if(!r.ok)throw new Error(formatFastApiDetail(d.detail, JSON.stringify(d)));return d
|
||||
},
|
||||
adminBlsImportFoods: async (file, dryRun=true) => {
|
||||
const fd=new FormData();fd.append('file',file)
|
||||
const r=await fetch(`${BASE}/admin/bls/import/foods?dry_run=${dryRun}`,{method:'POST',body:fd,headers:hdrs()})
|
||||
const d=await r.json();if(!r.ok)throw new Error(formatFastApiDetail(d.detail, JSON.stringify(d)));return d
|
||||
},
|
||||
adminBlsFoods: (q, kind) => req(`/admin/bls/foods?${q?('q='+encodeURIComponent(q)+'&'):''}${kind?('kind='+kind):''}`),
|
||||
adminBlsFoodDetail: (id) => req(`/admin/bls/foods/${id}`),
|
||||
adminCreateManualFood: (d) => req('/admin/bls/foods/manual', json(d)),
|
||||
adminBlsAttributes: () => req('/admin/bls/attributes'),
|
||||
adminCreateBlsAttribute: (d) => req('/admin/bls/attributes', json(d)),
|
||||
adminListFoodMappings: (globalOnly) => req(`/admin/food-mappings${globalOnly?'?global_only=true':''}`),
|
||||
adminCreateFoodMapping: (d) => req('/admin/food-mappings', json(d)),
|
||||
adminDeleteFoodMapping: (id) => req(`/admin/food-mappings/${id}`, {method:'DELETE'}),
|
||||
adminFoodMappingCoverage: () => req('/admin/food-mappings/stats/coverage'),
|
||||
listNutrition: (l=365) => req(`/nutrition?limit=${l}`),
|
||||
nutritionCorrelations: () => req('/nutrition/correlations'),
|
||||
nutritionWeekly: (w=16) => req(`/nutrition/weekly?weeks=${w}`),
|
||||
|
||||
Reference in new issue
Block a user