feat: Phase 1.5 - Flexible Goal System (DB-Registry) Part 2/2 - COMPLETE
Frontend dynamic goal types + Admin UI komplett implementiert. Frontend GoalsPage: - HARDCODED GOAL_TYPES entfernt - Dynamic loading von goal_type_definitions via API - goalTypes state + goalTypesMap für quick lookup - Dropdown zeigt alle aktiven Types aus DB - Vollständig flexibel - neue Types sofort verfügbar Admin UI: - AdminGoalTypesPage.jsx (400+ Zeilen) → Übersicht aller Goal Types (System + Custom) → Create/Edit/Delete Forms → CRUD via api.js (admin-only) → Validierung: System Types nur deaktivierbar, nicht löschbar → 8 Aggregationsmethoden im Dropdown → Category-Auswahl (body, mind, activity, nutrition, recovery, custom) - Route registriert: /admin/goal-types - Import in App.jsx Phase 1.5 KOMPLETT: ✅ Migration 024 (goal_type_definitions) ✅ Universal Value Fetcher (goal_utils.py) ✅ CRUD API (goals.py) ✅ Frontend Dynamic Dropdown (GoalsPage.jsx) ✅ Admin UI (AdminGoalTypesPage.jsx) System ist jetzt VOLLSTÄNDIG FLEXIBEL: - Neue Goal Types via Admin UI ohne Code-Deploy - Beispiele: Meditation, Trainingshäufigkeit, Planabweichung - Phase 0b Platzhalter können alle Types nutzen - Keine Doppelarbeit bei v2.0 Redesign Nächster Schritt: Testing + Phase 0b (120+ Platzhalter) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
65ee5f898f
commit
640ef81257
3 files changed
+476
-21
No files matched your search
@@ -44,21 +44,11 @@ const GOAL_MODES = [
|
||||
}
|
||||
]
|
||||
|
||||
// Goal Type Definitions
|
||||
const GOAL_TYPES = {
|
||||
weight: { label: 'Gewicht', unit: 'kg', icon: '⚖️' },
|
||||
body_fat: { label: 'Körperfett', unit: '%', icon: '📊' },
|
||||
lean_mass: { label: 'Muskelmasse', unit: 'kg', icon: '💪' },
|
||||
vo2max: { label: 'VO2Max', unit: 'ml/kg/min', icon: '🫁' },
|
||||
strength: { label: 'Kraft', unit: 'kg', icon: '🏋️' },
|
||||
flexibility: { label: 'Beweglichkeit', unit: 'cm', icon: '🤸' },
|
||||
bp: { label: 'Blutdruck', unit: 'mmHg', icon: '❤️' },
|
||||
rhr: { label: 'Ruhepuls', unit: 'bpm', icon: '💓' }
|
||||
}
|
||||
|
||||
export default function GoalsPage() {
|
||||
const [goalMode, setGoalMode] = useState(null)
|
||||
const [goals, setGoals] = useState([])
|
||||
const [goalTypes, setGoalTypes] = useState([]) // Dynamic from DB (Phase 1.5)
|
||||
const [goalTypesMap, setGoalTypesMap] = useState({}) // For quick lookup
|
||||
const [showGoalForm, setShowGoalForm] = useState(false)
|
||||
const [editingGoal, setEditingGoal] = useState(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
@@ -84,12 +74,28 @@ export default function GoalsPage() {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const [modeData, goalsData] = await Promise.all([
|
||||
const [modeData, goalsData, typesData] = await Promise.all([
|
||||
api.getGoalMode(),
|
||||
api.listGoals()
|
||||
api.listGoals(),
|
||||
api.listGoalTypeDefinitions() // Phase 1.5: Load from DB
|
||||
])
|
||||
setGoalMode(modeData.goal_mode)
|
||||
setGoals(goalsData)
|
||||
|
||||
// Convert types array to map for quick lookup
|
||||
const typesMap = {}
|
||||
typesData.forEach(type => {
|
||||
typesMap[type.type_key] = {
|
||||
label: type.label_de,
|
||||
unit: type.unit,
|
||||
icon: type.icon || '📊',
|
||||
category: type.category,
|
||||
is_system: type.is_system
|
||||
}
|
||||
})
|
||||
|
||||
setGoalTypes(typesData)
|
||||
setGoalTypesMap(typesMap)
|
||||
} catch (err) {
|
||||
console.error('Failed to load goals:', err)
|
||||
setError('Fehler beim Laden der Ziele')
|
||||
@@ -116,11 +122,12 @@ export default function GoalsPage() {
|
||||
|
||||
const handleCreateGoal = () => {
|
||||
setEditingGoal(null)
|
||||
const firstType = goalTypes.length > 0 ? goalTypes[0].type_key : 'weight'
|
||||
setFormData({
|
||||
goal_type: 'weight',
|
||||
goal_type: firstType,
|
||||
is_primary: goals.length === 0, // First goal is primary by default
|
||||
target_value: '',
|
||||
unit: GOAL_TYPES['weight'].unit,
|
||||
unit: goalTypesMap[firstType]?.unit || 'kg',
|
||||
target_date: '',
|
||||
name: '',
|
||||
description: ''
|
||||
@@ -146,7 +153,7 @@ export default function GoalsPage() {
|
||||
setFormData(f => ({
|
||||
...f,
|
||||
goal_type: type,
|
||||
unit: GOAL_TYPES[type].unit
|
||||
unit: goalTypesMap[type]?.unit || 'unit'
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -304,7 +311,7 @@ export default function GoalsPage() {
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
{goals.map(goal => {
|
||||
const typeInfo = GOAL_TYPES[goal.goal_type] || {}
|
||||
const typeInfo = goalTypesMap[goal.goal_type] || { label: goal.goal_type, unit: '', icon: '📊' }
|
||||
return (
|
||||
<div
|
||||
key={goal.id}
|
||||
@@ -489,9 +496,9 @@ export default function GoalsPage() {
|
||||
value={formData.goal_type}
|
||||
onChange={e => handleGoalTypeChange(e.target.value)}
|
||||
>
|
||||
{Object.entries(GOAL_TYPES).map(([key, info]) => (
|
||||
<option key={key} value={key}>
|
||||
{info.icon} {info.label}
|
||||
{goalTypes.map(type => (
|
||||
<option key={type.type_key} value={type.type_key}>
|
||||
{type.icon} {type.label_de}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
Reference in new issue
Block a user