Add per-sport location settings and clarify recovery groups

This commit is contained in:
2026-04-12 11:57:13 +02:00
parent 80f649c547
commit 1080dd9d82
8 changed files with 104 additions and 9 deletions
+12
View File
@@ -826,6 +826,12 @@ button {
line-height: 1.35; line-height: 1.35;
} }
.sport-choice__card small {
color: var(--muted);
font-size: 0.82rem;
line-height: 1.3;
}
.sport-choice input:checked + .sport-choice__card { .sport-choice input:checked + .sport-choice__card {
border-color: rgba(139, 228, 255, 0.44); border-color: rgba(139, 228, 255, 0.44);
background: linear-gradient(180deg, rgba(96, 184, 255, 0.18), rgba(255, 255, 255, 0.08)); background: linear-gradient(180deg, rgba(96, 184, 255, 0.18), rgba(255, 255, 255, 0.08));
@@ -1002,6 +1008,12 @@ input[type="range"] {
flex-wrap: wrap; flex-wrap: wrap;
} }
.section-actions {
display: flex;
justify-content: flex-end;
margin-top: 0.95rem;
}
.primary-button, .primary-button,
.ghost-button, .ghost-button,
.button-link { .button-link {
+11 -1
View File
@@ -763,11 +763,16 @@
const syncPreview = row => { const syncPreview = row => {
const labelInput = row.querySelector('input[data-name-template$="[label]"]'); const labelInput = row.querySelector('input[data-name-template$="[label]"]');
const iconSelect = row.querySelector('select[data-name-template$="[icon]"]'); const iconSelect = row.querySelector('select[data-name-template$="[icon]"]');
const locationSelect = row.querySelector('select[data-name-template$="[location]"]');
const previewText = row.querySelector(".sport-pill span:last-child"); const previewText = row.querySelector(".sport-pill span:last-child");
const previewImage = row.querySelector(".sport-pill img"); const previewImage = row.querySelector(".sport-pill img");
if (previewText) { if (previewText) {
previewText.textContent = (labelInput && labelInput.value.trim()) || "Neue Sportart"; const label = (labelInput && labelInput.value.trim()) || "Neue Sportart";
const location = locationSelect && locationSelect.value
? locationSelect.options[locationSelect.selectedIndex]?.textContent || ""
: "";
previewText.textContent = location ? `${label} · ${location}` : label;
} }
if (previewImage && iconSelect) { if (previewImage && iconSelect) {
@@ -808,6 +813,7 @@
const idInput = row.querySelector('input[data-name-template$="[id]"]'); const idInput = row.querySelector('input[data-name-template$="[id]"]');
const labelInput = row.querySelector('input[data-name-template$="[label]"]'); const labelInput = row.querySelector('input[data-name-template$="[label]"]');
const iconSelect = row.querySelector('select[data-name-template$="[icon]"]'); const iconSelect = row.querySelector('select[data-name-template$="[icon]"]');
const locationSelect = row.querySelector('select[data-name-template$="[location]"]');
const groupInput = row.querySelector('input[data-name-template$="[recovery_group]"]'); const groupInput = row.querySelector('input[data-name-template$="[recovery_group]"]');
const bonusInput = row.querySelector('input[data-name-template$="[bonus_points]"]'); const bonusInput = row.querySelector('input[data-name-template$="[bonus_points]"]');
const consecutiveInput = row.querySelector('input[data-name-template$="[allow_consecutive]"]'); const consecutiveInput = row.querySelector('input[data-name-template$="[allow_consecutive]"]');
@@ -821,6 +827,9 @@
if (iconSelect) { if (iconSelect) {
iconSelect.value = values.icon || "run"; iconSelect.value = values.icon || "run";
} }
if (locationSelect) {
locationSelect.value = values.location || "";
}
if (groupInput) { if (groupInput) {
groupInput.value = values.recovery_group || ""; groupInput.value = values.recovery_group || "";
} }
@@ -845,6 +854,7 @@
id: button.dataset.id || "", id: button.dataset.id || "",
label: button.dataset.label || "", label: button.dataset.label || "",
icon: button.dataset.icon || "run", icon: button.dataset.icon || "run",
location: button.dataset.location || "",
recovery_group: button.dataset.recoveryGroup || "", recovery_group: button.dataset.recoveryGroup || "",
bonus_points: button.dataset.bonusPoints || "2", bonus_points: button.dataset.bonusPoints || "2",
allow_consecutive: button.dataset.allowConsecutive === "1", allow_consecutive: button.dataset.allowConsecutive === "1",
+7 -1
View File
@@ -330,6 +330,7 @@ final class App
'authUser' => $user, 'authUser' => $user,
'settings' => $settings, 'settings' => $settings,
'sportTypePresets' => $sportTypePresets, 'sportTypePresets' => $sportTypePresets,
'sportLocationOptions' => sport_location_options(),
'users' => $user['is_admin'] ? $this->users->all() : [], 'users' => $user['is_admin'] ? $this->users->all() : [],
'maxScore' => $this->scoring->evaluate([ 'maxScore' => $this->scoring->evaluate([
'mood' => 10, 'mood' => 10,
@@ -481,7 +482,12 @@ final class App
'sport' => $entry['sport_minutes'], 'sport' => $entry['sport_minutes'],
'walk' => $entry['walk_minutes'], 'walk' => $entry['walk_minutes'],
'sport_labels' => array_values(array_filter(array_map( 'sport_labels' => array_values(array_filter(array_map(
static fn (array $type): string => (string) ($type['label'] ?? ''), static function (array $type): string {
$label = (string) ($type['label'] ?? '');
$location = sport_location_label((string) ($type['location'] ?? ''));
return $location !== '' ? $label . ' · ' . $location : $label;
},
$entry['sport_type_meta'] ?? [] $entry['sport_type_meta'] ?? []
))), ))),
'sport_icons' => array_values(array_filter(array_map( 'sport_icons' => array_values(array_filter(array_map(
+10
View File
@@ -21,6 +21,7 @@ final class Defaults
'id' => 'running', 'id' => 'running',
'label' => 'Joggen', 'label' => 'Joggen',
'icon' => 'run', 'icon' => 'run',
'location' => '',
'recovery_group' => 'joggen', 'recovery_group' => 'joggen',
'bonus_points' => 2, 'bonus_points' => 2,
'allow_consecutive' => false, 'allow_consecutive' => false,
@@ -29,6 +30,7 @@ final class Defaults
'id' => 'cycling', 'id' => 'cycling',
'label' => 'Radfahren', 'label' => 'Radfahren',
'icon' => 'bike', 'icon' => 'bike',
'location' => '',
'recovery_group' => 'radfahren', 'recovery_group' => 'radfahren',
'bonus_points' => 2, 'bonus_points' => 2,
'allow_consecutive' => false, 'allow_consecutive' => false,
@@ -37,6 +39,7 @@ final class Defaults
'id' => 'strength', 'id' => 'strength',
'label' => 'Krafttraining', 'label' => 'Krafttraining',
'icon' => 'strength', 'icon' => 'strength',
'location' => '',
'recovery_group' => 'kraftsport', 'recovery_group' => 'kraftsport',
'bonus_points' => 2, 'bonus_points' => 2,
'allow_consecutive' => false, 'allow_consecutive' => false,
@@ -45,6 +48,7 @@ final class Defaults
'id' => 'hiking', 'id' => 'hiking',
'label' => 'Wandern', 'label' => 'Wandern',
'icon' => 'hike', 'icon' => 'hike',
'location' => '',
'recovery_group' => 'wandern', 'recovery_group' => 'wandern',
'bonus_points' => 2, 'bonus_points' => 2,
'allow_consecutive' => false, 'allow_consecutive' => false,
@@ -53,6 +57,7 @@ final class Defaults
'id' => 'swimming', 'id' => 'swimming',
'label' => 'Schwimmen', 'label' => 'Schwimmen',
'icon' => 'swim', 'icon' => 'swim',
'location' => '',
'recovery_group' => 'schwimmen', 'recovery_group' => 'schwimmen',
'bonus_points' => 2, 'bonus_points' => 2,
'allow_consecutive' => false, 'allow_consecutive' => false,
@@ -61,6 +66,7 @@ final class Defaults
'id' => 'yoga', 'id' => 'yoga',
'label' => 'Yoga', 'label' => 'Yoga',
'icon' => 'yoga', 'icon' => 'yoga',
'location' => '',
'recovery_group' => 'yoga', 'recovery_group' => 'yoga',
'bonus_points' => 2, 'bonus_points' => 2,
'allow_consecutive' => false, 'allow_consecutive' => false,
@@ -69,6 +75,7 @@ final class Defaults
'id' => 'hiit-workout', 'id' => 'hiit-workout',
'label' => 'HIIT / Workout', 'label' => 'HIIT / Workout',
'icon' => 'hiit', 'icon' => 'hiit',
'location' => '',
'recovery_group' => 'hiit', 'recovery_group' => 'hiit',
'bonus_points' => 2, 'bonus_points' => 2,
'allow_consecutive' => false, 'allow_consecutive' => false,
@@ -77,6 +84,7 @@ final class Defaults
'id' => 'rowing', 'id' => 'rowing',
'label' => 'Rudern', 'label' => 'Rudern',
'icon' => 'row', 'icon' => 'row',
'location' => '',
'recovery_group' => 'rudern', 'recovery_group' => 'rudern',
'bonus_points' => 2, 'bonus_points' => 2,
'allow_consecutive' => false, 'allow_consecutive' => false,
@@ -85,6 +93,7 @@ final class Defaults
'id' => 'dance', 'id' => 'dance',
'label' => 'Tanzen', 'label' => 'Tanzen',
'icon' => 'dance', 'icon' => 'dance',
'location' => '',
'recovery_group' => 'tanzen', 'recovery_group' => 'tanzen',
'bonus_points' => 2, 'bonus_points' => 2,
'allow_consecutive' => false, 'allow_consecutive' => false,
@@ -93,6 +102,7 @@ final class Defaults
'id' => 'core', 'id' => 'core',
'label' => 'Core', 'label' => 'Core',
'icon' => 'core', 'icon' => 'core',
'location' => '',
'recovery_group' => 'core', 'recovery_group' => 'core',
'bonus_points' => 2, 'bonus_points' => 2,
'allow_consecutive' => true, 'allow_consecutive' => true,
+23
View File
@@ -240,6 +240,23 @@ function sport_icon_options(): array
]; ];
} }
function sport_location_options(): array
{
return [
'' => 'ohne Angabe',
'home' => 'Zuhause',
'away' => 'Auswärts',
];
}
function sport_location_label(?string $value): string
{
$options = sport_location_options();
$value = is_string($value) ? trim($value) : '';
return $options[$value] ?? '';
}
function normalize_sport_type_id(string $value): string function normalize_sport_type_id(string $value): string
{ {
$value = trim(strtr($value, [ $value = trim(strtr($value, [
@@ -300,6 +317,11 @@ function normalized_sport_types(array $settings): array
$icon = 'run'; $icon = 'run';
} }
$location = trim((string) ($type['location'] ?? ''));
if (!array_key_exists($location, sport_location_options())) {
$location = '';
}
$group = trim((string) ($type['recovery_group'] ?? '')); $group = trim((string) ($type['recovery_group'] ?? ''));
if ($group === '') { if ($group === '') {
$group = $id; $group = $id;
@@ -309,6 +331,7 @@ function normalized_sport_types(array $settings): array
'id' => $id, 'id' => $id,
'label' => $label, 'label' => $label,
'icon' => $icon, 'icon' => $icon,
'location' => $location,
'recovery_group' => normalize_sport_type_id($group) ?: $id, 'recovery_group' => normalize_sport_type_id($group) ?: $id,
'bonus_points' => max(0, min(20, (int) ($type['bonus_points'] ?? 0))), 'bonus_points' => max(0, min(20, (int) ($type['bonus_points'] ?? 0))),
'allow_consecutive' => !empty($type['allow_consecutive']), 'allow_consecutive' => !empty($type['allow_consecutive']),
+2 -2
View File
@@ -22,7 +22,7 @@
<?php foreach ($entry['sport_type_meta'] as $sportType): ?> <?php foreach ($entry['sport_type_meta'] as $sportType): ?>
<span class="sport-pill"> <span class="sport-pill">
<img src="<?= e(sport_icon_path($sportType['icon'])) ?>" alt=""> <img src="<?= e(sport_icon_path($sportType['icon'])) ?>" alt="">
<span><?= e($sportType['label']) ?></span> <span><?= e($sportType['label']) ?><?= !empty($sportType['location']) ? ' · ' . e(sport_location_label((string) $sportType['location'])) : '' ?></span>
</span> </span>
<?php endforeach; ?> <?php endforeach; ?>
</span> </span>
@@ -65,7 +65,7 @@
<?php foreach ($selectedEntry['sport_type_meta'] as $sportType): ?> <?php foreach ($selectedEntry['sport_type_meta'] as $sportType): ?>
<span class="sport-pill sport-pill--inline"> <span class="sport-pill sport-pill--inline">
<img src="<?= e(sport_icon_path($sportType['icon'])) ?>" alt=""> <img src="<?= e(sport_icon_path($sportType['icon'])) ?>" alt="">
<span><?= e($sportType['label']) ?></span> <span><?= e($sportType['label']) ?><?= !empty($sportType['location']) ? ' · ' . e(sport_location_label((string) $sportType['location'])) : '' ?></span>
</span> </span>
<?php endforeach; ?> <?php endforeach; ?>
</span> </span>
+36 -5
View File
@@ -82,6 +82,7 @@
data-id="<?= e($preset['id']) ?>" data-id="<?= e($preset['id']) ?>"
data-label="<?= e($preset['label']) ?>" data-label="<?= e($preset['label']) ?>"
data-icon="<?= e($preset['icon']) ?>" data-icon="<?= e($preset['icon']) ?>"
data-location="<?= e($preset['location'] ?? '') ?>"
data-recovery-group="<?= e($preset['recovery_group']) ?>" data-recovery-group="<?= e($preset['recovery_group']) ?>"
data-bonus-points="<?= e((string) $preset['bonus_points']) ?>" data-bonus-points="<?= e((string) $preset['bonus_points']) ?>"
data-allow-consecutive="<?= !empty($preset['allow_consecutive']) ? '1' : '0' ?>" data-allow-consecutive="<?= !empty($preset['allow_consecutive']) ? '1' : '0' ?>"
@@ -114,10 +115,21 @@
</label> </label>
<label> <label>
<span>Erholungsgruppe</span> <span>Ort</span>
<input type="text" name="settings[sport_types][<?= e((string) $index) ?>][recovery_group]" value="<?= e($sportType['recovery_group']) ?>" data-name-template="settings[sport_types][__INDEX__][recovery_group]"> <select name="settings[sport_types][<?= e((string) $index) ?>][location]" data-name-template="settings[sport_types][__INDEX__][location]">
<?php foreach ($sportLocationOptions as $locationValue => $locationLabel): ?>
<option value="<?= e($locationValue) ?>" <?= ($sportType['location'] ?? '') === $locationValue ? 'selected' : '' ?>><?= e($locationLabel) ?></option>
<?php endforeach; ?>
</select>
</label> </label>
<label>
<span>Erholungsgruppe optional</span>
<input type="text" name="settings[sport_types][<?= e((string) $index) ?>][recovery_group]" value="<?= e($sportType['recovery_group']) ?>" data-name-template="settings[sport_types][__INDEX__][recovery_group]">
</label>
</div>
<div class="field-grid field-grid--four">
<label> <label>
<span>Bonuspunkte</span> <span>Bonuspunkte</span>
<input type="number" name="settings[sport_types][<?= e((string) $index) ?>][bonus_points]" value="<?= e((string) $sportType['bonus_points']) ?>" min="0" max="20" data-name-template="settings[sport_types][__INDEX__][bonus_points]"> <input type="number" name="settings[sport_types][<?= e((string) $index) ?>][bonus_points]" value="<?= e((string) $sportType['bonus_points']) ?>" min="0" max="20" data-name-template="settings[sport_types][__INDEX__][bonus_points]">
@@ -129,10 +141,12 @@
<span>Darf an aufeinanderfolgenden Tagen Bonus geben</span> <span>Darf an aufeinanderfolgenden Tagen Bonus geben</span>
</label> </label>
<p class="helper-text">Die Erholungsgruppe brauchst du nur, wenn mehrere Varianten dieselbe Belastung teilen sollen, zum Beispiel Krafttraining Zuhause und Krafttraining Auswärts. Wenn du nichts Besonderes einträgst, reicht die Sportart selbst.</p>
<div class="sport-type-card__actions"> <div class="sport-type-card__actions">
<span class="sport-pill sport-pill--soft"> <span class="sport-pill sport-pill--soft">
<img src="<?= e(sport_icon_path($sportType['icon'])) ?>" alt=""> <img src="<?= e(sport_icon_path($sportType['icon'])) ?>" alt="">
<span><?= e($sportType['label']) ?></span> <span><?= e($sportType['label']) ?><?= !empty($sportType['location']) ? ' · ' . e(sport_location_label((string) $sportType['location'])) : '' ?></span>
</span> </span>
<button class="ghost-button ghost-button--small" type="button" data-remove-sport-type>Entfernen</button> <button class="ghost-button ghost-button--small" type="button" data-remove-sport-type>Entfernen</button>
</div> </div>
@@ -140,6 +154,10 @@
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<div class="section-actions">
<button class="primary-button" type="submit">Sportarten speichern</button>
</div>
<template id="sport-type-row-template"> <template id="sport-type-row-template">
<div class="sport-type-card band-card" data-sport-type-row> <div class="sport-type-card band-card" data-sport-type-row>
<input type="hidden" value="" data-name-template="settings[sport_types][__INDEX__][id]"> <input type="hidden" value="" data-name-template="settings[sport_types][__INDEX__][id]">
@@ -160,10 +178,21 @@
</label> </label>
<label> <label>
<span>Erholungsgruppe</span> <span>Ort</span>
<input type="text" value="" placeholder="z. B. krafttraining" data-name-template="settings[sport_types][__INDEX__][recovery_group]"> <select data-name-template="settings[sport_types][__INDEX__][location]">
<?php foreach ($sportLocationOptions as $locationValue => $locationLabel): ?>
<option value="<?= e($locationValue) ?>"><?= e($locationLabel) ?></option>
<?php endforeach; ?>
</select>
</label> </label>
<label>
<span>Erholungsgruppe optional</span>
<input type="text" value="" placeholder="z. B. krafttraining" data-name-template="settings[sport_types][__INDEX__][recovery_group]">
</label>
</div>
<div class="field-grid field-grid--four">
<label> <label>
<span>Bonuspunkte</span> <span>Bonuspunkte</span>
<input type="number" value="2" min="0" max="20" data-name-template="settings[sport_types][__INDEX__][bonus_points]"> <input type="number" value="2" min="0" max="20" data-name-template="settings[sport_types][__INDEX__][bonus_points]">
@@ -175,6 +204,8 @@
<span>Darf an aufeinanderfolgenden Tagen Bonus geben</span> <span>Darf an aufeinanderfolgenden Tagen Bonus geben</span>
</label> </label>
<p class="helper-text">Die Erholungsgruppe ist nur dann nützlich, wenn mehrere Varianten sportlich gleich belastend sind und denselben Bonusrhythmus teilen sollen.</p>
<div class="sport-type-card__actions"> <div class="sport-type-card__actions">
<span class="sport-pill sport-pill--soft"> <span class="sport-pill sport-pill--soft">
<img src="<?= e(sport_icon_path('run')) ?>" alt=""> <img src="<?= e(sport_icon_path('run')) ?>" alt="">
+3
View File
@@ -76,6 +76,9 @@
<span class="sport-choice__card"> <span class="sport-choice__card">
<img src="<?= e(sport_icon_path($sportType['icon'])) ?>" alt=""> <img src="<?= e(sport_icon_path($sportType['icon'])) ?>" alt="">
<strong><?= e($sportType['label']) ?></strong> <strong><?= e($sportType['label']) ?></strong>
<?php if (!empty($sportType['location'])): ?>
<small><?= e(sport_location_label((string) $sportType['location'])) ?></small>
<?php endif; ?>
</span> </span>
</label> </label>
<?php endforeach; ?> <?php endforeach; ?>