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
@@ -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 && (
|
||||
|
||||
Reference in new issue
Block a user