Initial habit tracker project

This commit is contained in:
2026-07-10 16:18:31 +02:00
commit 23416ee382
20 changed files with 1157 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
<section class="dashboard-head">
<div>
<p class="eyebrow">Heute</p>
<h1>Deine Habits</h1>
</div>
<a class="button" href="index.php?route=habits/create">Habit erstellen</a>
</section>
<form method="get" action="index.php" class="filters">
<input type="hidden" name="route" value="dashboard">
<label for="category_id">Kategorie</label>
<select id="category_id" name="category_id">
<option value="">Alle Kategorien</option>
<?php foreach ($categories as $category): ?>
<option value="<?= (int) $category['id'] ?>" <?= (string) $filters['category_id'] === (string) $category['id'] ? 'selected' : '' ?>>
<?= e($category['name']) ?>
</option>
<?php endforeach; ?>
</select>
<label for="status">Status</label>
<select id="status" name="status">
<option value="">Alle</option>
<option value="open" <?= $filters['status'] === 'open' ? 'selected' : '' ?>>Offen</option>
<option value="done" <?= $filters['status'] === 'done' ? 'selected' : '' ?>>Erledigt</option>
</select>
<button type="submit">Filtern</button>
</form>
<?php if (empty($habits)): ?>
<p class="empty">Noch keine Habits gefunden. Erstelle deinen ersten Habit.</p>
<?php endif; ?>
<section class="habit-list">
<?php foreach ($habits as $habit): ?>
<article class="habit-card <?= $habit['done_today'] ? 'done' : '' ?>">
<div class="habit-main">
<span class="category-dot" style="background-color: <?= e($habit['category_color'] ?? '#9ca3af') ?>"></span>
<div>
<h2><?= e($habit['title']) ?></h2>
<p><?= e($habit['description']) ?></p>
<small>
<?= e($habit['category_name'] ?? 'Ohne Kategorie') ?> |
Ziel: <?= (int) $habit['target_per_week'] ?>x pro Woche
</small>
</div>
</div>
<div class="habit-actions">
<form method="post" action="index.php?route=habits/toggle">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $habit['id'] ?>">
<button type="submit"><?= $habit['done_today'] ? 'Heute erledigt' : 'Abhaken' ?></button>
</form>
<a href="index.php?route=habits/edit&id=<?= (int) $habit['id'] ?>">Bearbeiten</a>
<form method="post" action="index.php?route=habits/delete" onsubmit="return confirm('Diesen Habit wirklich loeschen?');">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $habit['id'] ?>">
<button class="danger" type="submit">Loeschen</button>
</form>
</div>
</article>
<?php endforeach; ?>
</section>
+58
View File
@@ -0,0 +1,58 @@
<?php $isEdit = !empty($habit['id']); ?>
<section class="form-panel">
<h1><?= $isEdit ? 'Habit bearbeiten' : 'Habit erstellen' ?></h1>
<form method="post" action="index.php?route=<?= $isEdit ? 'habits/update' : 'habits/store' ?>" class="form">
<?= csrf_field() ?>
<?php if ($isEdit): ?>
<input type="hidden" name="id" value="<?= (int) $habit['id'] ?>">
<?php endif; ?>
<label for="title">Name des Habits</label>
<input
id="title"
name="title"
type="text"
class="<?= !empty($errors['title']) ? 'input-error' : '' ?>"
value="<?= e($habit['title'] ?? '') ?>"
required
aria-describedby="title-error"
>
<?php if (!empty($errors['title'])): ?>
<small id="title-error" class="field-error"><?= e($errors['title']) ?></small>
<?php endif; ?>
<label for="description">Beschreibung <span>optional</span></label>
<textarea id="description" name="description" rows="4"><?= e($habit['description'] ?? '') ?></textarea>
<label for="category_id">Kategorie</label>
<select id="category_id" name="category_id">
<option value="">Keine Kategorie</option>
<?php foreach ($categories as $category): ?>
<option value="<?= (int) $category['id'] ?>" <?= (string) ($habit['category_id'] ?? '') === (string) $category['id'] ? 'selected' : '' ?>>
<?= e($category['name']) ?>
</option>
<?php endforeach; ?>
</select>
<label for="target_per_week">Ziel pro Woche</label>
<input
id="target_per_week"
name="target_per_week"
type="number"
class="<?= !empty($errors['target_per_week']) ? 'input-error' : '' ?>"
min="1"
max="7"
value="<?= e((string) ($habit['target_per_week'] ?? '3')) ?>"
required
aria-describedby="target-error"
>
<?php if (!empty($errors['target_per_week'])): ?>
<small id="target-error" class="field-error"><?= e($errors['target_per_week']) ?></small>
<?php endif; ?>
<button type="submit"><?= $isEdit ? 'Speichern' : 'Erstellen' ?></button>
</form>
</section>