fix: FDDB-Zeilen im CSV-Import speichern und in Ernährung zeigen
Bezeichnung/Menge auch ohne Vorlagen-Mapping, Zuordnen-Hinweis, Tagesliste mit Lebensmitteln. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a07a668de2
commit
4b1be3019d
7 files changed
+141
-5
No files matched your search
@@ -195,6 +195,49 @@ function EntryForm({ onSaved }) {
|
||||
}
|
||||
|
||||
// ── Data Tab (Editable Entry List) ───────────────────────────────────────────
|
||||
function DayItems({ date }) {
|
||||
const [items, setItems] = useState(null)
|
||||
const [open, setOpen] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const toggle = async () => {
|
||||
if (open) {
|
||||
setOpen(false)
|
||||
return
|
||||
}
|
||||
if (!items) {
|
||||
try {
|
||||
setItems(await nutritionApi.listNutritionItems(date))
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
return
|
||||
}
|
||||
}
|
||||
setOpen(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<button type="button" className="btn btn-secondary" style={{ fontSize: 12 }} onClick={toggle}>
|
||||
{open ? 'Lebensmittel ausblenden' : 'Lebensmittel zeigen'}
|
||||
</button>
|
||||
{error && <p style={{ color: 'var(--danger)', fontSize: 12, margin: '6px 0 0' }}>{error}</p>}
|
||||
{open && Array.isArray(items) && (
|
||||
<ul style={{ margin: '8px 0 0', paddingLeft: 18, fontSize: 13, color: 'var(--text1)' }}>
|
||||
{items.length === 0 && <li style={{ color: 'var(--text3)' }}>Keine Zeilen für diesen Tag</li>}
|
||||
{items.map((it) => (
|
||||
<li key={it.id}>
|
||||
{it.source_name_raw}
|
||||
{it.quantity_raw ? ` · ${it.quantity_raw}` : ''}
|
||||
{it.food_name_de ? ` → ${it.food_name_de}` : ' · noch nicht zugeordnet'}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function DataTab({ entries, onUpdate }) {
|
||||
const [editId, setEditId] = useState(null)
|
||||
const [editValues, setEditValues] = useState({})
|
||||
@@ -327,8 +370,14 @@ function DataTab({ entries, onUpdate }) {
|
||||
<div style={{fontSize:10, color:'var(--text3)', marginTop:4}}>
|
||||
Quelle: {e.source}{e.macro_origin ? ` · Makros: ${e.macro_origin}` : ''}
|
||||
{e.mark_type ? ` · ${e.mark_type === 'fasting' ? 'Fastentag' : 'unvollständig'}` : ''}
|
||||
{e.item_count ? ` · ${e.item_count} Lebensmittel` : ''}
|
||||
</div>
|
||||
)}
|
||||
{e.item_count > 0 ? (
|
||||
<DayItems date={e.date} />
|
||||
) : (
|
||||
<div style={{fontSize:12, color:'var(--text3)', marginTop:6}}>Keine einzelnen Lebensmittelzeilen</div>
|
||||
)}
|
||||
<div style={{marginTop:8}}>
|
||||
<DayMarkButtons date={e.date} markType={e.mark_type} onChanged={onUpdate} />
|
||||
</div>
|
||||
@@ -849,6 +898,7 @@ export default function NutritionPage() {
|
||||
const [hasData, setHasData]= useState(false)
|
||||
const [importHistoryKey, setImportHistoryKey] = useState(Date.now()) // BUG-004 fix
|
||||
const [nutritionUsage, setNutritionUsage] = useState(null)
|
||||
const [unmappedCount, setUnmappedCount] = useState(0)
|
||||
|
||||
const loadUsage = () => {
|
||||
nutritionApi.getFeatureUsage().then(features => {
|
||||
@@ -860,16 +910,18 @@ export default function NutritionPage() {
|
||||
const load = async () => {
|
||||
setLoad(true)
|
||||
try {
|
||||
const [corr, wkly, ent, prof] = await Promise.all([
|
||||
const [corr, wkly, ent, prof, unmapped] = await Promise.all([
|
||||
nutritionApi.nutritionCorrelations(),
|
||||
nutritionApi.nutritionWeekly(16),
|
||||
nutritionApi.listNutrition(365), // BUG-002 fix: load raw entries
|
||||
nutritionApi.getActiveProfile(),
|
||||
nutritionApi.listUnmappedFoods().catch(() => []),
|
||||
])
|
||||
setCorr(Array.isArray(corr)?corr:[])
|
||||
setWeekly(Array.isArray(wkly)?wkly:[])
|
||||
setEntries(Array.isArray(ent)?ent:[]) // BUG-002 fix
|
||||
setProf(prof)
|
||||
setUnmappedCount(Array.isArray(unmapped) ? unmapped.length : 0)
|
||||
setHasData(Array.isArray(corr) && corr.some(d=>d.kcal))
|
||||
} catch(e) { console.error('load error:', e) }
|
||||
finally { setLoad(false) }
|
||||
@@ -880,6 +932,14 @@ export default function NutritionPage() {
|
||||
return (
|
||||
<div className="capture-page">
|
||||
<h1 className="page-title">Ernährung</h1>
|
||||
{unmappedCount > 0 && (
|
||||
<div className="card" style={{ marginBottom: 12, padding: 12, fontSize: 13 }}>
|
||||
{unmappedCount} Lebensmittel noch ohne BLS-Zuordnung.{' '}
|
||||
<button type="button" className="btn btn-secondary" style={{ marginLeft: 8 }} onClick={() => setInputTab('map')}>
|
||||
Jetzt zuordnen
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Input Method Tabs */}
|
||||
<div className="tabs section-gap" style={{marginBottom:0}}>
|
||||
@@ -890,7 +950,7 @@ export default function NutritionPage() {
|
||||
📥 Import
|
||||
</button>
|
||||
<button className={'tab'+(inputTab==='map'?' active':'')} onClick={()=>setInputTab('map')}>
|
||||
Zuordnen
|
||||
Zuordnen{unmappedCount ? ` (${unmappedCount})` : ''}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -201,10 +201,14 @@ export default function UniversalCsvImportPage() {
|
||||
setLastImport(res)
|
||||
const st = res.stats || {}
|
||||
const modLabel = MODULE_LABEL[res.module] || res.module || ''
|
||||
const extra = []
|
||||
if (st.items_written) extra.push(`${st.items_written} Lebensmittelzeilen`)
|
||||
if (st.unmapped_names) extra.push(`${st.unmapped_names} noch ohne Zuordnung — Ernährung → Zuordnen`)
|
||||
setSuccess(
|
||||
(modLabel ? `${modLabel}: ` : '') +
|
||||
`Import fertig — ${st.imported ?? 0} neu, ${st.updated ?? 0} aktualisiert, ` +
|
||||
`${st.skipped ?? 0} übersprungen, ${st.errors ?? 0} Zeilenfehler.`,
|
||||
`${st.skipped ?? 0} übersprungen, ${st.errors ?? 0} Zeilenfehler.` +
|
||||
(extra.length ? ` ${extra.join(' · ')}.` : ''),
|
||||
)
|
||||
} catch (e) {
|
||||
setError(e.message || 'Import fehlgeschlagen')
|
||||
|
||||
Reference in new issue
Block a user