Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f561ac29ba | ||
|
|
de8914f9cc | ||
|
|
96eaf3989e | ||
|
|
474467811c |
@@ -4,6 +4,50 @@ Alle nennenswerten Änderungen an diesem Projekt werden hier dokumentiert.
|
||||
Format angelehnt an [Keep a Changelog](https://keepachangelog.com/de/1.1.0/),
|
||||
Versionierung nach [Semantic Versioning](https://semver.org/lang/de/).
|
||||
|
||||
## [1.8.0] – 2026-07-19
|
||||
|
||||
### Hinzugefügt
|
||||
- Umschaltbarer Hinweismodus für Allergene/Zusatzstoffe: Auf der Seite
|
||||
„Allergene & Zusatzstoffe“ kann zwischen der bisherigen detaillierten
|
||||
Auswahl je Gericht und einem einfachen, in Deutsch/Englisch/Polnisch
|
||||
editierbaren Hinweistext (z. B. „Bei Fragen zu Allergenen und
|
||||
Zusatzstoffen wenden Sie sich bitte an das Kantinen-Team.“)
|
||||
umgeschaltet werden. Im Hinweismodus entfällt auf der öffentlichen
|
||||
Speisekarte die Legende und die Kürzel an den Gerichten, und in der
|
||||
Gerichte-Verwaltung wird die Allergen-/Zusatzstoff-Auswahl beim
|
||||
Bearbeiten ausgeblendet (bereits zugeordnete Daten bleiben in der
|
||||
Datenbank erhalten). Umschalten und Hinweistext bearbeiten dürfen
|
||||
sowohl Kantinenpersonal als auch Admins.
|
||||
|
||||
## [1.7.0] – 2026-07-19
|
||||
|
||||
### Hinzugefügt
|
||||
- CSV-Import/-Export für Gerichte, Allergene und Zusatzstoffe (Buttons
|
||||
„Exportieren“/„Importieren“ auf den jeweiligen Verwaltungsseiten).
|
||||
Export lädt die aktuelle Liste als CSV herunter (Gerichte:
|
||||
`name,name_en,name_pl,price,allergens,additives`, Allergene/
|
||||
Zusatzstoffe: `code,name,name_en,name_pl`; Kürzel bei Gerichten
|
||||
Semikolon-getrennt in einer Zelle, z. B. `A;G`). Import liest dieselbe
|
||||
Spaltenstruktur (Reihenfolge egal, Groß-/Kleinschreibung der
|
||||
Kopfzeile wird ignoriert) und aktualisiert bestehende Einträge
|
||||
(Abgleich über Kürzel bei Allergenen/Zusatzstoffen, über den exakten
|
||||
Namen bei Gerichten) bzw. legt neue an. Zeilen mit fehlenden
|
||||
Pflichtfeldern, ungültigem Preis oder mehrdeutigem Gerichtsnamen
|
||||
(mehrere Gerichte mit demselben Namen) werden übersprungen und mit
|
||||
Grund in der Erfolgsmeldung aufgelistet, statt den ganzen Import
|
||||
abzubrechen.
|
||||
|
||||
### Behoben
|
||||
- RSS-Feed (`/feed.xml`): Mehrere Feed-Reader (u. a. Outlook,
|
||||
Thunderbird) behandeln `<description>` als kurze Vorschau und kürzen
|
||||
sie eigenmächtig – dadurch war bei Tagen mit mehreren Essenszeiten
|
||||
oft nur die erste sichtbar, obwohl der Server bereits alle
|
||||
Essenszeiten des Tages in der Beschreibung lieferte. Zusätzlich zu
|
||||
`<description>` wird jetzt auch `<content:encoded>` (RSS-Content-
|
||||
Modul) mit demselben vollständigen Inhalt ausgeliefert – von den
|
||||
meisten Readern als vollständiger Artikeltext erkannt und ungekürzt
|
||||
angezeigt.
|
||||
|
||||
## [1.6.3] – 2026-07-18
|
||||
|
||||
### Behoben
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { listCodes } from "@/lib/db/code-lists";
|
||||
import { authErrorResponse, requireRole } from "@/lib/auth/session";
|
||||
import { toCsv } from "@/lib/csv";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
await requireRole(["staff", "admin"]);
|
||||
const items = await listCodes("additives");
|
||||
const rows = [
|
||||
["code", "name", "name_en", "name_pl"],
|
||||
...items.map((i) => [i.code, i.name, i.name_en ?? "", i.name_pl ?? ""]),
|
||||
];
|
||||
return new Response(toCsv(rows), {
|
||||
headers: {
|
||||
"Content-Type": "text/csv; charset=utf-8",
|
||||
"Content-Disposition": 'attachment; filename="zusatzstoffe.csv"',
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
const res = authErrorResponse(err);
|
||||
if (res) return res;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { importCodes, type CodeImportRow } from "@/lib/db/code-lists";
|
||||
import { authErrorResponse, requireRole } from "@/lib/auth/session";
|
||||
import { isSameOrigin } from "@/lib/origin";
|
||||
import { parseCsvWithHeader } from "@/lib/csv";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
if (!isSameOrigin(request)) {
|
||||
return NextResponse.json({ error: "Nicht erlaubt." }, { status: 403 });
|
||||
}
|
||||
try {
|
||||
await requireRole(["staff", "admin"]);
|
||||
const form = await request.formData();
|
||||
const file = form.get("file");
|
||||
if (!(file instanceof File)) {
|
||||
return NextResponse.json({ error: "invalid_input" }, { status: 400 });
|
||||
}
|
||||
|
||||
const { header, rows: cells } = parseCsvWithHeader(await file.text());
|
||||
const codeIdx = header.indexOf("code");
|
||||
const nameIdx = header.indexOf("name");
|
||||
if (codeIdx === -1 || nameIdx === -1) {
|
||||
return NextResponse.json({ error: "missing_columns" }, { status: 400 });
|
||||
}
|
||||
const nameEnIdx = header.indexOf("name_en");
|
||||
const namePlIdx = header.indexOf("name_pl");
|
||||
|
||||
const rows: CodeImportRow[] = [];
|
||||
const skipped: { row: number; reason: string }[] = [];
|
||||
cells.forEach((c, i) => {
|
||||
const rowNum = i + 2; // 1-indexiert + Kopfzeile
|
||||
const code = (c[codeIdx] ?? "").trim();
|
||||
const name = (c[nameIdx] ?? "").trim();
|
||||
if (!code || !name) {
|
||||
skipped.push({ row: rowNum, reason: "Kürzel oder Bezeichnung fehlt" });
|
||||
return;
|
||||
}
|
||||
rows.push({
|
||||
code,
|
||||
name,
|
||||
name_en: nameEnIdx >= 0 ? c[nameEnIdx]?.trim() || null : null,
|
||||
name_pl: namePlIdx >= 0 ? c[namePlIdx]?.trim() || null : null,
|
||||
});
|
||||
});
|
||||
|
||||
const result = rows.length > 0 ? await importCodes("additives", rows) : { created: 0, updated: 0 };
|
||||
return NextResponse.json({ ...result, skipped });
|
||||
} catch (err) {
|
||||
const res = authErrorResponse(err);
|
||||
if (res) return res;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { listCodes } from "@/lib/db/code-lists";
|
||||
import { authErrorResponse, requireRole } from "@/lib/auth/session";
|
||||
import { toCsv } from "@/lib/csv";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
await requireRole(["staff", "admin"]);
|
||||
const items = await listCodes("allergens");
|
||||
const rows = [
|
||||
["code", "name", "name_en", "name_pl"],
|
||||
...items.map((i) => [i.code, i.name, i.name_en ?? "", i.name_pl ?? ""]),
|
||||
];
|
||||
return new Response(toCsv(rows), {
|
||||
headers: {
|
||||
"Content-Type": "text/csv; charset=utf-8",
|
||||
"Content-Disposition": 'attachment; filename="allergene.csv"',
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
const res = authErrorResponse(err);
|
||||
if (res) return res;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { importCodes, type CodeImportRow } from "@/lib/db/code-lists";
|
||||
import { authErrorResponse, requireRole } from "@/lib/auth/session";
|
||||
import { isSameOrigin } from "@/lib/origin";
|
||||
import { parseCsvWithHeader } from "@/lib/csv";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
if (!isSameOrigin(request)) {
|
||||
return NextResponse.json({ error: "Nicht erlaubt." }, { status: 403 });
|
||||
}
|
||||
try {
|
||||
await requireRole(["staff", "admin"]);
|
||||
const form = await request.formData();
|
||||
const file = form.get("file");
|
||||
if (!(file instanceof File)) {
|
||||
return NextResponse.json({ error: "invalid_input" }, { status: 400 });
|
||||
}
|
||||
|
||||
const { header, rows: cells } = parseCsvWithHeader(await file.text());
|
||||
const codeIdx = header.indexOf("code");
|
||||
const nameIdx = header.indexOf("name");
|
||||
if (codeIdx === -1 || nameIdx === -1) {
|
||||
return NextResponse.json({ error: "missing_columns" }, { status: 400 });
|
||||
}
|
||||
const nameEnIdx = header.indexOf("name_en");
|
||||
const namePlIdx = header.indexOf("name_pl");
|
||||
|
||||
const rows: CodeImportRow[] = [];
|
||||
const skipped: { row: number; reason: string }[] = [];
|
||||
cells.forEach((c, i) => {
|
||||
const rowNum = i + 2; // 1-indexiert + Kopfzeile
|
||||
const code = (c[codeIdx] ?? "").trim();
|
||||
const name = (c[nameIdx] ?? "").trim();
|
||||
if (!code || !name) {
|
||||
skipped.push({ row: rowNum, reason: "Kürzel oder Bezeichnung fehlt" });
|
||||
return;
|
||||
}
|
||||
rows.push({
|
||||
code,
|
||||
name,
|
||||
name_en: nameEnIdx >= 0 ? c[nameEnIdx]?.trim() || null : null,
|
||||
name_pl: namePlIdx >= 0 ? c[namePlIdx]?.trim() || null : null,
|
||||
});
|
||||
});
|
||||
|
||||
const result = rows.length > 0 ? await importCodes("allergens", rows) : { created: 0, updated: 0 };
|
||||
return NextResponse.json({ ...result, skipped });
|
||||
} catch (err) {
|
||||
const res = authErrorResponse(err);
|
||||
if (res) return res;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { query } from "@/lib/db";
|
||||
import { authErrorResponse, requireRole } from "@/lib/auth/session";
|
||||
import { toCsv } from "@/lib/csv";
|
||||
import type { Dish } from "@/lib/types";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
await requireRole(["staff", "admin"]);
|
||||
const dishes = await query<Dish>("select * from dishes order by name");
|
||||
const rows = [
|
||||
["name", "name_en", "name_pl", "price", "allergens", "additives"],
|
||||
...dishes.map((d) => [
|
||||
d.name,
|
||||
d.name_en ?? "",
|
||||
d.name_pl ?? "",
|
||||
String(d.price),
|
||||
(d.allergens ?? []).join(";"),
|
||||
(d.additives ?? []).join(";"),
|
||||
]),
|
||||
];
|
||||
return new Response(toCsv(rows), {
|
||||
headers: {
|
||||
"Content-Type": "text/csv; charset=utf-8",
|
||||
"Content-Disposition": 'attachment; filename="gerichte.csv"',
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
const res = authErrorResponse(err);
|
||||
if (res) return res;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { withTransaction } from "@/lib/db";
|
||||
import { authErrorResponse, requireRole } from "@/lib/auth/session";
|
||||
import { isSameOrigin } from "@/lib/origin";
|
||||
import { parseCsvWithHeader, splitCodes } from "@/lib/csv";
|
||||
|
||||
interface ImportRow {
|
||||
rowNum: number;
|
||||
name: string;
|
||||
name_en: string | null;
|
||||
name_pl: string | null;
|
||||
price: number;
|
||||
allergens: string[];
|
||||
additives: string[];
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
if (!isSameOrigin(request)) {
|
||||
return NextResponse.json({ error: "Nicht erlaubt." }, { status: 403 });
|
||||
}
|
||||
try {
|
||||
await requireRole(["staff", "admin"]);
|
||||
const form = await request.formData();
|
||||
const file = form.get("file");
|
||||
if (!(file instanceof File)) {
|
||||
return NextResponse.json({ error: "invalid_input" }, { status: 400 });
|
||||
}
|
||||
|
||||
const { header, rows: cells } = parseCsvWithHeader(await file.text());
|
||||
const nameIdx = header.indexOf("name");
|
||||
const priceIdx = header.indexOf("price");
|
||||
if (nameIdx === -1 || priceIdx === -1) {
|
||||
return NextResponse.json({ error: "missing_columns" }, { status: 400 });
|
||||
}
|
||||
const nameEnIdx = header.indexOf("name_en");
|
||||
const namePlIdx = header.indexOf("name_pl");
|
||||
const allergensIdx = header.indexOf("allergens");
|
||||
const additivesIdx = header.indexOf("additives");
|
||||
|
||||
const rows: ImportRow[] = [];
|
||||
const skipped: { row: number; reason: string }[] = [];
|
||||
cells.forEach((c, i) => {
|
||||
const rowNum = i + 2; // 1-indexiert + Kopfzeile
|
||||
const name = (c[nameIdx] ?? "").trim();
|
||||
if (!name) {
|
||||
skipped.push({ row: rowNum, reason: "Name fehlt" });
|
||||
return;
|
||||
}
|
||||
const priceRaw = (c[priceIdx] ?? "").trim().replace(",", ".");
|
||||
const price = Number.parseFloat(priceRaw);
|
||||
if (Number.isNaN(price) || price < 0) {
|
||||
skipped.push({ row: rowNum, reason: `Ungültiger Preis „${c[priceIdx] ?? ""}“` });
|
||||
return;
|
||||
}
|
||||
rows.push({
|
||||
rowNum,
|
||||
name,
|
||||
name_en: nameEnIdx >= 0 ? c[nameEnIdx]?.trim() || null : null,
|
||||
name_pl: namePlIdx >= 0 ? c[namePlIdx]?.trim() || null : null,
|
||||
price,
|
||||
allergens: allergensIdx >= 0 ? splitCodes(c[allergensIdx]) : [],
|
||||
additives: additivesIdx >= 0 ? splitCodes(c[additivesIdx]) : [],
|
||||
});
|
||||
});
|
||||
|
||||
let created = 0;
|
||||
let updated = 0;
|
||||
if (rows.length > 0) {
|
||||
await withTransaction(async (client) => {
|
||||
for (const row of rows) {
|
||||
// Gerichtsnamen sind nicht eindeutig (keine DB-Constraint) – bei
|
||||
// mehreren Treffern lieber überspringen als versehentlich alle
|
||||
// gleichnamigen Gerichte mit denselben Werten zu überschreiben.
|
||||
const existing = await client.query<{ id: string }>(
|
||||
"select id from dishes where name = $1",
|
||||
[row.name]
|
||||
);
|
||||
if (existing.rows.length > 1) {
|
||||
skipped.push({
|
||||
row: row.rowNum,
|
||||
reason: `„${row.name}“ ist mehrdeutig (mehrere Gerichte mit diesem Namen) – übersprungen`,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (existing.rows.length === 1) {
|
||||
await client.query(
|
||||
`update dishes set name_en = $1, name_pl = $2, price = $3, allergens = $4, additives = $5
|
||||
where id = $6`,
|
||||
[row.name_en, row.name_pl, row.price, row.allergens, row.additives, existing.rows[0].id]
|
||||
);
|
||||
updated++;
|
||||
} else {
|
||||
await client.query(
|
||||
`insert into dishes (name, name_en, name_pl, price, allergens, additives)
|
||||
values ($1, $2, $3, $4, $5, $6)`,
|
||||
[row.name, row.name_en, row.name_pl, row.price, row.allergens, row.additives]
|
||||
);
|
||||
created++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({ created, updated, skipped });
|
||||
} catch (err) {
|
||||
const res = authErrorResponse(err);
|
||||
if (res) return res;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { getSettings } from "@/lib/db/settings";
|
||||
import { getSettings, type LabelingMode } from "@/lib/db/settings";
|
||||
import { authErrorResponse, requireRole } from "@/lib/auth/session";
|
||||
import { isSameOrigin } from "@/lib/origin";
|
||||
|
||||
@@ -8,14 +8,58 @@ export async function GET() {
|
||||
return NextResponse.json(await getSettings());
|
||||
}
|
||||
|
||||
interface SettingsPatchBody {
|
||||
colors?: Record<string, string>;
|
||||
labeling_mode?: LabelingMode;
|
||||
labeling_notice?: string;
|
||||
labeling_notice_en?: string | null;
|
||||
labeling_notice_pl?: string | null;
|
||||
}
|
||||
|
||||
export async function PATCH(request: Request) {
|
||||
if (!isSameOrigin(request)) {
|
||||
return NextResponse.json({ error: "Nicht erlaubt." }, { status: 403 });
|
||||
}
|
||||
try {
|
||||
await requireRole(["admin"]);
|
||||
const { colors } = (await request.json()) as { colors: Record<string, string> };
|
||||
await query("update settings set colors = $1 where id = 1", [JSON.stringify(colors)]);
|
||||
// Farben bleiben admin-only wie bisher; die Allergen-/Zusatzstoff-
|
||||
// Anzeige darf auch Kantinenpersonal umschalten/bearbeiten.
|
||||
const session = await requireRole(["staff", "admin"]);
|
||||
const body = (await request.json()) as SettingsPatchBody;
|
||||
|
||||
const sets: string[] = [];
|
||||
const params: unknown[] = [];
|
||||
|
||||
if (body.colors !== undefined) {
|
||||
if (session.user.role !== "admin") {
|
||||
return NextResponse.json({ error: "forbidden" }, { status: 403 });
|
||||
}
|
||||
params.push(JSON.stringify(body.colors));
|
||||
sets.push(`colors = $${params.length}`);
|
||||
}
|
||||
if (body.labeling_mode !== undefined) {
|
||||
if (body.labeling_mode !== "detailed" && body.labeling_mode !== "notice") {
|
||||
return NextResponse.json({ error: "invalid_input" }, { status: 400 });
|
||||
}
|
||||
params.push(body.labeling_mode);
|
||||
sets.push(`labeling_mode = $${params.length}`);
|
||||
}
|
||||
if (body.labeling_notice !== undefined) {
|
||||
params.push(body.labeling_notice);
|
||||
sets.push(`labeling_notice = $${params.length}`);
|
||||
}
|
||||
if (body.labeling_notice_en !== undefined) {
|
||||
params.push(body.labeling_notice_en);
|
||||
sets.push(`labeling_notice_en = $${params.length}`);
|
||||
}
|
||||
if (body.labeling_notice_pl !== undefined) {
|
||||
params.push(body.labeling_notice_pl);
|
||||
sets.push(`labeling_notice_pl = $${params.length}`);
|
||||
}
|
||||
|
||||
if (sets.length === 0) {
|
||||
return NextResponse.json({ error: "invalid_input" }, { status: 400 });
|
||||
}
|
||||
await query(`update settings set ${sets.join(", ")} where id = 1`, params);
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
const res = authErrorResponse(err);
|
||||
|
||||
@@ -80,12 +80,20 @@ export async function GET() {
|
||||
<guid isPermaLink="false">${appUrl}/feed.xml#${iso}</guid>
|
||||
<pubDate>${pubDate}</pubDate>
|
||||
<description><![CDATA[${dayContent}]]></description>
|
||||
<content:encoded><![CDATA[${dayContent}]]></content:encoded>
|
||||
</item>`;
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
// "description" gilt bei vielen Feed-Readern (Thunderbird, Outlook,
|
||||
// etliche Apps) als reine Kurzfassung/Vorschau und wird eigenmächtig
|
||||
// gekürzt – dadurch war z. B. bei mehreren Essenszeiten pro Tag oft nur
|
||||
// die erste sichtbar. "content:encoded" (RSS-Content-Modul) gilt als
|
||||
// vollständiger Artikeltext und wird von den meisten Readern
|
||||
// ungekürzt angezeigt, wenn vorhanden – redundant zu description für
|
||||
// Reader ohne Unterstützung des Moduls.
|
||||
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0">
|
||||
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
|
||||
<channel>
|
||||
<title>${escapeXml(SITE_TITLE)} – Speiseplan</title>
|
||||
<link>${appUrl}</link>
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import CodeListManager from "@/components/CodeListManager";
|
||||
import LabelingNoticeEditor from "@/components/LabelingNoticeEditor";
|
||||
|
||||
export default function KennzeichnungPage() {
|
||||
const translateEnabled = !!process.env.DEEPL_API_KEY;
|
||||
return (
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
<CodeListManager table="allergens" translateEnabled={translateEnabled} />
|
||||
<CodeListManager table="additives" translateEnabled={translateEnabled} />
|
||||
<div className="flex flex-col gap-6">
|
||||
<LabelingNoticeEditor />
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
<CodeListManager table="allergens" translateEnabled={translateEnabled} />
|
||||
<CodeListManager table="additives" translateEnabled={translateEnabled} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
+60
-31
@@ -42,6 +42,7 @@ export default async function Home({
|
||||
]);
|
||||
|
||||
const logo = logoUrl(settings?.logo_path);
|
||||
const labelingDetailed = (settings?.labeling_mode ?? "detailed") !== "notice";
|
||||
|
||||
return (
|
||||
<div className="flex-1 px-4 py-6 max-w-[1600px] mx-auto w-full">
|
||||
@@ -99,7 +100,12 @@ export default async function Home({
|
||||
</header>
|
||||
|
||||
{/* Mobil: Tag (Standard) oder Woche umschaltbar */}
|
||||
<PublicMobileMenu monday={monday} sections={sections} entries={entries} />
|
||||
<PublicMobileMenu
|
||||
monday={monday}
|
||||
sections={sections}
|
||||
entries={entries}
|
||||
showLabeling={labelingDetailed}
|
||||
/>
|
||||
|
||||
{/* Ab "sm": klassische Wochentabelle */}
|
||||
<div className="hidden sm:block">
|
||||
@@ -148,7 +154,9 @@ export default async function Home({
|
||||
<span className="font-bold">
|
||||
{localized(e.dish, locale)}
|
||||
</span>
|
||||
{codes && <sup className="dish-codes">{codes}</sup>}
|
||||
{labelingDetailed && codes && (
|
||||
<sup className="dish-codes">{codes}</sup>
|
||||
)}
|
||||
{" – "}
|
||||
{formatPrice(e.dish.price)}
|
||||
</div>
|
||||
@@ -163,35 +171,56 @@ export default async function Home({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Allergene & Zusatzstoffe: Legende zu den Kürzeln bei den Gerichten */}
|
||||
<section className="mt-8 grid gap-6 sm:grid-cols-2 text-sm text-gray-700">
|
||||
<div>
|
||||
<h2 className="font-bold text-[var(--c-primary)] mb-2">
|
||||
{dict.publicMenu.allergens}
|
||||
</h2>
|
||||
<ul className="space-y-0.5">
|
||||
{allergens.map((a) => (
|
||||
<li key={a.code}>
|
||||
<span className="font-semibold">{a.code}</span> –{" "}
|
||||
{localized(a, locale)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="font-bold text-[var(--c-primary)] mb-2">
|
||||
{dict.publicMenu.additives}
|
||||
</h2>
|
||||
<ul className="space-y-0.5">
|
||||
{additives.map((a) => (
|
||||
<li key={a.code}>
|
||||
<span className="font-semibold">{a.code}</span> –{" "}
|
||||
{localized(a, locale)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
{/* Allergene & Zusatzstoffe: entweder Legende zu den Kürzeln bei den
|
||||
Gerichten, oder – falls im Hinweismodus – nur ein Hinweistext. */}
|
||||
{labelingDetailed ? (
|
||||
<section className="mt-8 grid gap-6 sm:grid-cols-2 text-sm text-gray-700">
|
||||
<div>
|
||||
<h2 className="font-bold text-[var(--c-primary)] mb-2">
|
||||
{dict.publicMenu.allergens}
|
||||
</h2>
|
||||
<ul className="space-y-0.5">
|
||||
{allergens.map((a) => (
|
||||
<li key={a.code}>
|
||||
<span className="font-semibold">{a.code}</span> –{" "}
|
||||
{localized(a, locale)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="font-bold text-[var(--c-primary)] mb-2">
|
||||
{dict.publicMenu.additives}
|
||||
</h2>
|
||||
<ul className="space-y-0.5">
|
||||
{additives.map((a) => (
|
||||
<li key={a.code}>
|
||||
<span className="font-semibold">{a.code}</span> –{" "}
|
||||
{localized(a, locale)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
) : (
|
||||
settings && (
|
||||
<section className="mt-8 text-sm text-gray-700">
|
||||
<h2 className="font-bold text-[var(--c-primary)] mb-2">
|
||||
{dict.publicMenu.labelingNoticeTitle}
|
||||
</h2>
|
||||
<p>
|
||||
{localized(
|
||||
{
|
||||
name: settings.labeling_notice,
|
||||
name_en: settings.labeling_notice_en,
|
||||
name_pl: settings.labeling_notice_pl,
|
||||
},
|
||||
locale
|
||||
)}
|
||||
</p>
|
||||
</section>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ export default function CodeListManager({
|
||||
namePl: string;
|
||||
} | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [notice, setNotice] = useState<string | null>(null);
|
||||
const [ioBusy, setIoBusy] = useState(false);
|
||||
const [translateState, setTranslateState] = useState<"idle" | "busy" | "done">(
|
||||
"idle"
|
||||
);
|
||||
@@ -125,12 +127,77 @@ export default function CodeListManager({
|
||||
}
|
||||
}
|
||||
|
||||
async function exportItems() {
|
||||
setError(null);
|
||||
setNotice(null);
|
||||
const res = await fetch(`/api/${table}/export`);
|
||||
if (!res.ok) {
|
||||
setError(formatMessage(dict.codeList.exportError, { message: String(res.status) }));
|
||||
return;
|
||||
}
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = table === "allergens" ? "allergene.csv" : "zusatzstoffe.csv";
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async function importItems(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
const file = e.target.files?.[0];
|
||||
e.target.value = "";
|
||||
if (!file) return;
|
||||
setError(null);
|
||||
setNotice(null);
|
||||
setIoBusy(true);
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
const res = await fetch(`/api/${table}/import`, { method: "POST", body: fd });
|
||||
setIoBusy(false);
|
||||
if (!res.ok) {
|
||||
setError(formatMessage(dict.codeList.importError, { message: String(res.status) }));
|
||||
return;
|
||||
}
|
||||
const data = (await res.json()) as {
|
||||
created: number;
|
||||
updated: number;
|
||||
skipped: { row: number; reason: string }[];
|
||||
};
|
||||
let msg = formatMessage(dict.codeList.importSuccess, {
|
||||
created: data.created,
|
||||
updated: data.updated,
|
||||
});
|
||||
if (data.skipped.length > 0) {
|
||||
const reasons = data.skipped
|
||||
.map((s) => formatMessage(dict.codeList.importSkippedRow, s))
|
||||
.join("; ");
|
||||
msg +=
|
||||
" " + formatMessage(dict.codeList.importSkipped, { count: data.skipped.length, reasons });
|
||||
}
|
||||
setNotice(msg);
|
||||
await load();
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="card">
|
||||
<div className="flex items-center gap-3 mb-3">
|
||||
<h2 className="text-lg font-bold text-[var(--c-primary)] mr-auto">
|
||||
{title}
|
||||
</h2>
|
||||
<button type="button" className="btn btn-neutral" onClick={exportItems}>
|
||||
{dict.codeList.exportButton}
|
||||
</button>
|
||||
<label className="btn btn-neutral cursor-pointer">
|
||||
{dict.codeList.importButton}
|
||||
<input
|
||||
type="file"
|
||||
accept=".csv,text/csv"
|
||||
className="hidden"
|
||||
onChange={importItems}
|
||||
disabled={ioBusy}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-add"
|
||||
@@ -148,6 +215,7 @@ export default function CodeListManager({
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{notice && <p className="mb-2 text-sm text-green-700">{notice}</p>}
|
||||
|
||||
{editing && (
|
||||
<form onSubmit={save} className="mb-3 space-y-2 border-b border-gray-200 pb-3">
|
||||
|
||||
+93
-13
@@ -40,10 +40,13 @@ export default function DishManager({
|
||||
const [additives, setAdditives] = useState<CodeItem[]>([]);
|
||||
const [form, setForm] = useState<DishForm | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [notice, setNotice] = useState<string | null>(null);
|
||||
const [ioBusy, setIoBusy] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [selected, setSelected] = useState<Set<string>>(new Set());
|
||||
const [bulkBusy, setBulkBusy] = useState(false);
|
||||
const [search, setSearch] = useState("");
|
||||
const [labelingDetailed, setLabelingDetailed] = useState(true);
|
||||
const [translateState, setTranslateState] = useState<"idle" | "busy" | "done">(
|
||||
"idle"
|
||||
);
|
||||
@@ -55,10 +58,11 @@ export default function DishManager({
|
||||
}, [dishes, search]);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
const [dishesRes, allergensRes, additivesRes] = await Promise.all([
|
||||
const [dishesRes, allergensRes, additivesRes, settingsRes] = await Promise.all([
|
||||
fetch("/api/dishes"),
|
||||
fetch("/api/allergens"),
|
||||
fetch("/api/additives"),
|
||||
fetch("/api/settings"),
|
||||
]);
|
||||
if (!dishesRes.ok || !allergensRes.ok || !additivesRes.ok) {
|
||||
setError(formatMessage(dict.dishManager.loadError, { message: "load failed" }));
|
||||
@@ -67,6 +71,10 @@ export default function DishManager({
|
||||
setAllergens(await allergensRes.json());
|
||||
setAdditives(await additivesRes.json());
|
||||
}
|
||||
if (settingsRes.ok) {
|
||||
const settings = await settingsRes.json();
|
||||
setLabelingDetailed((settings?.labeling_mode ?? "detailed") !== "notice");
|
||||
}
|
||||
setLoading(false);
|
||||
}, [dict]);
|
||||
|
||||
@@ -219,6 +227,58 @@ export default function DishManager({
|
||||
}
|
||||
}
|
||||
|
||||
async function exportDishes() {
|
||||
setError(null);
|
||||
setNotice(null);
|
||||
const res = await fetch("/api/dishes/export");
|
||||
if (!res.ok) {
|
||||
setError(formatMessage(dict.dishManager.exportError, { message: String(res.status) }));
|
||||
return;
|
||||
}
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "gerichte.csv";
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async function importDishes(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
const file = e.target.files?.[0];
|
||||
e.target.value = "";
|
||||
if (!file) return;
|
||||
setError(null);
|
||||
setNotice(null);
|
||||
setIoBusy(true);
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
const res = await fetch("/api/dishes/import", { method: "POST", body: fd });
|
||||
setIoBusy(false);
|
||||
if (!res.ok) {
|
||||
setError(formatMessage(dict.dishManager.importError, { message: String(res.status) }));
|
||||
return;
|
||||
}
|
||||
const data = (await res.json()) as {
|
||||
created: number;
|
||||
updated: number;
|
||||
skipped: { row: number; reason: string }[];
|
||||
};
|
||||
let msg = formatMessage(dict.dishManager.importSuccess, {
|
||||
created: data.created,
|
||||
updated: data.updated,
|
||||
});
|
||||
if (data.skipped.length > 0) {
|
||||
const reasons = data.skipped
|
||||
.map((s) => formatMessage(dict.dishManager.importSkippedRow, s))
|
||||
.join("; ");
|
||||
msg +=
|
||||
" " + formatMessage(dict.dishManager.importSkipped, { count: data.skipped.length, reasons });
|
||||
}
|
||||
setNotice(msg);
|
||||
await load();
|
||||
}
|
||||
|
||||
const allSelected =
|
||||
visible.length > 0 && visible.every((d) => selected.has(d.id));
|
||||
|
||||
@@ -228,6 +288,19 @@ export default function DishManager({
|
||||
<h1 className="text-xl font-bold text-[var(--c-primary)] mr-auto">
|
||||
{dict.dishManager.title}
|
||||
</h1>
|
||||
<button type="button" className="btn btn-neutral" onClick={exportDishes}>
|
||||
{dict.dishManager.exportButton}
|
||||
</button>
|
||||
<label className="btn btn-neutral cursor-pointer">
|
||||
{dict.dishManager.importButton}
|
||||
<input
|
||||
type="file"
|
||||
accept=".csv,text/csv"
|
||||
className="hidden"
|
||||
onChange={importDishes}
|
||||
disabled={ioBusy}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-add"
|
||||
@@ -245,6 +318,7 @@ export default function DishManager({
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{notice && <p className="mb-3 text-sm text-green-700">{notice}</p>}
|
||||
|
||||
{form && (
|
||||
<form onSubmit={save} className="card mb-4 space-y-4">
|
||||
@@ -322,18 +396,24 @@ export default function DishManager({
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ChipPicker
|
||||
label={dict.codeList.allergensTitle}
|
||||
items={allergens}
|
||||
selected={form.allergens}
|
||||
onToggle={toggleAllergen}
|
||||
/>
|
||||
<ChipPicker
|
||||
label={dict.codeList.additivesTitle}
|
||||
items={additives}
|
||||
selected={form.additives}
|
||||
onToggle={toggleAdditive}
|
||||
/>
|
||||
{labelingDetailed ? (
|
||||
<>
|
||||
<ChipPicker
|
||||
label={dict.codeList.allergensTitle}
|
||||
items={allergens}
|
||||
selected={form.allergens}
|
||||
onToggle={toggleAllergen}
|
||||
/>
|
||||
<ChipPicker
|
||||
label={dict.codeList.additivesTitle}
|
||||
items={additives}
|
||||
selected={form.additives}
|
||||
onToggle={toggleAdditive}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-sm text-gray-500">{dict.dishManager.labelingDisabledHint}</p>
|
||||
)}
|
||||
<div className="flex gap-2">
|
||||
<button type="submit" className="btn btn-add">
|
||||
{dict.common.save}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
"use client";
|
||||
|
||||
// Umschaltung zwischen der detaillierten Allergen-/Zusatzstoff-Auswahl
|
||||
// je Gericht und einem einfachen, editierbaren Hinweistext.
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { formatMessage } from "@/lib/i18n/shared";
|
||||
import { useDict } from "@/components/i18n/LocaleProvider";
|
||||
import type { LabelingMode } from "@/lib/db/settings";
|
||||
|
||||
export default function LabelingNoticeEditor() {
|
||||
const dict = useDict();
|
||||
const [mode, setMode] = useState<LabelingMode>("detailed");
|
||||
const [noticeDe, setNoticeDe] = useState("");
|
||||
const [noticeEn, setNoticeEn] = useState("");
|
||||
const [noticePl, setNoticePl] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [info, setInfo] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
const res = await fetch("/api/settings");
|
||||
if (!res.ok) {
|
||||
setError(formatMessage(dict.labelingNotice.loadError, { message: String(res.status) }));
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
const data = await res.json();
|
||||
setMode(data.labeling_mode ?? "detailed");
|
||||
setNoticeDe(data.labeling_notice ?? "");
|
||||
setNoticeEn(data.labeling_notice_en ?? "");
|
||||
setNoticePl(data.labeling_notice_pl ?? "");
|
||||
setLoading(false);
|
||||
}, [dict]);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
async function save() {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setInfo(null);
|
||||
const res = await fetch("/api/settings", {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
labeling_mode: mode,
|
||||
labeling_notice: noticeDe.trim(),
|
||||
labeling_notice_en: noticeEn.trim() || null,
|
||||
labeling_notice_pl: noticePl.trim() || null,
|
||||
}),
|
||||
});
|
||||
setBusy(false);
|
||||
if (!res.ok) {
|
||||
setError(formatMessage(dict.labelingNotice.saveError, { message: String(res.status) }));
|
||||
return;
|
||||
}
|
||||
setInfo(dict.labelingNotice.saved);
|
||||
}
|
||||
|
||||
if (loading) return null;
|
||||
|
||||
return (
|
||||
<section className="card">
|
||||
<h2 className="font-semibold mb-2">{dict.labelingNotice.title}</h2>
|
||||
<p className="text-sm text-gray-600 mb-3">{dict.labelingNotice.hint}</p>
|
||||
|
||||
{error && (
|
||||
<p className="mb-3 text-sm text-[var(--c-del)]" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{info && <p className="mb-3 text-sm text-green-700">{info}</p>}
|
||||
|
||||
<div className="flex flex-col gap-2 mb-4">
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="radio"
|
||||
name="labeling-mode"
|
||||
checked={mode === "detailed"}
|
||||
onChange={() => setMode("detailed")}
|
||||
/>
|
||||
{dict.labelingNotice.modeDetailed}
|
||||
</label>
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="radio"
|
||||
name="labeling-mode"
|
||||
checked={mode === "notice"}
|
||||
onChange={() => setMode("notice")}
|
||||
/>
|
||||
{dict.labelingNotice.modeNotice}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3 mb-4">
|
||||
<div>
|
||||
<label className="label" htmlFor="labeling-notice-de">
|
||||
{dict.labelingNotice.noticeDeLabel}
|
||||
</label>
|
||||
<textarea
|
||||
id="labeling-notice-de"
|
||||
className="input"
|
||||
rows={2}
|
||||
value={noticeDe}
|
||||
onChange={(e) => setNoticeDe(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="label" htmlFor="labeling-notice-en">
|
||||
{dict.labelingNotice.noticeEnLabel}
|
||||
</label>
|
||||
<textarea
|
||||
id="labeling-notice-en"
|
||||
className="input"
|
||||
rows={2}
|
||||
value={noticeEn}
|
||||
onChange={(e) => setNoticeEn(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="label" htmlFor="labeling-notice-pl">
|
||||
{dict.labelingNotice.noticePlLabel}
|
||||
</label>
|
||||
<textarea
|
||||
id="labeling-notice-pl"
|
||||
className="input"
|
||||
rows={2}
|
||||
value={noticePl}
|
||||
onChange={(e) => setNoticePl(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="button" className="btn btn-add" onClick={save} disabled={busy}>
|
||||
{dict.labelingNotice.save}
|
||||
</button>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -27,10 +27,12 @@ export default function PublicMobileMenu({
|
||||
monday,
|
||||
sections,
|
||||
entries,
|
||||
showLabeling,
|
||||
}: {
|
||||
monday: string;
|
||||
sections: Section[];
|
||||
entries: MenuEntry[];
|
||||
showLabeling: boolean;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const dict = useDict();
|
||||
@@ -86,7 +88,9 @@ export default function PublicMobileMenu({
|
||||
<span className="font-semibold">
|
||||
{localized(e.dish, locale)}
|
||||
</span>
|
||||
{codes && <sup className="dish-codes">{codes}</sup>}{" "}
|
||||
{showLabeling && codes && (
|
||||
<sup className="dish-codes">{codes}</sup>
|
||||
)}{" "}
|
||||
– {formatPrice(e.dish.price)}
|
||||
</p>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
-- Umschaltbare Anzeige der Allergene/Zusatzstoffe: entweder die
|
||||
-- detaillierte Auswahl je Gericht (bisheriges Verhalten) oder
|
||||
-- stattdessen nur ein von Personal/Admin editierbarer Hinweistext
|
||||
-- (z. B. "Bei Fragen bitte das Kantinen-Team fragen").
|
||||
alter table settings
|
||||
add column labeling_mode text not null default 'detailed'
|
||||
check (labeling_mode in ('detailed', 'notice')),
|
||||
add column labeling_notice text not null default
|
||||
'Bei Fragen zu Allergenen und Zusatzstoffen wenden Sie sich bitte an das Kantinen-Team.',
|
||||
add column labeling_notice_en text,
|
||||
add column labeling_notice_pl text;
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
import "server-only";
|
||||
|
||||
// Minimaler RFC-4180-artiger CSV-Parser/-Serializer für Import/Export der
|
||||
// Gerichte-/Allergen-/Zusatzstofflisten. Bewusst ohne npm-Abhängigkeit
|
||||
// (Projekt-Stil: kein ORM, keine Validierungs-Library, minimale Deps) –
|
||||
// deckt quoted Felder mit eingebetteten Kommas/Anführungszeichen/
|
||||
// Zeilenumbrüchen ab, da Gerichtsnamen Kommas enthalten können.
|
||||
|
||||
export function parseCsv(text: string): string[][] {
|
||||
const rows: string[][] = [];
|
||||
let row: string[] = [];
|
||||
let field = "";
|
||||
let inQuotes = false;
|
||||
let i = 0;
|
||||
const len = text.length;
|
||||
|
||||
function pushField() {
|
||||
row.push(field);
|
||||
field = "";
|
||||
}
|
||||
function pushRow() {
|
||||
pushField();
|
||||
rows.push(row);
|
||||
row = [];
|
||||
}
|
||||
|
||||
while (i < len) {
|
||||
const c = text[i];
|
||||
if (inQuotes) {
|
||||
if (c === '"') {
|
||||
if (text[i + 1] === '"') {
|
||||
field += '"';
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
inQuotes = false;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
field += c;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (c === '"') {
|
||||
inQuotes = true;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (c === ",") {
|
||||
pushField();
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (c === "\r") {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (c === "\n") {
|
||||
pushRow();
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
field += c;
|
||||
i++;
|
||||
}
|
||||
// Letzte Zeile ohne abschließenden Zeilenumbruch noch anhängen.
|
||||
if (field !== "" || row.length > 0) pushRow();
|
||||
// Leere Zeilen überspringen (z. B. durch einen abschließenden Zeilenumbruch).
|
||||
return rows.filter((r) => !(r.length === 1 && r[0].trim() === ""));
|
||||
}
|
||||
|
||||
function csvField(value: string): string {
|
||||
if (/[",\r\n]/.test(value)) {
|
||||
return `"${value.replace(/"/g, '""')}"`;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function toCsv(rows: string[][]): string {
|
||||
return rows.map((row) => row.map(csvField).join(",")).join("\r\n") + "\r\n";
|
||||
}
|
||||
|
||||
/** Kopfzeile in Kleinbuchstaben, damit der Import tolerant gegenüber Groß-/
|
||||
* Kleinschreibung und Spaltenreihenfolge ist. */
|
||||
export function parseCsvWithHeader(text: string): { header: string[]; rows: string[][] } {
|
||||
const table = parseCsv(text);
|
||||
if (table.length === 0) return { header: [], rows: [] };
|
||||
const [header, ...rows] = table;
|
||||
return { header: header.map((h) => h.trim().toLowerCase()), rows };
|
||||
}
|
||||
|
||||
/** Codes einer Zelle wie "A;G;2" in einzelne, getrimmte Kürzel zerlegen. */
|
||||
export function splitCodes(cell: string | undefined): string[] {
|
||||
return (cell ?? "")
|
||||
.split(";")
|
||||
.map((c) => c.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
+45
-1
@@ -1,5 +1,5 @@
|
||||
import "server-only";
|
||||
import { query, queryOne } from "@/lib/db";
|
||||
import { query, queryOne, withTransaction } from "@/lib/db";
|
||||
import type { CodeItem } from "@/lib/types";
|
||||
|
||||
// "allergens"/"additives" sind identisch aufgebaute Tabellen (Kürzel +
|
||||
@@ -39,3 +39,47 @@ export async function updateCode(
|
||||
export async function deleteCode(table: CodeTable, code: string): Promise<void> {
|
||||
await query(`delete from ${table} where code = $1`, [code]);
|
||||
}
|
||||
|
||||
export interface CodeImportRow {
|
||||
code: string;
|
||||
name: string;
|
||||
name_en: string | null;
|
||||
name_pl: string | null;
|
||||
}
|
||||
|
||||
/** CSV-Import: legt neue Kürzel an, bestehende (gleicher Code) werden
|
||||
* aktualisiert – ein doppelter Code innerhalb derselben Datei
|
||||
* aktualisiert also einfach zweimal statt einen Fehler zu werfen. */
|
||||
export async function importCodes(
|
||||
table: CodeTable,
|
||||
rows: CodeImportRow[]
|
||||
): Promise<{ created: number; updated: number }> {
|
||||
return withTransaction(async (client) => {
|
||||
const existing = await client.query<{ code: string }>(`select code from ${table}`);
|
||||
const known = new Set(existing.rows.map((r) => r.code));
|
||||
const maxRow = await client.query<{ sort: number }>(
|
||||
`select coalesce(max(sort), 0) as sort from ${table}`
|
||||
);
|
||||
let nextSort = (maxRow.rows[0]?.sort ?? 0) + 1;
|
||||
let created = 0;
|
||||
let updated = 0;
|
||||
|
||||
for (const row of rows) {
|
||||
if (known.has(row.code)) {
|
||||
await client.query(
|
||||
`update ${table} set name = $1, name_en = $2, name_pl = $3 where code = $4`,
|
||||
[row.name, row.name_en, row.name_pl, row.code]
|
||||
);
|
||||
updated++;
|
||||
} else {
|
||||
await client.query(
|
||||
`insert into ${table} (code, name, name_en, name_pl, sort) values ($1, $2, $3, $4, $5)`,
|
||||
[row.code, row.name, row.name_en, row.name_pl, nextSort++]
|
||||
);
|
||||
known.add(row.code);
|
||||
created++;
|
||||
}
|
||||
}
|
||||
return { created, updated };
|
||||
});
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,14 +1,22 @@
|
||||
import "server-only";
|
||||
import { queryOne } from "@/lib/db";
|
||||
|
||||
export type LabelingMode = "detailed" | "notice";
|
||||
|
||||
export interface Settings {
|
||||
colors: Record<string, string>;
|
||||
logo_path: string | null;
|
||||
favicon_path: string | null;
|
||||
labeling_mode: LabelingMode;
|
||||
labeling_notice: string;
|
||||
labeling_notice_en: string | null;
|
||||
labeling_notice_pl: string | null;
|
||||
}
|
||||
|
||||
export async function getSettings(): Promise<Settings | null> {
|
||||
return queryOne<Settings>(
|
||||
"select colors, logo_path, favicon_path from settings where id = 1"
|
||||
`select colors, logo_path, favicon_path, labeling_mode,
|
||||
labeling_notice, labeling_notice_en, labeling_notice_pl
|
||||
from settings where id = 1`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ const de = {
|
||||
weekTab: "Woche",
|
||||
allergens: "Allergene",
|
||||
additives: "Zusatzstoffe",
|
||||
labelingNoticeTitle: "Allergene & Zusatzstoffe",
|
||||
suggestDish: "Rezept vorschlagen",
|
||||
noEntry: "–",
|
||||
rssFeed: "RSS-Feed abonnieren",
|
||||
@@ -106,6 +107,15 @@ const de = {
|
||||
loadError: "Laden fehlgeschlagen: {message}",
|
||||
saveError: "Speichern fehlgeschlagen: {message}",
|
||||
deleteError: "Löschen fehlgeschlagen: {message}",
|
||||
exportButton: "Exportieren",
|
||||
importButton: "Importieren",
|
||||
exportError: "Export fehlgeschlagen: {message}",
|
||||
importError: "Import fehlgeschlagen: {message}",
|
||||
importSuccess: "{created} neu angelegt, {updated} aktualisiert.",
|
||||
importSkipped: "{count} Zeile(n) übersprungen: {reasons}",
|
||||
importSkippedRow: "Zeile {row}: {reason}",
|
||||
labelingDisabledHint:
|
||||
"Allergene/Zusatzstoffe sind aktuell deaktiviert (Hinweismodus aktiv, siehe „Allergene & Zusatzstoffe“).",
|
||||
},
|
||||
codeList: {
|
||||
allergensTitle: "Allergene",
|
||||
@@ -119,6 +129,13 @@ const de = {
|
||||
loadError: "Laden fehlgeschlagen: {message}",
|
||||
saveError: "Speichern fehlgeschlagen: {message}",
|
||||
deleteError: "Löschen fehlgeschlagen: {message}",
|
||||
exportButton: "Exportieren",
|
||||
importButton: "Importieren",
|
||||
exportError: "Export fehlgeschlagen: {message}",
|
||||
importError: "Import fehlgeschlagen: {message}",
|
||||
importSuccess: "{created} neu angelegt, {updated} aktualisiert.",
|
||||
importSkipped: "{count} Zeile(n) übersprungen: {reasons}",
|
||||
importSkippedRow: "Zeile {row}: {reason}",
|
||||
},
|
||||
sectionManager: {
|
||||
title: "Essenszeiten",
|
||||
@@ -185,6 +202,20 @@ const de = {
|
||||
confirmRemoveLogo: "Logo wirklich entfernen?",
|
||||
confirmRemoveFavicon: "Favicon wirklich entfernen?",
|
||||
},
|
||||
labelingNotice: {
|
||||
title: "Anzeige von Allergenen & Zusatzstoffen",
|
||||
hint:
|
||||
"Standardmäßig sieht jeder Gast eine detaillierte Auswahl der Allergene/Zusatzstoffe je Gericht. Alternativ kann stattdessen nur ein Hinweistext angezeigt werden – die Auswahl je Gericht wird dann auch in der Gerichte-Verwaltung ausgeblendet.",
|
||||
modeDetailed: "Detaillierte Auswahl je Gericht anzeigen",
|
||||
modeNotice: "Nur Hinweistext anzeigen",
|
||||
noticeDeLabel: "Hinweistext (Deutsch)",
|
||||
noticeEnLabel: "Hinweistext (Englisch)",
|
||||
noticePlLabel: "Hinweistext (Polnisch)",
|
||||
save: "Speichern",
|
||||
saved: "Gespeichert.",
|
||||
loadError: "Laden fehlgeschlagen: {message}",
|
||||
saveError: "Speichern fehlgeschlagen: {message}",
|
||||
},
|
||||
passkeys: {
|
||||
title: "Passkeys",
|
||||
hint: "Mit einem Passkey (Fingerabdruck, Gesichtserkennung oder Sicherheitsschlüssel) kannst du dich künftig ohne Passwort anmelden. Passkeys gelten pro Domain – nach einem Domainwechsel müssen sie neu registriert werden.",
|
||||
@@ -319,6 +350,7 @@ const en: Dict = {
|
||||
weekTab: "Week",
|
||||
allergens: "Allergens",
|
||||
additives: "Additives",
|
||||
labelingNoticeTitle: "Allergens & additives",
|
||||
suggestDish: "Suggest a dish",
|
||||
noEntry: "–",
|
||||
rssFeed: "Subscribe to RSS feed",
|
||||
@@ -362,6 +394,15 @@ const en: Dict = {
|
||||
loadError: "Loading failed: {message}",
|
||||
saveError: "Saving failed: {message}",
|
||||
deleteError: "Deleting failed: {message}",
|
||||
exportButton: "Export",
|
||||
importButton: "Import",
|
||||
exportError: "Export failed: {message}",
|
||||
importError: "Import failed: {message}",
|
||||
importSuccess: "{created} created, {updated} updated.",
|
||||
importSkipped: "{count} row(s) skipped: {reasons}",
|
||||
importSkippedRow: "Row {row}: {reason}",
|
||||
labelingDisabledHint:
|
||||
"Allergens/additives are currently disabled (notice mode active, see \"Allergens & additives\").",
|
||||
},
|
||||
codeList: {
|
||||
allergensTitle: "Allergens",
|
||||
@@ -375,6 +416,13 @@ const en: Dict = {
|
||||
loadError: "Loading failed: {message}",
|
||||
saveError: "Saving failed: {message}",
|
||||
deleteError: "Deleting failed: {message}",
|
||||
exportButton: "Export",
|
||||
importButton: "Import",
|
||||
exportError: "Export failed: {message}",
|
||||
importError: "Import failed: {message}",
|
||||
importSuccess: "{created} created, {updated} updated.",
|
||||
importSkipped: "{count} row(s) skipped: {reasons}",
|
||||
importSkippedRow: "Row {row}: {reason}",
|
||||
},
|
||||
sectionManager: {
|
||||
title: "Meal times",
|
||||
@@ -441,6 +489,20 @@ const en: Dict = {
|
||||
confirmRemoveLogo: "Really remove the logo?",
|
||||
confirmRemoveFavicon: "Really remove the favicon?",
|
||||
},
|
||||
labelingNotice: {
|
||||
title: "Allergen & additive display",
|
||||
hint:
|
||||
"By default every guest sees a detailed allergen/additive selection per dish. Alternatively, only a notice text can be shown instead – the per-dish selection is then also hidden in the dish manager.",
|
||||
modeDetailed: "Show detailed selection per dish",
|
||||
modeNotice: "Show only notice text",
|
||||
noticeDeLabel: "Notice text (German)",
|
||||
noticeEnLabel: "Notice text (English)",
|
||||
noticePlLabel: "Notice text (Polish)",
|
||||
save: "Save",
|
||||
saved: "Saved.",
|
||||
loadError: "Loading failed: {message}",
|
||||
saveError: "Saving failed: {message}",
|
||||
},
|
||||
passkeys: {
|
||||
title: "Passkeys",
|
||||
hint: "With a passkey (fingerprint, face recognition, or a security key) you can sign in without a password in the future. Passkeys are bound to a domain – after a domain change they need to be registered again.",
|
||||
@@ -573,6 +635,7 @@ const pl: Dict = {
|
||||
weekTab: "Tydzień",
|
||||
allergens: "Alergeny",
|
||||
additives: "Dodatki",
|
||||
labelingNoticeTitle: "Alergeny i dodatki",
|
||||
suggestDish: "Zaproponuj danie",
|
||||
noEntry: "–",
|
||||
rssFeed: "Subskrybuj kanał RSS",
|
||||
@@ -616,6 +679,15 @@ const pl: Dict = {
|
||||
loadError: "Wczytywanie nie powiodło się: {message}",
|
||||
saveError: "Zapisywanie nie powiodło się: {message}",
|
||||
deleteError: "Usuwanie nie powiodło się: {message}",
|
||||
exportButton: "Eksportuj",
|
||||
importButton: "Importuj",
|
||||
exportError: "Eksport nie powiódł się: {message}",
|
||||
importError: "Import nie powiódł się: {message}",
|
||||
importSuccess: "Utworzono: {created}, zaktualizowano: {updated}.",
|
||||
importSkipped: "Pominięto wierszy: {count}: {reasons}",
|
||||
importSkippedRow: "Wiersz {row}: {reason}",
|
||||
labelingDisabledHint:
|
||||
"Alergeny/dodatki są obecnie wyłączone (aktywny tryb komunikatu, patrz „Alergeny i dodatki”).",
|
||||
},
|
||||
codeList: {
|
||||
allergensTitle: "Alergeny",
|
||||
@@ -629,6 +701,13 @@ const pl: Dict = {
|
||||
loadError: "Wczytywanie nie powiodło się: {message}",
|
||||
saveError: "Zapisywanie nie powiodło się: {message}",
|
||||
deleteError: "Usuwanie nie powiodło się: {message}",
|
||||
exportButton: "Eksportuj",
|
||||
importButton: "Importuj",
|
||||
exportError: "Eksport nie powiódł się: {message}",
|
||||
importError: "Import nie powiódł się: {message}",
|
||||
importSuccess: "Utworzono: {created}, zaktualizowano: {updated}.",
|
||||
importSkipped: "Pominięto wierszy: {count}: {reasons}",
|
||||
importSkippedRow: "Wiersz {row}: {reason}",
|
||||
},
|
||||
sectionManager: {
|
||||
title: "Pory posiłków",
|
||||
@@ -695,6 +774,20 @@ const pl: Dict = {
|
||||
confirmRemoveLogo: "Czy na pewno usunąć logo?",
|
||||
confirmRemoveFavicon: "Czy na pewno usunąć favicon?",
|
||||
},
|
||||
labelingNotice: {
|
||||
title: "Wyświetlanie alergenów i dodatków",
|
||||
hint:
|
||||
"Domyślnie każdy gość widzi szczegółowy wybór alergenów/dodatków dla każdego dania. Alternatywnie można zamiast tego wyświetlić tylko komunikat – wybór dla poszczególnych dań zostanie wtedy również ukryty w zarządzaniu daniami.",
|
||||
modeDetailed: "Pokaż szczegółowy wybór dla każdego dania",
|
||||
modeNotice: "Pokaż tylko komunikat",
|
||||
noticeDeLabel: "Tekst komunikatu (niemiecki)",
|
||||
noticeEnLabel: "Tekst komunikatu (angielski)",
|
||||
noticePlLabel: "Tekst komunikatu (polski)",
|
||||
save: "Zapisz",
|
||||
saved: "Zapisano.",
|
||||
loadError: "Wczytywanie nie powiodło się: {message}",
|
||||
saveError: "Zapisywanie nie powiodło się: {message}",
|
||||
},
|
||||
passkeys: {
|
||||
title: "Klucze dostępu",
|
||||
hint: "Dzięki kluczowi dostępu (odcisk palca, rozpoznawanie twarzy lub klucz bezpieczeństwa) możesz w przyszłości logować się bez hasła. Klucze dostępu są przypisane do domeny – po zmianie domeny trzeba je zarejestrować ponownie.",
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "canteen-menu",
|
||||
"version": "1.6.3",
|
||||
"version": "1.8.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "canteen-menu",
|
||||
"version": "1.6.3",
|
||||
"version": "1.8.0",
|
||||
"dependencies": {
|
||||
"@simplewebauthn/browser": "^13.3.0",
|
||||
"@simplewebauthn/server": "^13.3.2",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "canteen-menu",
|
||||
"version": "1.6.3",
|
||||
"version": "1.8.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"predev": "node --env-file-if-exists=.env.local db/migrate.mjs && node --env-file-if-exists=.env.local scripts/bootstrap-admin.mjs",
|
||||
|
||||
Reference in New Issue
Block a user