M1: CRUD-Slice 'Mahlzeit' Schritt 2 – UI (Controller, Templates, Routen, Feature-Tests)

This commit is contained in:
2026-09-19 10:17:55 +02:00
parent 1589088379
commit 160b89f5a1
11 changed files with 536 additions and 9 deletions
+47 -2
View File
@@ -12,6 +12,7 @@
--accent: #0a7bff;
--muted: #667;
--warn: #b45309;
--danger: #b91c1c;
}
* { box-sizing: border-box; }
body {
@@ -44,17 +45,61 @@
border-radius: 0.5rem;
box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.muted { color: var(--muted); font-size: 0.9rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.btn {
display: inline-block;
background: var(--accent);
color: #fff;
padding: 0.4rem 0.8rem;
border-radius: 0.35rem;
text-decoration: none;
border: none;
font: inherit;
cursor: pointer;
}
.btn:hover { opacity: 0.92; }
.btn-danger { background: var(--danger); }
.btn-link { background: transparent; color: var(--muted); }
.actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.list { list-style: none; margin: 1rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.item { display: flex; justify-content: space-between; gap: 1rem; padding: 0.75rem; border: 1px solid #eee; border-radius: 0.4rem; align-items: center; flex-wrap: wrap; }
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.4rem; }
.tag { background: #eef4ff; color: var(--accent); padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.8rem; }
.status { font-size: 0.8rem; color: var(--muted); }
.status-gegessen { color: #15573b; }
.field { margin-bottom: 1rem; }
.field > label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.field input[type="text"], .field textarea {
width: 100%;
padding: 0.5rem;
border: 1px solid #ccc;
border-radius: 0.35rem;
font: inherit;
}
.req { color: var(--danger); }
.checkboxes { display: flex; flex-wrap: wrap; gap: 0.5rem 0.9rem; margin-top: 0.3rem; }
.checkbox { display: inline-flex; align-items: center; gap: 0.3rem; font-weight: 400; cursor: pointer; }
.flash { padding: 0.6rem 0.9rem; border-radius: 0.4rem; margin-bottom: 1rem; }
.flash-notice { background: #e6f6ec; color: #15573b; }
.flash-error { background: #fdecec; color: #8a1f1f; }
</style>
{% block stylesheets %}{% endblock %}
</head>
<body>
<header>
<strong>essen.ljh31.de</strong>
<a href="{{ path('home') }}" style="color: inherit; font-weight: 600;">essen.ljh31.de</a>
<nav>
<a href="logout">Abmelden</a>
<a href="{{ path('mahlzeiten_index') }}">Mahlzeiten</a>
<a href="{{ path('logout') }}">Abmelden</a>
</nav>
</header>
<main>
{% for label, messages in app.flashes %}
{% for message in messages %}
<div class="flash flash-{{ label }}">{{ message }}</div>
{% endfor %}
{% endfor %}
{% block body %}{% endblock %}
</main>
<script src="{{ asset('js/htmx.min.js') }}"></script>
+48
View File
@@ -0,0 +1,48 @@
{% extends 'layout/base.html.twig' %}
{% set titel = mahlzeit ? 'Mahlzeit bearbeiten' : 'Neue Mahlzeit' %}
{% block title %}{{ titel }} · svc-essensplanung{% endblock %}
{% block body %}
<div class="card">
<h1 style="margin-top: 0;">{{ titel }}</h1>
{% if fehler %}
<div class="flash flash-error">{{ fehler }}</div>
{% endif %}
<form method="post"
action="{{ mahlzeit ? path('mahlzeiten_aktualisieren', { id: mahlzeit.id }) : path('mahlzeiten_speichern') }}">
<div class="field">
<label for="name">Name <span class="req" title="Pflichtfeld">*</span></label>
<input type="text" id="name" name="name" value="{{ werte.name }}" required>
</div>
<div class="field">
<label for="notiz">Notiz</label>
<textarea id="notiz" name="notiz" rows="3" placeholder="z. B. mit Basilikum, scharf …">{{ werte.notiz }}</textarea>
</div>
<div class="field">
<label>Wochentage</label>
{% set gewaehlte = werte.wochentage|map(t => t.value) %}
<div class="checkboxes">
{% for tag in wochentage_choices %}
<label class="checkbox">
<input type="checkbox" name="wochentage[]" value="{{ tag.value }}"
{{ tag.value in gewaehlte ? 'checked' : '' }}>
{{ tag.name }}
</label>
{% endfor %}
</div>
</div>
<div class="actions">
<button type="submit" class="btn">{{ mahlzeit ? 'Speichern' : 'Anlegen' }}</button>
<a class="btn btn-link" href="{{ path('mahlzeiten_index') }}">Abbrechen</a>
</div>
</form>
</div>
{% endblock %}
+46
View File
@@ -0,0 +1,46 @@
{% extends 'layout/base.html.twig' %}
{% block title %}Mahlzeiten · svc-essensplanung{% endblock %}
{% block body %}
<div class="card">
<div class="row-between">
<h1 style="margin: 0;">Mahlzeiten</h1>
<a class="btn" href="{{ path('mahlzeiten_neu') }}">+ Neue Mahlzeit</a>
</div>
{% if mahlzeiten|length == 0 %}
<p class="muted" style="margin-top: 1rem;">Noch keine Mahlzeiten angelegt.</p>
{% else %}
<ul class="list">
{% for m in mahlzeiten %}
<li class="item">
<div>
<strong>{{ m.name }}</strong>
{% if m.notiz != '' %}
<div class="muted">{{ m.notiz }}</div>
{% endif %}
{% if m.wochentage|length > 0 %}
<div class="tags">
{% for tag in m.wochentage %}
<span class="tag">{{ tag.name }}</span>
{% endfor %}
</div>
{% endif %}
<span class="status {{ m.status.value == 'gegessen' ? 'status-gegessen' : '' }}">
{{ m.status.value == 'gegessen' ? 'gegessen' : 'geplant' }}
</span>
</div>
<div class="actions">
<a class="btn btn-link" href="{{ path('mahlzeiten_bearbeiten', { id: m.id }) }}">Bearbeiten</a>
<form method="post" action="{{ path('mahlzeiten_loeschen', { id: m.id }) }}"
onsubmit="return confirm('Mahlzeit „{{ m.name }}“ wirklich löschen?');">
<button type="submit" class="btn btn-danger">Löschen</button>
</form>
</div>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endblock %}