Show reminders on dashboard
This commit is contained in:
@@ -6,15 +6,23 @@ class HabitController
|
||||
{
|
||||
require_login();
|
||||
|
||||
$userId = (int) current_user_id();
|
||||
|
||||
$filters = [
|
||||
'category_id' => $_GET['category_id'] ?? '',
|
||||
'status' => $_GET['status'] ?? '',
|
||||
];
|
||||
|
||||
$remindersByHabit = [];
|
||||
foreach (Reminder::allForUser($userId) as $reminder) {
|
||||
$remindersByHabit[(int) $reminder['habit_id']][] = $reminder;
|
||||
}
|
||||
|
||||
View::render('habits/dashboard', [
|
||||
'habits' => Habit::allForUser(current_user_id(), $filters),
|
||||
'habits' => Habit::allForUser($userId, $filters),
|
||||
'categories' => Category::all(),
|
||||
'filters' => $filters,
|
||||
'remindersByHabit' => $remindersByHabit,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
<?php
|
||||
|
||||
$weekdayLabels = [
|
||||
1 => 'Montag',
|
||||
2 => 'Dienstag',
|
||||
3 => 'Mittwoch',
|
||||
4 => 'Donnerstag',
|
||||
5 => 'Freitag',
|
||||
6 => 'Samstag',
|
||||
7 => 'Sonntag',
|
||||
];
|
||||
?>
|
||||
|
||||
<section class="dashboard-head">
|
||||
<div>
|
||||
<p class="eyebrow">Heute</p>
|
||||
@@ -35,6 +48,7 @@
|
||||
|
||||
<section class="habit-list">
|
||||
<?php foreach ($habits as $habit): ?>
|
||||
<?php $habitReminders = $remindersByHabit[(int) $habit['id']] ?? []; ?>
|
||||
<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>
|
||||
@@ -61,6 +75,46 @@
|
||||
<button class="danger" type="submit">Loeschen</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<section class="habit-reminders" aria-labelledby="reminders-<?= (int) $habit['id'] ?>">
|
||||
<div class="reminder-heading">
|
||||
<h3 id="reminders-<?= (int) $habit['id'] ?>">Erinnerungen</h3>
|
||||
<a href="index.php?route=reminders/create&habit_id=<?= (int) $habit['id'] ?>">Erinnerung hinzufuegen</a>
|
||||
</div>
|
||||
|
||||
<?php if (empty($habitReminders)): ?>
|
||||
<p class="reminder-empty">Noch keine Erinnerung eingerichtet.</p>
|
||||
<?php else: ?>
|
||||
<ul class="reminder-list">
|
||||
<?php foreach ($habitReminders as $reminder): ?>
|
||||
<?php
|
||||
$weekday = $reminder['weekday'] === null
|
||||
? 'Taeglich'
|
||||
: ($weekdayLabels[(int) $reminder['weekday']] ?? 'Unbekannt');
|
||||
$isActive = (int) $reminder['is_active'] === 1;
|
||||
?>
|
||||
<li class="reminder-item <?= $isActive ? '' : 'paused' ?>">
|
||||
<strong class="reminder-time"><?= e(substr($reminder['reminder_time'], 0, 5)) ?></strong>
|
||||
<span><?= e($weekday) ?></span>
|
||||
<span class="reminder-status"><?= $isActive ? 'Aktiv' : 'Pausiert' ?></span>
|
||||
<div class="reminder-actions">
|
||||
<form method="post" action="index.php?route=reminders/toggle">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="id" value="<?= (int) $reminder['id'] ?>">
|
||||
<button type="submit"><?= $isActive ? 'Pausieren' : 'Aktivieren' ?></button>
|
||||
</form>
|
||||
<a href="index.php?route=reminders/edit&id=<?= (int) $reminder['id'] ?>">Bearbeiten</a>
|
||||
<form method="post" action="index.php?route=reminders/delete" onsubmit="return confirm('Diese Erinnerung wirklich loeschen?');">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="id" value="<?= (int) $reminder['id'] ?>">
|
||||
<button class="danger" type="submit">Loeschen</button>
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
</section>
|
||||
|
||||
@@ -114,7 +114,8 @@ a {
|
||||
}
|
||||
|
||||
h1,
|
||||
h2 {
|
||||
h2,
|
||||
h3 {
|
||||
line-height: 1.2;
|
||||
margin: 0;
|
||||
}
|
||||
@@ -127,6 +128,10 @@ h2 {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.button,
|
||||
button {
|
||||
background: var(--primary);
|
||||
@@ -212,6 +217,7 @@ input.input-error {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 18px;
|
||||
justify-content: space-between;
|
||||
padding: 18px;
|
||||
@@ -223,6 +229,7 @@ input.input-error {
|
||||
|
||||
.habit-main {
|
||||
display: flex;
|
||||
flex: 1 1 480px;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
@@ -247,6 +254,71 @@ input.input-error {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.habit-reminders {
|
||||
border-top: 1px solid var(--line);
|
||||
flex-basis: 100%;
|
||||
margin-top: 2px;
|
||||
padding-top: 14px;
|
||||
}
|
||||
|
||||
.reminder-heading {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.reminder-empty,
|
||||
.form-help,
|
||||
.form small {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.reminder-list {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
list-style: none;
|
||||
margin: 12px 0 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.reminder-item {
|
||||
align-items: center;
|
||||
background: var(--bg);
|
||||
border-radius: 6px;
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
grid-template-columns: 72px minmax(100px, 1fr) auto auto;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.reminder-item.paused {
|
||||
opacity: 0.68;
|
||||
}
|
||||
|
||||
.reminder-time {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.reminder-status {
|
||||
color: var(--muted);
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.reminder-actions {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.reminder-actions button {
|
||||
min-height: 36px;
|
||||
padding: 6px 10px;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.topbar,
|
||||
.dashboard-head,
|
||||
@@ -271,5 +343,19 @@ input.input-error {
|
||||
.habit-actions {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.reminder-item {
|
||||
align-items: start;
|
||||
grid-template-columns: 72px 1fr;
|
||||
}
|
||||
|
||||
.reminder-status,
|
||||
.reminder-actions {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.reminder-actions {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user