feat: enhance exercise management with training types and rich text support
- Added support for training types in exercise creation and updates, allowing for better categorization of exercises. - Implemented a rich text editor for exercise descriptions, improving content formatting capabilities. - Updated the ExerciseDetailPage to display training types and enhanced the layout for better user experience. - Refactored ExerciseFormPage to accommodate new multi-association fields for training styles, types, and target groups. - Improved API payload handling to include training types and ensure proper data structure for exercise management. - Enhanced the ExercisesListPage with improved loading and filtering functionalities for better performance.
This commit is contained in:
1 parent
cb11e39201
commit
d8f439a3e5
8 files changed
+1198
-689
No files matched your search
+31
-14
@@ -4,6 +4,8 @@
|
||||
* Zentrale API-Kommunikation mit automatischer Token-Injektion
|
||||
*/
|
||||
|
||||
import { stripHtmlToText } from './htmlUtils'
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||
|
||||
/**
|
||||
@@ -219,19 +221,37 @@ export async function listExercises(filters = {}) {
|
||||
return request(`/api/exercises${query ? '?' + query : ''}`)
|
||||
}
|
||||
|
||||
/** Formular → API-Body (M:N gemäß EXERCISES_API_SPEC) */
|
||||
/** Formular → API-Body (M:N gemäß EXERCISES_API_SPEC + training_types) */
|
||||
export function buildExerciseApiPayload(formData) {
|
||||
const num = (v) => (v === '' || v == null ? null : Number(v))
|
||||
const goal = (formData.goal || '').trim()
|
||||
const execution = (formData.execution || '').trim()
|
||||
if (!goal && !execution) {
|
||||
throw new Error('Ziel oder Durchführung ausfüllen (mindestens eines).')
|
||||
|
||||
const goalHtml = formData.goal || ''
|
||||
const execHtml = formData.execution || ''
|
||||
const goalText = stripHtmlToText(goalHtml)
|
||||
const execText = stripHtmlToText(execHtml)
|
||||
|
||||
if (!goalText && !execText) {
|
||||
throw new Error('Ziel oder Durchführung ausfüllen (mindestens eines, auch mit Formatierung).')
|
||||
}
|
||||
|
||||
const mapFocus = (formData.focus_areas_multi || [])
|
||||
.filter((x) => x && x.focus_area_id)
|
||||
.map((x) => ({ focus_area_id: Number(x.focus_area_id), is_primary: !!x.is_primary }))
|
||||
const mapStyles = (formData.training_styles_multi || [])
|
||||
.filter((x) => x && x.training_style_id)
|
||||
.map((x) => ({ training_style_id: Number(x.training_style_id), is_primary: !!x.is_primary }))
|
||||
const mapTTypes = (formData.training_types_multi || [])
|
||||
.filter((x) => x && x.training_type_id)
|
||||
.map((x) => ({ training_type_id: Number(x.training_type_id), is_primary: !!x.is_primary }))
|
||||
const mapTg = (formData.target_groups_multi || [])
|
||||
.filter((x) => x && x.target_group_id)
|
||||
.map((x) => ({ target_group_id: Number(x.target_group_id), is_primary: !!x.is_primary }))
|
||||
|
||||
return {
|
||||
title: (formData.title || '').trim(),
|
||||
summary: formData.summary || null,
|
||||
goal: goal || null,
|
||||
execution: execution || null,
|
||||
goal: goalHtml.trim() ? goalHtml : null,
|
||||
execution: execHtml.trim() ? execHtml : null,
|
||||
preparation: formData.preparation || null,
|
||||
trainer_notes: formData.trainer_notes || null,
|
||||
duration_min: num(formData.duration_min),
|
||||
@@ -239,13 +259,10 @@ export function buildExerciseApiPayload(formData) {
|
||||
group_size_min: num(formData.group_size_min),
|
||||
group_size_max: num(formData.group_size_max),
|
||||
equipment: Array.isArray(formData.equipment) ? formData.equipment : [],
|
||||
focus_areas_multi: formData.focus_area_id
|
||||
? [{ focus_area_id: formData.focus_area_id, is_primary: true }]
|
||||
: [],
|
||||
training_styles_multi: formData.training_style_id
|
||||
? [{ training_style_id: formData.training_style_id, is_primary: true }]
|
||||
: [],
|
||||
target_groups_multi: [],
|
||||
focus_areas_multi: mapFocus,
|
||||
training_styles_multi: mapStyles,
|
||||
training_types_multi: mapTTypes,
|
||||
target_groups_multi: mapTg,
|
||||
age_groups: formData.age_groups || [],
|
||||
skills: (formData.skills || []).map((s) => ({
|
||||
skill_id: s.skill_id,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/** Einfache HTML-Hilfen für Rich-Text (Trainer-Content, kein öffentliches CMS). */
|
||||
|
||||
export function stripHtmlToText(html) {
|
||||
if (!html || typeof html !== 'string') return ''
|
||||
const d = document.createElement('div')
|
||||
d.innerHTML = html
|
||||
return (d.textContent || '').replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
|
||||
/** Entfernt script/iframes und Event-Handler-Attribute grob. */
|
||||
export function sanitizeTrainerHtml(html) {
|
||||
if (!html || typeof html !== 'string') return ''
|
||||
const d = document.createElement('div')
|
||||
d.innerHTML = html
|
||||
d.querySelectorAll('script, iframe, object, embed').forEach((n) => n.remove())
|
||||
d.querySelectorAll('*').forEach((el) => {
|
||||
for (const attr of [...el.attributes]) {
|
||||
const n = attr.name.toLowerCase()
|
||||
if (n.startsWith('on') || n === 'srcdoc') el.removeAttribute(attr.name)
|
||||
}
|
||||
})
|
||||
return d.innerHTML
|
||||
}
|
||||
Reference in new issue
Block a user