feat: Objekte-Kategorien (stern/sonne/beide) — Version 1.10.1
- Neue Spalte Kategorie (SET stern/sonne) in objekte-Tabelle - ObjektSelector zeigt je nach ArtFuehrung nur passende Objekte - SonnenFührung: Sonne fest vorausgewählt, zusätzliche Sonne-Objekte wählbar - Bestehende Objekte erhalten Kategorie automatisch beim Speichern - Admin: Kategorie editierbar (stern / sonne / stern,sonne) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,9 @@ export default function ObjekteManager({ initialObjekte }: Props) {
|
||||
const router = useRouter();
|
||||
const [editingId, setEditingId] = useState<number | null>(null);
|
||||
const [editName, setEditName] = useState('');
|
||||
const [editKategorie, setEditKategorie] = useState<string>('stern');
|
||||
const [newName, setNewName] = useState('');
|
||||
const [newKategorie, setNewKategorie] = useState<string>('stern');
|
||||
const [error, setError] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
@@ -24,7 +26,7 @@ export default function ObjekteManager({ initialObjekte }: Props) {
|
||||
const res = await fetch('/api/objekte/' + id, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name: trimmed }),
|
||||
body: JSON.stringify({ name: trimmed, kategorie: editKategorie }),
|
||||
});
|
||||
setBusy(false);
|
||||
if (!res.ok) {
|
||||
@@ -59,7 +61,7 @@ export default function ObjekteManager({ initialObjekte }: Props) {
|
||||
const res = await fetch('/api/objekte', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name: trimmed }),
|
||||
body: JSON.stringify({ name: trimmed, kategorie: newKategorie }),
|
||||
});
|
||||
setBusy(false);
|
||||
if (!res.ok) {
|
||||
@@ -85,6 +87,15 @@ export default function ObjekteManager({ initialObjekte }: Props) {
|
||||
placeholder="Neues Objekt…"
|
||||
className="flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:border-blue-500"
|
||||
/>
|
||||
<select
|
||||
value={newKategorie}
|
||||
onChange={(e) => setNewKategorie(e.target.value)}
|
||||
className="px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:border-blue-500"
|
||||
>
|
||||
<option value="stern">Stern</option>
|
||||
<option value="sonne">Sonne</option>
|
||||
<option value="stern,sonne">Stern & Sonne</option>
|
||||
</select>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={busy}
|
||||
@@ -100,6 +111,7 @@ export default function ObjekteManager({ initialObjekte }: Props) {
|
||||
<tr>
|
||||
<th className="text-left px-4 py-3 font-semibold w-16">ID</th>
|
||||
<th className="text-left px-4 py-3 font-semibold">Name</th>
|
||||
<th className="text-left px-4 py-3 font-semibold hidden sm:table-cell">Kategorie</th>
|
||||
<th className="text-left px-4 py-3 font-semibold hidden sm:table-cell">Zuletzt verwendet</th>
|
||||
<th className="px-4 py-3 w-36"></th>
|
||||
</tr>
|
||||
@@ -125,6 +137,27 @@ export default function ObjekteManager({ initialObjekte }: Props) {
|
||||
obj.Name
|
||||
)}
|
||||
</td>
|
||||
<td className="px-4 py-2 hidden sm:table-cell">
|
||||
{editingId === obj.ID ? (
|
||||
<select
|
||||
value={editKategorie}
|
||||
onChange={(e) => setEditKategorie(e.target.value)}
|
||||
className="px-2 py-1 border border-blue-400 rounded text-sm focus:outline-none"
|
||||
>
|
||||
<option value="stern">Stern</option>
|
||||
<option value="sonne">Sonne</option>
|
||||
<option value="stern,sonne">Stern & Sonne</option>
|
||||
</select>
|
||||
) : (
|
||||
<span className="flex gap-1">
|
||||
{obj.Kategorie.split(',').map((k) => (
|
||||
<span key={k} className={`text-xs px-2 py-0.5 rounded-full font-medium ${k === 'sonne' ? 'bg-yellow-100 text-yellow-800' : 'bg-blue-100 text-blue-800'}`}>
|
||||
{k}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-4 py-2 text-gray-500 hidden sm:table-cell">
|
||||
{obj.LastUsed ? new Date(obj.LastUsed).toLocaleDateString('de-DE') : '—'}
|
||||
</td>
|
||||
@@ -151,7 +184,7 @@ export default function ObjekteManager({ initialObjekte }: Props) {
|
||||
<span className="flex justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { setEditingId(obj.ID); setEditName(obj.Name); setError(''); }}
|
||||
onClick={() => { setEditingId(obj.ID); setEditName(obj.Name); setEditKategorie(obj.Kategorie); setError(''); }}
|
||||
disabled={busy}
|
||||
className="px-2 py-1 text-xs font-medium bg-blue-100 text-blue-700 border border-blue-300 rounded hover:bg-blue-200 disabled:opacity-50"
|
||||
>
|
||||
@@ -172,7 +205,7 @@ export default function ObjekteManager({ initialObjekte }: Props) {
|
||||
))}
|
||||
{initialObjekte.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={4} className="px-4 py-6 text-center text-gray-400 text-sm">Keine Objekte vorhanden.</td>
|
||||
<td colSpan={5} className="px-4 py-6 text-center text-gray-400 text-sm">Keine Objekte vorhanden.</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface ObjektRow {
|
||||
ID: number;
|
||||
Name: string;
|
||||
LastUsed: string | null;
|
||||
Kategorie: string;
|
||||
}
|
||||
|
||||
export async function listObjekte(): Promise<ObjektRow[]> {
|
||||
|
||||
@@ -10,10 +10,12 @@ export async function PUT(req: NextRequest, { params }: { params: Promise<{ id:
|
||||
const { id } = await params;
|
||||
const numId = Number(id);
|
||||
if (isNaN(numId)) return NextResponse.json({ error: 'Ungültige ID' }, { status: 400 });
|
||||
const { name } = await req.json();
|
||||
const { name, kategorie } = await req.json();
|
||||
const trimmed = (name as string)?.trim();
|
||||
if (!trimmed) return NextResponse.json({ error: 'Name darf nicht leer sein' }, { status: 400 });
|
||||
const result = await phpdb.updateObjekt(numId, trimmed);
|
||||
const VALID = ['stern', 'sonne', 'stern,sonne'];
|
||||
const kat: string | undefined = VALID.includes(kategorie) ? kategorie : undefined;
|
||||
const result = await phpdb.updateObjekt(numId, trimmed, kat);
|
||||
return NextResponse.json(result);
|
||||
} catch (error) {
|
||||
console.error('PUT /api/objekte/[id]:', error);
|
||||
|
||||
@@ -2,11 +2,13 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getSession } from '@/lib/session';
|
||||
import * as phpdb from '@/lib/phpdb';
|
||||
|
||||
export async function GET() {
|
||||
export async function GET(req: NextRequest) {
|
||||
const session = await getSession();
|
||||
if (!session) return NextResponse.json({ error: 'Nicht angemeldet' }, { status: 401 });
|
||||
try {
|
||||
const rows = await phpdb.getObjekte();
|
||||
const raw = req.nextUrl.searchParams.get('kategorie');
|
||||
const kategorie = raw === 'sonne' ? 'sonne' : 'stern';
|
||||
const rows = await phpdb.getObjekte(kategorie);
|
||||
return NextResponse.json(rows);
|
||||
} catch (error) {
|
||||
console.error('GET /api/objekte:', error);
|
||||
@@ -19,10 +21,12 @@ export async function POST(req: NextRequest) {
|
||||
if (!session) return NextResponse.json({ error: 'Nicht angemeldet' }, { status: 401 });
|
||||
if (!session.role?.includes('admin')) return NextResponse.json({ error: 'Keine Berechtigung' }, { status: 403 });
|
||||
try {
|
||||
const { name } = await req.json();
|
||||
const { name, kategorie } = await req.json();
|
||||
const trimmed = (name as string)?.trim();
|
||||
if (!trimmed) return NextResponse.json({ error: 'Name darf nicht leer sein' }, { status: 400 });
|
||||
const result = await phpdb.createObjekt(trimmed);
|
||||
const VALID = ['stern', 'sonne', 'stern,sonne'];
|
||||
const kat: string = VALID.includes(kategorie) ? kategorie : 'stern';
|
||||
const result = await phpdb.createObjekt(trimmed, kat);
|
||||
return NextResponse.json(result, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error('POST /api/objekte:', error);
|
||||
|
||||
Reference in New Issue
Block a user