Redaktionskalender für das Redaktionsteam
- Planungen mit Art, Status (Idee → In Arbeit → Zur Freigabe → Geplant → Erledigt), Zuständigkeit, Erscheinungstag, Frist, Notizen und Kommentaren - Monatsansicht mit Planungen, Meldungen (online/geplant/Entwurf) und Terminen; Verschieben per Ziehen & Ablegen oder im Dialog (Tastatur) - Ideenspeicher für Planungen ohne Datum - Board nach Status mit Ziehen & Ablegen, Listenansicht mit Tabelle - Filter nach Person („Nur meine“), Art und erledigten Einträgen - „Meldung daraus erstellen“ legt einen verknüpften Entwurf an - „Meine Aufgaben“ auf der Übersicht, überfällige Fristen hervorgehoben - Demo-Planungen im Seed Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fdb6b0e70e
commit
7da1a10af2
19 changed files with 2613 additions and 3 deletions
33
drizzle/0001_redaktionskalender.sql
Normal file
33
drizzle/0001_redaktionskalender.sql
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
CREATE TABLE `editorial_comments` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`item_id` integer NOT NULL,
|
||||
`user_id` integer,
|
||||
`body` text NOT NULL,
|
||||
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
|
||||
FOREIGN KEY (`item_id`) REFERENCES `editorial_items`(`id`) ON UPDATE no action ON DELETE cascade,
|
||||
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE set null
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `editorial_comments_item_idx` ON `editorial_comments` (`item_id`);--> statement-breakpoint
|
||||
CREATE TABLE `editorial_items` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`title` text NOT NULL,
|
||||
`notes` text DEFAULT '' NOT NULL,
|
||||
`kind` text DEFAULT 'post' NOT NULL,
|
||||
`status` text DEFAULT 'idea' NOT NULL,
|
||||
`assignee_id` integer,
|
||||
`date` text DEFAULT '' NOT NULL,
|
||||
`due_date` text DEFAULT '' NOT NULL,
|
||||
`post_id` integer,
|
||||
`page_id` integer,
|
||||
`created_by` integer,
|
||||
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
|
||||
`updated_at` integer DEFAULT (unixepoch()) NOT NULL,
|
||||
FOREIGN KEY (`assignee_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE set null,
|
||||
FOREIGN KEY (`post_id`) REFERENCES `posts`(`id`) ON UPDATE no action ON DELETE set null,
|
||||
FOREIGN KEY (`page_id`) REFERENCES `pages`(`id`) ON UPDATE no action ON DELETE set null,
|
||||
FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE set null
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `editorial_date_idx` ON `editorial_items` (`date`);--> statement-breakpoint
|
||||
CREATE INDEX `editorial_assignee_idx` ON `editorial_items` (`assignee_id`);
|
||||
1203
drizzle/meta/0001_snapshot.json
Normal file
1203
drizzle/meta/0001_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -8,6 +8,13 @@
|
|||
"when": 1790710683402,
|
||||
"tag": "0000_init",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "6",
|
||||
"when": 1790780351202,
|
||||
"tag": "0001_redaktionskalender",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ if (db.select().from(s.pages).all().length && !force) {
|
|||
process.exit(0);
|
||||
}
|
||||
if (force) {
|
||||
for (const t of [s.tiles, s.posts, s.pages, s.events, s.contacts, s.messages, s.media, s.settings]) db.delete(t).run();
|
||||
for (const t of [s.editorialComments, s.editorialItems, s.tiles, s.posts, s.pages, s.events, s.contacts, s.messages, s.media, s.settings]) db.delete(t).run();
|
||||
// alte Upload-Dateien mit entfernen
|
||||
for (const f of fs.readdirSync(UPLOAD_DIR)) fs.rmSync(path.join(UPLOAD_DIR, f), { force: true });
|
||||
}
|
||||
|
|
@ -243,6 +243,25 @@ const eventDefs: (typeof s.events.$inferInsert)[] = [
|
|||
];
|
||||
for (const e of eventDefs) db.insert(s.events).values(e).run();
|
||||
|
||||
// ─── Redaktionskalender ──────────────────────────────────────────────────────
|
||||
|
||||
const teamIds = db.select({ id: s.users.id }).from(s.users).all().map((u) => u.id);
|
||||
const who = (i: number) => (teamIds.length ? teamIds[i % teamIds.length] : null);
|
||||
const planDefs: (typeof s.editorialItems.$inferInsert)[] = [
|
||||
{ title: 'Rückblick Kunstausstellung', kind: 'post', status: 'ready', date: iso(27), dueDate: iso(24), notes: 'Fotos von der Vernissage besorgen (Kreativwerkstatt fragen).\n\nZitat von zwei Künstler:innen einholen.' },
|
||||
{ title: 'Speiseplan November hochladen', kind: 'page', status: 'progress', date: iso(30), dueDate: iso(28), notes: 'PDF kommt von der Küche.' },
|
||||
{ title: 'Interview mit dem neuen Werkstattrat', kind: 'post', status: 'review', date: iso(9), dueDate: iso(6), notes: 'Text liegt vor, Freigabe durch Jonas Pieper steht aus.' },
|
||||
{ title: 'Aushang Weihnachtsferien', kind: 'print', status: 'idea', date: iso(60), notes: 'In Leichter Sprache, mit Piktogrammen.' },
|
||||
{ title: 'Social-Media-Post Tanzabend', kind: 'social', status: 'progress', date: iso(19), dueDate: iso(17) },
|
||||
{ title: 'Portrait: 25 Jahre in der Holzwerkstatt', kind: 'post', status: 'idea', notes: 'Idee von Aylin – Jubilar im Dezember.' },
|
||||
{ title: 'Neue Seite „Fahrdienst“', kind: 'page', status: 'idea', notes: 'Viele Nachfragen im Postfach. Busfahrplan + Ansprechpartner.' },
|
||||
{ title: 'Erste-Hilfe-Kurs bewerben', kind: 'post', status: 'done', date: iso(-20) },
|
||||
{ title: 'Fotos Sommerfest sortieren', kind: 'other', status: 'progress', date: '', dueDate: iso(-2) }
|
||||
];
|
||||
planDefs.forEach((p, i) => db.insert(s.editorialItems).values({ ...p, assigneeId: who(i), createdBy: who(0) }).run());
|
||||
const firstPlan = db.select({ id: s.editorialItems.id }).from(s.editorialItems).get();
|
||||
if (firstPlan && teamIds.length) db.insert(s.editorialComments).values({ itemId: firstPlan.id + 2, userId: teamIds[0], body: 'Habe Jonas heute angeschrieben, Antwort kommt bis Freitag.' }).run();
|
||||
|
||||
db.insert(s.messages).values({ name: 'Petra (Demo)', email: 'petra@example.org', message: 'Hallo! Die App ist super. Könnt ihr auch den Busfahrplan einstellen?' }).run();
|
||||
|
||||
console.log('✔ Demo-Inhalte angelegt.');
|
||||
|
|
|
|||
25
src/lib/admin/actions.ts
Normal file
25
src/lib/admin/actions.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { deserialize } from '$app/forms';
|
||||
import { invalidateAll } from '$app/navigation';
|
||||
import { toasts } from './toast.svelte';
|
||||
|
||||
/**
|
||||
* Ruft eine Form-Action der aktuellen Seite ohne Formular auf (z. B. nach Ziehen & Ablegen),
|
||||
* lädt danach die Daten neu und meldet Fehler als Hinweis.
|
||||
*/
|
||||
export async function callAction(action: string, data: Record<string, string | number | null | undefined>, success?: string) {
|
||||
const body = new FormData();
|
||||
for (const [k, v] of Object.entries(data)) body.set(k, v == null ? '' : String(v));
|
||||
const res = await fetch(`?/${action}`, { method: 'POST', body, headers: { 'x-sveltekit-action': 'true' } });
|
||||
const result = deserialize(await res.text());
|
||||
if (result.type === 'failure') {
|
||||
toasts.show(String(result.data?.error ?? 'Das hat nicht geklappt.'), 'error');
|
||||
return null;
|
||||
}
|
||||
if (result.type === 'error') {
|
||||
toasts.show(result.error?.message ?? 'Das hat nicht geklappt.', 'error');
|
||||
return null;
|
||||
}
|
||||
await invalidateAll();
|
||||
if (success) toasts.show(success);
|
||||
return result.type === 'success' ? (result.data ?? {}) : {};
|
||||
}
|
||||
74
src/lib/admin/calendar/BoardView.svelte
Normal file
74
src/lib/admin/calendar/BoardView.svelte
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<script lang="ts">
|
||||
import Plus from '@lucide/svelte/icons/plus';
|
||||
import EntryChip from './EntryChip.svelte';
|
||||
import { callAction } from '../actions';
|
||||
import { EDITORIAL_STATUS, STATUS_TONE, statusKeys, type CalendarEntry, type EditorialStatus, type TeamMember } from '$lib/editorial';
|
||||
import { formatShort } from '$lib/dates';
|
||||
|
||||
let {
|
||||
plans,
|
||||
team,
|
||||
today,
|
||||
onopen,
|
||||
oncreate
|
||||
}: {
|
||||
plans: CalendarEntry[];
|
||||
team: TeamMember[];
|
||||
today: string;
|
||||
onopen: (e: CalendarEntry) => void;
|
||||
oncreate: (date: string, status?: EditorialStatus) => void;
|
||||
} = $props();
|
||||
|
||||
const columns = $derived(
|
||||
statusKeys.map((s) => ({ status: s, items: plans.filter((p) => p.type === 'plan' && p.status === s) }))
|
||||
);
|
||||
|
||||
let dropTarget = $state<string | null>(null);
|
||||
|
||||
async function drop(e: DragEvent, status: EditorialStatus) {
|
||||
e.preventDefault();
|
||||
dropTarget = null;
|
||||
const raw = e.dataTransfer?.getData('application/x-redaktion');
|
||||
if (!raw) return;
|
||||
const { type, id } = JSON.parse(raw);
|
||||
if (type !== 'plan') return;
|
||||
await callAction('status', { id, status }, `Status: ${EDITORIAL_STATUS[status]}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex gap-4 overflow-x-auto pb-4 -mx-4 px-4 sm:mx-0 sm:px-0 snap-x">
|
||||
{#each columns as col (col.status)}
|
||||
<section
|
||||
aria-labelledby="col-{col.status}"
|
||||
class="tone-{STATUS_TONE[col.status]} snap-start shrink-0 w-72 rounded-2xl bg-surface-2 p-3 transition-colors {dropTarget === col.status ? 'outline-2 outline-dashed outline-tone bg-tone-soft' : ''}"
|
||||
ondragover={(e) => {
|
||||
if (!e.dataTransfer?.types.includes('application/x-redaktion')) return;
|
||||
e.preventDefault();
|
||||
dropTarget = col.status;
|
||||
}}
|
||||
ondragleave={() => dropTarget === col.status && (dropTarget = null)}
|
||||
ondrop={(e) => drop(e, col.status)}
|
||||
>
|
||||
<header class="flex items-center gap-2 px-1 mb-3">
|
||||
<span class="size-2.5 rounded-full bg-tone" aria-hidden="true"></span>
|
||||
<h2 id="col-{col.status}" class="font-bold text-sm flex-1">{EDITORIAL_STATUS[col.status]}</h2>
|
||||
<span class="text-xs font-bold text-ink-3" aria-label="{col.items.length} Einträge">{col.items.length}</span>
|
||||
<button type="button" class="grid place-items-center size-7 rounded-full text-ink-3 hover:bg-surface hover:text-ink" aria-label="Neuer Eintrag mit Status {EDITORIAL_STATUS[col.status]}" onclick={() => oncreate('', col.status)}>
|
||||
<Plus class="size-4" />
|
||||
</button>
|
||||
</header>
|
||||
<ul class="space-y-2 min-h-16">
|
||||
{#each col.items as entry (entry.id)}
|
||||
<li>
|
||||
<EntryChip {entry} {team} {today} {onopen} />
|
||||
{#if entry.type === 'plan' && entry.date}
|
||||
<span class="sr-only">geplant für {formatShort(entry.date)}</span>
|
||||
{/if}
|
||||
</li>
|
||||
{:else}
|
||||
<li class="text-xs text-ink-3 px-1 py-4 text-center border-2 border-dashed border-line rounded-xl">Hierher ziehen</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</section>
|
||||
{/each}
|
||||
</div>
|
||||
97
src/lib/admin/calendar/EntryChip.svelte
Normal file
97
src/lib/admin/calendar/EntryChip.svelte
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
<script lang="ts">
|
||||
import Newspaper from '@lucide/svelte/icons/newspaper';
|
||||
import CalendarDays from '@lucide/svelte/icons/calendar-days';
|
||||
import DoorClosed from '@lucide/svelte/icons/door-closed';
|
||||
import MessageSquare from '@lucide/svelte/icons/message-square';
|
||||
import AlarmClock from '@lucide/svelte/icons/alarm-clock';
|
||||
import Link2 from '@lucide/svelte/icons/link-2';
|
||||
import { EDITORIAL_KINDS, EDITORIAL_STATUS, STATUS_TONE, type CalendarEntry, type TeamMember } from '$lib/editorial';
|
||||
import { formatShort } from '$lib/dates';
|
||||
|
||||
let {
|
||||
entry,
|
||||
team,
|
||||
today,
|
||||
onopen,
|
||||
compact = false
|
||||
}: { entry: CalendarEntry; team: TeamMember[]; today: string; onopen: (e: CalendarEntry) => void; compact?: boolean } = $props();
|
||||
|
||||
const assignee = $derived(entry.type === 'plan' ? team.find((m) => m.id === entry.assigneeId) : undefined);
|
||||
const overdue = $derived(entry.type === 'plan' && !!entry.dueDate && entry.dueDate < today && entry.status !== 'done');
|
||||
const draggable = $derived(entry.type === 'plan' || (entry.type === 'post' && !entry.live));
|
||||
|
||||
/** Vollständige Beschreibung für Screenreader */
|
||||
const label = $derived.by(() => {
|
||||
if (entry.type === 'plan')
|
||||
return [
|
||||
`Planung: ${entry.title}`,
|
||||
EDITORIAL_KINDS[entry.kind],
|
||||
`Status ${EDITORIAL_STATUS[entry.status]}`,
|
||||
assignee ? `zuständig ${assignee.name}` : 'niemand zuständig',
|
||||
entry.dueDate ? `Frist ${formatShort(entry.dueDate)}${overdue ? ', überfällig' : ''}` : '',
|
||||
entry.commentCount ? `${entry.commentCount} Kommentare` : ''
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(', ');
|
||||
if (entry.type === 'post')
|
||||
return `Meldung: ${entry.title}, ${entry.live ? 'veröffentlicht' : entry.published ? `geplant um ${entry.time} Uhr` : 'Entwurf'}`;
|
||||
return `${entry.closure ? 'Schließzeit' : 'Termin'}: ${entry.title}`;
|
||||
});
|
||||
|
||||
function dragstart(e: DragEvent) {
|
||||
e.dataTransfer?.setData('application/x-redaktion', JSON.stringify({ type: entry.type, id: entry.id }));
|
||||
if (e.dataTransfer) e.dataTransfer.effectAllowed = 'move';
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if entry.type === 'plan'}
|
||||
<button
|
||||
type="button"
|
||||
{draggable}
|
||||
ondragstart={dragstart}
|
||||
onclick={() => onopen(entry)}
|
||||
aria-label={label}
|
||||
class="tone-{STATUS_TONE[entry.status]} group w-full text-left rounded-lg bg-surface border border-line border-l-4 border-l-tone px-2 py-1.5 hover:border-brand/40 hover:shadow-card transition cursor-grab active:cursor-grabbing {entry.status === 'done' ? 'opacity-60' : ''}"
|
||||
>
|
||||
<span class="flex items-start gap-1.5">
|
||||
<span class="flex-1 min-w-0 text-[0.8rem] font-semibold leading-snug {compact ? 'line-clamp-2' : ''} {entry.status === 'done' ? 'line-through' : ''}">{entry.title}</span>
|
||||
{#if assignee}
|
||||
<span class="grid place-items-center size-5 rounded-full bg-brand text-on-brand text-[0.6rem] font-bold shrink-0" aria-hidden="true" title={assignee.name}>{assignee.initials}</span>
|
||||
{/if}
|
||||
</span>
|
||||
<span class="flex flex-wrap items-center gap-x-2 gap-y-0.5 mt-1 text-[0.7rem] text-ink-3" aria-hidden="true">
|
||||
<span class="font-semibold text-tone-ink">{EDITORIAL_STATUS[entry.status]}</span>
|
||||
{#if !compact}<span>{EDITORIAL_KINDS[entry.kind]}</span>{/if}
|
||||
{#if entry.dueDate}
|
||||
<span class="inline-flex items-center gap-0.5 {overdue ? 'text-danger font-bold' : ''}"><AlarmClock class="size-3" />{formatShort(entry.dueDate).slice(0, 6)}</span>
|
||||
{/if}
|
||||
{#if entry.commentCount}<span class="inline-flex items-center gap-0.5"><MessageSquare class="size-3" />{entry.commentCount}</span>{/if}
|
||||
{#if entry.postId || entry.pageId}<Link2 class="size-3" />{/if}
|
||||
</span>
|
||||
</button>
|
||||
{:else if entry.type === 'post'}
|
||||
<button
|
||||
type="button"
|
||||
{draggable}
|
||||
ondragstart={dragstart}
|
||||
onclick={() => onopen(entry)}
|
||||
aria-label={label}
|
||||
class="w-full text-left rounded-lg px-2 py-1.5 text-[0.8rem] leading-snug transition {entry.live ? 'bg-brand text-on-brand' : 'bg-brand-soft text-brand-ink border border-dashed border-brand/40'} {draggable ? 'cursor-grab active:cursor-grabbing' : ''}"
|
||||
>
|
||||
<span class="flex items-start gap-1.5">
|
||||
<Newspaper class="size-3.5 mt-0.5 shrink-0" />
|
||||
<span class="flex-1 min-w-0 font-semibold {compact ? 'line-clamp-2' : ''}">{entry.title}</span>
|
||||
</span>
|
||||
<span class="block text-[0.7rem] opacity-80 mt-0.5" aria-hidden="true">{entry.live ? 'Online' : entry.published ? `Geplant · ${entry.time}` : 'Entwurf'}</span>
|
||||
</button>
|
||||
{:else}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => onopen(entry)}
|
||||
aria-label={label}
|
||||
class="w-full text-left flex items-center gap-1.5 rounded-lg px-2 py-1 text-[0.75rem] {entry.closure ? 'bg-accent-soft text-accent-ink' : 'text-ink-2 hover:bg-surface-2'}"
|
||||
>
|
||||
{#if entry.closure}<DoorClosed class="size-3.5 shrink-0" />{:else}<CalendarDays class="size-3.5 shrink-0" />{/if}
|
||||
<span class="truncate">{entry.title}</span>
|
||||
</button>
|
||||
{/if}
|
||||
273
src/lib/admin/calendar/ItemDialog.svelte
Normal file
273
src/lib/admin/calendar/ItemDialog.svelte
Normal file
|
|
@ -0,0 +1,273 @@
|
|||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import { goto, invalidateAll } from '$app/navigation';
|
||||
import X from '@lucide/svelte/icons/x';
|
||||
import Save from '@lucide/svelte/icons/save';
|
||||
import Trash2 from '@lucide/svelte/icons/trash-2';
|
||||
import Newspaper from '@lucide/svelte/icons/newspaper';
|
||||
import ExternalLink from '@lucide/svelte/icons/external-link';
|
||||
import Send from '@lucide/svelte/icons/send';
|
||||
import MessageSquare from '@lucide/svelte/icons/message-square';
|
||||
import { callAction } from '../actions';
|
||||
import { toasts } from '../toast.svelte';
|
||||
import { EDITORIAL_KINDS, EDITORIAL_STATUS, STATUS_TONE, kindKeys, statusKeys, type CalendarEntry, type EditorialStatus, type TeamMember } from '$lib/editorial';
|
||||
|
||||
type Plan = Extract<CalendarEntry, { type: 'plan' }>;
|
||||
type Comment = { id: number; body: string; createdAt: string; userId: number | null; name: string };
|
||||
|
||||
let {
|
||||
item = $bindable(null),
|
||||
team,
|
||||
me,
|
||||
isAdmin,
|
||||
postOptions,
|
||||
pageOptions
|
||||
}: {
|
||||
item: Plan | null;
|
||||
team: TeamMember[];
|
||||
me: number;
|
||||
isAdmin: boolean;
|
||||
postOptions: { id: number; title: string }[];
|
||||
pageOptions: { id: number; title: string }[];
|
||||
} = $props();
|
||||
|
||||
let dialog: HTMLDialogElement;
|
||||
let status = $state<EditorialStatus>('idea');
|
||||
let kind = $state<string>('post');
|
||||
let comments = $state<Comment[]>([]);
|
||||
let commentText = $state('');
|
||||
let busy = $state(false);
|
||||
|
||||
const isNew = $derived(!item?.id);
|
||||
|
||||
$effect(() => {
|
||||
if (item && !dialog.open) {
|
||||
status = item.status;
|
||||
kind = item.kind;
|
||||
commentText = '';
|
||||
comments = [];
|
||||
dialog.showModal();
|
||||
if (item.id) loadComments(item.id);
|
||||
}
|
||||
if (!item && dialog.open) dialog.close();
|
||||
});
|
||||
|
||||
async function loadComments(id: number) {
|
||||
const res = await fetch(`/admin/redaktion/${id}/kommentare`);
|
||||
if (res.ok) comments = await res.json();
|
||||
}
|
||||
|
||||
async function addComment() {
|
||||
if (!item?.id || !commentText.trim()) return;
|
||||
const ok = await callAction('comment', { id: item.id, body: commentText });
|
||||
if (ok) {
|
||||
commentText = '';
|
||||
await loadComments(item.id);
|
||||
}
|
||||
}
|
||||
|
||||
async function removeComment(c: Comment) {
|
||||
if (!item?.id) return;
|
||||
if (await callAction('deleteComment', { commentId: c.id })) await loadComments(item.id);
|
||||
}
|
||||
|
||||
let confirmDelete = $state(false);
|
||||
async function remove() {
|
||||
if (!item?.id) return;
|
||||
if (!confirmDelete) {
|
||||
confirmDelete = true;
|
||||
return;
|
||||
}
|
||||
if (await callAction('delete', { id: item.id }, 'Gelöscht')) item = null;
|
||||
confirmDelete = false;
|
||||
}
|
||||
|
||||
async function createPost() {
|
||||
if (!item?.id) return;
|
||||
const res = await callAction('createPost', { id: item.id }, 'Entwurf angelegt');
|
||||
if (res?.postId) goto(`/admin/meldungen/${res.postId}`);
|
||||
}
|
||||
|
||||
const when = (iso: string) =>
|
||||
new Intl.DateTimeFormat('de-DE', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit', timeZone: 'Europe/Berlin' }).format(new Date(iso));
|
||||
</script>
|
||||
|
||||
<dialog
|
||||
bind:this={dialog}
|
||||
onclose={() => {
|
||||
item = null;
|
||||
confirmDelete = false;
|
||||
}}
|
||||
aria-labelledby="item-title"
|
||||
class="m-0 ml-auto h-dvh max-h-dvh w-full max-w-xl bg-surface text-ink p-0 shadow-float backdrop:bg-black/40"
|
||||
>
|
||||
{#if item}
|
||||
<div class="flex flex-col h-full">
|
||||
<header class="flex items-center gap-3 px-5 h-16 border-b border-line shrink-0">
|
||||
<h2 id="item-title" class="font-bold text-lg flex-1 truncate">{isNew ? 'Neue Planung' : 'Planung bearbeiten'}</h2>
|
||||
<button type="button" class="btn btn-ghost btn-icon" aria-label="Schließen" onclick={() => (item = null)}><X class="size-5" /></button>
|
||||
</header>
|
||||
|
||||
<div class="flex-1 overflow-y-auto">
|
||||
<form
|
||||
id="item-form"
|
||||
method="POST"
|
||||
action="?/save"
|
||||
class="p-5 space-y-5"
|
||||
use:enhance={() => {
|
||||
busy = true;
|
||||
return async ({ result }) => {
|
||||
busy = false;
|
||||
if (result.type === 'failure') toasts.show(String(result.data?.error ?? 'Bitte Eingaben prüfen.'), 'error');
|
||||
else if (result.type === 'success') {
|
||||
toasts.show('Gespeichert');
|
||||
await invalidateAll();
|
||||
item = null;
|
||||
}
|
||||
};
|
||||
}}
|
||||
>
|
||||
<input type="hidden" name="id" value={item.id || ''} />
|
||||
<div>
|
||||
<label class="label" for="it-title">Titel</label>
|
||||
<!-- svelte-ignore a11y_autofocus -->
|
||||
<input id="it-title" name="title" class="field font-semibold" required value={item.title} autofocus={isNew} placeholder="z. B. Bericht vom Sommerfest" />
|
||||
</div>
|
||||
|
||||
<fieldset>
|
||||
<legend class="label">Status</legend>
|
||||
<input type="hidden" name="status" value={status} />
|
||||
<div class="flex flex-wrap gap-1.5" role="radiogroup" aria-label="Status">
|
||||
{#each statusKeys as s (s)}
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={status === s}
|
||||
class="tone-{STATUS_TONE[s]} inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-sm font-bold border-2 transition {status === s ? 'border-tone bg-tone-soft text-tone-ink' : 'border-line text-ink-2 hover:border-ink-3'}"
|
||||
onclick={() => (status = s)}
|
||||
>
|
||||
<span class="size-2 rounded-full bg-tone" aria-hidden="true"></span>{EDITORIAL_STATUS[s]}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div class="grid sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="label" for="it-kind">Art</label>
|
||||
<select id="it-kind" name="kind" class="field" bind:value={kind}>
|
||||
{#each kindKeys as k (k)}<option value={k}>{EDITORIAL_KINDS[k]}</option>{/each}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label" for="it-assignee">Zuständig</label>
|
||||
<select id="it-assignee" name="assigneeId" class="field">
|
||||
<option value="">– niemand –</option>
|
||||
{#each team as m (m.id)}<option value={m.id} selected={m.id === item.assigneeId}>{m.name}{m.id === me ? ' (ich)' : ''}</option>{/each}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label" for="it-date">Erscheint am</label>
|
||||
<input id="it-date" name="date" type="date" class="field" value={item.date} />
|
||||
<p class="hint">Leer = Ideenspeicher</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label" for="it-due">Abgabe / Frist</label>
|
||||
<input id="it-due" name="dueDate" type="date" class="field" value={item.dueDate} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label" for="it-notes">Notizen & Briefing</label>
|
||||
<textarea id="it-notes" name="notes" rows="5" class="field" placeholder="Worum geht es? Wer ist beteiligt? Fotos vorhanden?">{item.notes}</textarea>
|
||||
</div>
|
||||
|
||||
{#if kind === 'post'}
|
||||
<div>
|
||||
<label class="label" for="it-post">Verknüpfte Meldung</label>
|
||||
<select id="it-post" name="postId" class="field">
|
||||
<option value="">– keine –</option>
|
||||
{#each postOptions as p (p.id)}<option value={p.id} selected={p.id === item.postId}>{p.title}</option>{/each}
|
||||
</select>
|
||||
</div>
|
||||
{:else}
|
||||
<input type="hidden" name="postId" value={item.postId ?? ''} />
|
||||
{/if}
|
||||
{#if kind === 'page'}
|
||||
<div>
|
||||
<label class="label" for="it-page">Verknüpfte Seite</label>
|
||||
<select id="it-page" name="pageId" class="field">
|
||||
<option value="">– keine –</option>
|
||||
{#each pageOptions as p (p.id)}<option value={p.id} selected={p.id === item.pageId}>{p.title}</option>{/each}
|
||||
</select>
|
||||
</div>
|
||||
{:else}
|
||||
<input type="hidden" name="pageId" value={item.pageId ?? ''} />
|
||||
{/if}
|
||||
|
||||
{#if !isNew && (item.postId || item.pageId || kind === 'post')}
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{#if item.postId}
|
||||
<a href="/admin/meldungen/{item.postId}" class="btn btn-soft btn-sm"><ExternalLink class="size-4" />Meldung bearbeiten</a>
|
||||
{:else if kind === 'post'}
|
||||
<button type="button" class="btn btn-soft btn-sm" onclick={createPost}><Newspaper class="size-4" />Meldung daraus erstellen</button>
|
||||
{/if}
|
||||
{#if item.pageId}
|
||||
<a href="/admin/seiten/{item.pageId}" class="btn btn-soft btn-sm"><ExternalLink class="size-4" />Seite bearbeiten</a>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</form>
|
||||
|
||||
{#if !isNew}
|
||||
<section aria-labelledby="kommentare" class="px-5 pb-6 pt-2 border-t border-line">
|
||||
<h3 id="kommentare" class="font-bold flex items-center gap-2 py-3"><MessageSquare class="size-4" />Kommentare</h3>
|
||||
{#if comments.length}
|
||||
<ol class="space-y-3 mb-4">
|
||||
{#each comments as c (c.id)}
|
||||
<li class="rounded-xl bg-surface-2 px-3.5 py-2.5">
|
||||
<div class="flex items-baseline gap-2 text-xs text-ink-3">
|
||||
<span class="font-bold text-ink">{c.name}</span>
|
||||
<time datetime={c.createdAt}>{when(c.createdAt)}</time>
|
||||
{#if c.userId === me || isAdmin}
|
||||
<button type="button" class="ml-auto hover:text-danger" onclick={() => removeComment(c)} aria-label="Kommentar von {c.name} löschen">Löschen</button>
|
||||
{/if}
|
||||
</div>
|
||||
<p class="text-sm mt-1 whitespace-pre-line">{c.body}</p>
|
||||
</li>
|
||||
{/each}
|
||||
</ol>
|
||||
{:else}
|
||||
<p class="text-sm text-ink-3 mb-3">Noch keine Kommentare.</p>
|
||||
{/if}
|
||||
<div class="flex gap-2 items-end">
|
||||
<label class="sr-only" for="it-comment">Kommentar schreiben</label>
|
||||
<textarea
|
||||
id="it-comment"
|
||||
bind:value={commentText}
|
||||
rows="2"
|
||||
class="field text-sm"
|
||||
placeholder="Kommentar für das Team …"
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) addComment();
|
||||
}}
|
||||
></textarea>
|
||||
<button type="button" class="btn btn-soft btn-icon shrink-0" aria-label="Kommentar senden" disabled={!commentText.trim()} onclick={addComment}><Send class="size-4" /></button>
|
||||
</div>
|
||||
<p class="hint">Senden mit Strg + Enter</p>
|
||||
</section>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<footer class="flex items-center gap-2 px-5 py-3 border-t border-line shrink-0 bg-surface">
|
||||
<button form="item-form" class="btn btn-primary" disabled={busy}><Save class="size-4" />Speichern</button>
|
||||
<button type="button" class="btn btn-ghost" onclick={() => (item = null)}>Abbrechen</button>
|
||||
{#if !isNew}
|
||||
<button type="button" class="btn btn-danger ml-auto" onclick={remove} aria-live="polite">
|
||||
<Trash2 class="size-4" />{confirmDelete ? 'Wirklich löschen?' : 'Löschen'}
|
||||
</button>
|
||||
{/if}
|
||||
</footer>
|
||||
</div>
|
||||
{/if}
|
||||
</dialog>
|
||||
52
src/lib/admin/calendar/ListView.svelte
Normal file
52
src/lib/admin/calendar/ListView.svelte
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<script lang="ts">
|
||||
import { EDITORIAL_KINDS, EDITORIAL_STATUS, STATUS_TONE, type CalendarEntry, type TeamMember } from '$lib/editorial';
|
||||
import { formatShort } from '$lib/dates';
|
||||
import AlarmClock from '@lucide/svelte/icons/alarm-clock';
|
||||
|
||||
let { plans, team, today, onopen }: { plans: CalendarEntry[]; team: TeamMember[]; today: string; onopen: (e: CalendarEntry) => void } = $props();
|
||||
|
||||
const rows = $derived(plans.filter((p): p is Extract<CalendarEntry, { type: 'plan' }> => p.type === 'plan'));
|
||||
const name = (id: number | null) => team.find((m) => m.id === id)?.name ?? '–';
|
||||
</script>
|
||||
|
||||
<div class="card overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<caption class="sr-only">Alle Planungen</caption>
|
||||
<thead class="bg-surface-2 text-left">
|
||||
<tr>
|
||||
<th scope="col" class="px-4 py-2.5 font-bold">Titel</th>
|
||||
<th scope="col" class="px-3 py-2.5 font-bold">Status</th>
|
||||
<th scope="col" class="px-3 py-2.5 font-bold hidden md:table-cell">Art</th>
|
||||
<th scope="col" class="px-3 py-2.5 font-bold hidden sm:table-cell">Zuständig</th>
|
||||
<th scope="col" class="px-3 py-2.5 font-bold">Erscheint</th>
|
||||
<th scope="col" class="px-3 py-2.5 font-bold hidden sm:table-cell">Frist</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-line">
|
||||
{#each rows as r (r.id)}
|
||||
{@const overdue = !!r.dueDate && r.dueDate < today && r.status !== 'done'}
|
||||
<tr class="hover:bg-surface-2/60">
|
||||
<td class="px-4 py-2.5">
|
||||
<button type="button" class="font-semibold text-left hover:underline underline-offset-2" onclick={() => onopen(r)}>{r.title}</button>
|
||||
</td>
|
||||
<td class="px-3 py-2.5">
|
||||
<span class="tone-{STATUS_TONE[r.status]} inline-flex items-center gap-1.5 rounded-full bg-tone-soft text-tone-ink px-2.5 py-0.5 text-xs font-bold whitespace-nowrap">
|
||||
<span class="size-1.5 rounded-full bg-tone" aria-hidden="true"></span>{EDITORIAL_STATUS[r.status]}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-3 py-2.5 hidden md:table-cell text-ink-2">{EDITORIAL_KINDS[r.kind]}</td>
|
||||
<td class="px-3 py-2.5 hidden sm:table-cell text-ink-2">{name(r.assigneeId)}</td>
|
||||
<td class="px-3 py-2.5 tabular-nums whitespace-nowrap">{r.date ? formatShort(r.date) : 'Ideenspeicher'}</td>
|
||||
<td class="px-3 py-2.5 hidden sm:table-cell tabular-nums whitespace-nowrap {overdue ? 'text-danger font-bold' : 'text-ink-2'}">
|
||||
{#if r.dueDate}
|
||||
{#if overdue}<AlarmClock class="size-3.5 inline -mt-0.5" /> <span class="sr-only">überfällig:</span>{/if}
|
||||
{formatShort(r.dueDate)}
|
||||
{:else}–{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{:else}
|
||||
<tr><td colspan="6" class="px-4 py-8 text-center text-ink-3">Keine Planungen für diese Auswahl.</td></tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
169
src/lib/admin/calendar/MonthView.svelte
Normal file
169
src/lib/admin/calendar/MonthView.svelte
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
<script lang="ts">
|
||||
import Plus from '@lucide/svelte/icons/plus';
|
||||
import Lightbulb from '@lucide/svelte/icons/lightbulb';
|
||||
import EntryChip from './EntryChip.svelte';
|
||||
import { callAction } from '../actions';
|
||||
import { formatLong, formatMonthYear, dayOfMonth } from '$lib/dates';
|
||||
import type { CalendarEntry, TeamMember } from '$lib/editorial';
|
||||
|
||||
let {
|
||||
days,
|
||||
month,
|
||||
entries,
|
||||
ideas,
|
||||
team,
|
||||
today,
|
||||
onopen,
|
||||
oncreate
|
||||
}: {
|
||||
days: string[];
|
||||
month: string;
|
||||
entries: CalendarEntry[];
|
||||
ideas: CalendarEntry[];
|
||||
team: TeamMember[];
|
||||
today: string;
|
||||
onopen: (e: CalendarEntry) => void;
|
||||
oncreate: (date: string) => void;
|
||||
} = $props();
|
||||
|
||||
const WEEKDAYS = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'];
|
||||
|
||||
/** Einträge je Tag */
|
||||
const byDay = $derived.by(() => {
|
||||
const map = new Map<string, CalendarEntry[]>(days.map((d) => [d, []]));
|
||||
const order = { event: 0, post: 1, plan: 2 } as const;
|
||||
for (const e of entries) {
|
||||
if (e.type === 'event' && e.endDate && e.endDate > e.date) {
|
||||
// Schließzeiten an jedem Tag, andere mehrtägige Termine am ersten Tag und jeden Montag
|
||||
days.forEach((d, i) => {
|
||||
if (d < e.date || d > e.endDate) return;
|
||||
if (e.closure || d === e.date || i % 7 === 0) map.get(d)!.push(e);
|
||||
});
|
||||
} else map.get(e.date)?.push(e);
|
||||
}
|
||||
for (const list of map.values()) list.sort((a, b) => order[a.type] - order[b.type]);
|
||||
return map;
|
||||
});
|
||||
|
||||
const weeks = $derived(Array.from({ length: days.length / 7 }, (_, i) => days.slice(i * 7, i * 7 + 7)));
|
||||
|
||||
let dropTarget = $state<string | null>(null);
|
||||
|
||||
function allowDrop(e: DragEvent, key: string) {
|
||||
if (!e.dataTransfer?.types.includes('application/x-redaktion')) return;
|
||||
e.preventDefault();
|
||||
dropTarget = key;
|
||||
}
|
||||
|
||||
async function drop(e: DragEvent, date: string) {
|
||||
e.preventDefault();
|
||||
dropTarget = null;
|
||||
const raw = e.dataTransfer?.getData('application/x-redaktion');
|
||||
if (!raw) return;
|
||||
const { type, id } = JSON.parse(raw);
|
||||
if (type === 'post' && !date) return;
|
||||
await callAction('move', { type, id, date }, date ? `Auf ${formatLong(date)} verschoben` : 'In den Ideenspeicher gelegt');
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="grid 2xl:grid-cols-[1fr_17rem] gap-6 items-start">
|
||||
<!-- Monatsraster (ab Tablet) -->
|
||||
<div class="hidden md:block card overflow-hidden">
|
||||
<table class="w-full table-fixed border-collapse">
|
||||
<caption class="sr-only">Redaktionskalender {formatMonthYear(`${month}-01`)}</caption>
|
||||
<thead>
|
||||
<tr class="bg-surface-2">
|
||||
{#each WEEKDAYS as w (w)}
|
||||
<th scope="col" class="py-2 text-xs font-bold uppercase tracking-[0.12em] text-ink-2">
|
||||
<abbr title={w} class="no-underline">{w.slice(0, 2)}</abbr>
|
||||
</th>
|
||||
{/each}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each weeks as week, wi (wi)}
|
||||
<tr>
|
||||
{#each week as day, di (day)}
|
||||
{@const inMonth = day.startsWith(month)}
|
||||
{@const isToday = day === today}
|
||||
{@const list = byDay.get(day) ?? []}
|
||||
<td
|
||||
class="group align-top border-t border-l first:border-l-0 border-line h-36 p-1.5 transition-colors {inMonth ? '' : 'bg-surface-2/50'} {dropTarget === day ? '!bg-brand-soft outline-2 outline-dashed outline-brand -outline-offset-4' : ''} {di >= 5 && inMonth ? 'bg-surface-2/30' : ''}"
|
||||
ondragover={(e) => allowDrop(e, day)}
|
||||
ondragleave={() => dropTarget === day && (dropTarget = null)}
|
||||
ondrop={(e) => drop(e, day)}
|
||||
>
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<span
|
||||
class="grid place-items-center size-7 rounded-full text-sm font-bold {isToday ? 'bg-accent text-white' : inMonth ? 'text-ink' : 'text-ink-3'}"
|
||||
aria-current={isToday ? 'date' : undefined}
|
||||
>
|
||||
{dayOfMonth(day)}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="grid place-items-center size-7 rounded-full text-ink-3 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:bg-brand hover:text-on-brand transition"
|
||||
aria-label="Neue Planung am {formatLong(day)}"
|
||||
onclick={() => oncreate(day)}
|
||||
>
|
||||
<Plus class="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
{#if list.length}
|
||||
<ul class="space-y-1" aria-label="Einträge am {formatLong(day)}">
|
||||
{#each list as entry (`${entry.type}-${entry.id}`)}
|
||||
<li><EntryChip {entry} {team} {today} {onopen} compact /></li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
</td>
|
||||
{/each}
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Handy: Tagesliste des Monats -->
|
||||
<ol class="md:hidden space-y-4" aria-label="Einträge {formatMonthYear(`${month}-01`)}">
|
||||
{#each days.filter((d) => d.startsWith(month) && ((byDay.get(d)?.length ?? 0) > 0 || d === today)) as day (day)}
|
||||
<li>
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<h3 class="text-sm font-bold {day === today ? 'text-accent-ink' : 'text-ink-2'}">{formatLong(day)}{day === today ? ' · heute' : ''}</h3>
|
||||
<button type="button" class="btn btn-ghost btn-sm btn-icon" aria-label="Neue Planung am {formatLong(day)}" onclick={() => oncreate(day)}><Plus class="size-4" /></button>
|
||||
</div>
|
||||
<ul class="space-y-1.5">
|
||||
{#each byDay.get(day) ?? [] as entry (`${entry.type}-${entry.id}`)}
|
||||
<li><EntryChip {entry} {team} {today} {onopen} /></li>
|
||||
{/each}
|
||||
</ul>
|
||||
</li>
|
||||
{:else}
|
||||
<li class="text-ink-3">In diesem Monat ist noch nichts geplant.</li>
|
||||
{/each}
|
||||
</ol>
|
||||
|
||||
<!-- Ideenspeicher: Planungen ohne Datum -->
|
||||
<section
|
||||
aria-labelledby="ideen"
|
||||
class="card p-4 2xl:sticky 2xl:top-6 transition-colors {dropTarget === 'ideen' ? '!bg-brand-soft outline-2 outline-dashed outline-brand' : ''}"
|
||||
ondragover={(e) => allowDrop(e, 'ideen')}
|
||||
ondragleave={() => dropTarget === 'ideen' && (dropTarget = null)}
|
||||
ondrop={(e) => drop(e, '')}
|
||||
>
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<h2 id="ideen" class="font-bold flex items-center gap-2"><Lightbulb class="size-4 text-accent" />Ideenspeicher</h2>
|
||||
<button type="button" class="btn btn-ghost btn-sm btn-icon" aria-label="Neue Idee ohne Datum" onclick={() => oncreate('')}><Plus class="size-4" /></button>
|
||||
</div>
|
||||
<p class="text-xs text-ink-3 mb-3">Noch ohne Datum. Zum Planen auf einen Tag ziehen oder öffnen und ein Datum wählen.</p>
|
||||
{#if ideas.length}
|
||||
<ul class="space-y-1.5">
|
||||
{#each ideas as entry (entry.id)}
|
||||
<li><EntryChip {entry} {team} {today} {onopen} /></li>
|
||||
{/each}
|
||||
</ul>
|
||||
{:else}
|
||||
<p class="text-sm text-ink-3">Keine offenen Ideen.</p>
|
||||
{/if}
|
||||
</section>
|
||||
</div>
|
||||
67
src/lib/editorial.ts
Normal file
67
src/lib/editorial.ts
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/** Bezeichnungen für den Redaktionskalender (Server und Browser). */
|
||||
|
||||
export const EDITORIAL_KINDS = {
|
||||
post: 'Meldung',
|
||||
page: 'Seite',
|
||||
event: 'Termin',
|
||||
social: 'Social Media',
|
||||
print: 'Aushang / Druck',
|
||||
other: 'Sonstiges'
|
||||
} as const;
|
||||
|
||||
/** Reihenfolge = Arbeitsablauf (Spalten im Board) */
|
||||
export const EDITORIAL_STATUS = {
|
||||
idea: 'Idee',
|
||||
progress: 'In Arbeit',
|
||||
review: 'Zur Freigabe',
|
||||
ready: 'Geplant',
|
||||
done: 'Erledigt'
|
||||
} as const;
|
||||
|
||||
export type EditorialKind = keyof typeof EDITORIAL_KINDS;
|
||||
export type EditorialStatus = keyof typeof EDITORIAL_STATUS;
|
||||
|
||||
export const kindKeys = Object.keys(EDITORIAL_KINDS) as EditorialKind[];
|
||||
export const statusKeys = Object.keys(EDITORIAL_STATUS) as EditorialStatus[];
|
||||
|
||||
export const isKind = (v: string): v is EditorialKind => v in EDITORIAL_KINDS;
|
||||
export const isStatus = (v: string): v is EditorialStatus => v in EDITORIAL_STATUS;
|
||||
|
||||
/** Farbe je Status – nicht nur Farbe, sondern immer mit Text/Symbol kombiniert (Barrierefreiheit) */
|
||||
export const STATUS_TONE: Record<EditorialStatus, string> = {
|
||||
idea: 'slate',
|
||||
progress: 'sky',
|
||||
review: 'amber',
|
||||
ready: 'violet',
|
||||
done: 'emerald'
|
||||
};
|
||||
|
||||
/** Ein Eintrag im Kalender – Planung, Meldung oder Termin */
|
||||
export type CalendarEntry =
|
||||
| {
|
||||
type: 'plan';
|
||||
id: number;
|
||||
title: string;
|
||||
notes: string;
|
||||
kind: EditorialKind;
|
||||
status: EditorialStatus;
|
||||
date: string;
|
||||
dueDate: string;
|
||||
assigneeId: number | null;
|
||||
postId: number | null;
|
||||
pageId: number | null;
|
||||
commentCount: number;
|
||||
}
|
||||
| { type: 'post'; id: number; title: string; date: string; time: string; published: boolean; live: boolean }
|
||||
| { type: 'event'; id: number; title: string; date: string; endDate: string; closure: boolean };
|
||||
|
||||
export type TeamMember = { id: number; name: string; initials: string };
|
||||
|
||||
export const initials = (name: string) =>
|
||||
name
|
||||
.split(/\s+/)
|
||||
.filter(Boolean)
|
||||
.map((w) => w[0])
|
||||
.slice(0, 2)
|
||||
.join('')
|
||||
.toUpperCase();
|
||||
|
|
@ -176,6 +176,50 @@ export const messages = sqliteTable('messages', {
|
|||
...timestamps
|
||||
});
|
||||
|
||||
// ─── Redaktionskalender ────────────────────────────────────────────────────────
|
||||
|
||||
/** Geplante Beiträge und Aufgaben des Redaktionsteams */
|
||||
export const editorialItems = sqliteTable(
|
||||
'editorial_items',
|
||||
{
|
||||
id: integer('id').primaryKey({ autoIncrement: true }),
|
||||
title: text('title').notNull(),
|
||||
notes: text('notes').notNull().default(''),
|
||||
kind: text('kind', { enum: ['post', 'page', 'event', 'social', 'print', 'other'] })
|
||||
.notNull()
|
||||
.default('post'),
|
||||
status: text('status', { enum: ['idea', 'progress', 'review', 'ready', 'done'] })
|
||||
.notNull()
|
||||
.default('idea'),
|
||||
assigneeId: integer('assignee_id').references(() => users.id, { onDelete: 'set null' }),
|
||||
/** Geplanter Erscheinungstag YYYY-MM-DD, leer = Ideenspeicher */
|
||||
date: text('date').notNull().default(''),
|
||||
/** Abgabe / Frist YYYY-MM-DD, leer = keine */
|
||||
dueDate: text('due_date').notNull().default(''),
|
||||
postId: integer('post_id').references(() => posts.id, { onDelete: 'set null' }),
|
||||
pageId: integer('page_id').references(() => pages.id, { onDelete: 'set null' }),
|
||||
createdBy: integer('created_by').references(() => users.id, { onDelete: 'set null' }),
|
||||
...timestamps
|
||||
},
|
||||
(t) => [index('editorial_date_idx').on(t.date), index('editorial_assignee_idx').on(t.assigneeId)]
|
||||
);
|
||||
|
||||
export const editorialComments = sqliteTable(
|
||||
'editorial_comments',
|
||||
{
|
||||
id: integer('id').primaryKey({ autoIncrement: true }),
|
||||
itemId: integer('item_id')
|
||||
.notNull()
|
||||
.references(() => editorialItems.id, { onDelete: 'cascade' }),
|
||||
userId: integer('user_id').references(() => users.id, { onDelete: 'set null' }),
|
||||
body: text('body').notNull(),
|
||||
createdAt: integer('created_at', { mode: 'timestamp' })
|
||||
.notNull()
|
||||
.default(sql`(unixepoch())`)
|
||||
},
|
||||
(t) => [index('editorial_comments_item_idx').on(t.itemId)]
|
||||
);
|
||||
|
||||
export type User = typeof users.$inferSelect;
|
||||
export type Media = typeof media.$inferSelect;
|
||||
export type Contact = typeof contacts.$inferSelect;
|
||||
|
|
@ -184,3 +228,5 @@ export type Post = typeof posts.$inferSelect;
|
|||
export type Event = typeof events.$inferSelect;
|
||||
export type Tile = typeof tiles.$inferSelect;
|
||||
export type Message = typeof messages.$inferSelect;
|
||||
export type EditorialItem = typeof editorialItems.$inferSelect;
|
||||
export type EditorialComment = typeof editorialComments.$inferSelect;
|
||||
|
|
|
|||
186
src/lib/server/editorial.ts
Normal file
186
src/lib/server/editorial.ts
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
import { and, asc, eq, gte, inArray, lte, ne, sql, type SQL } from 'drizzle-orm';
|
||||
import { db } from './db';
|
||||
import { editorialComments, editorialItems, events, posts, users } from './db/schema';
|
||||
import { addDays, TZ, today } from '$lib/dates';
|
||||
import { initials, type CalendarEntry, type EditorialKind, type TeamMember } from '$lib/editorial';
|
||||
|
||||
/** Datum (YYYY-MM-DD) eines Zeitpunkts in deutscher Zeit */
|
||||
const berlinDate = (d: Date) => new Intl.DateTimeFormat('sv-SE', { timeZone: TZ }).format(d);
|
||||
const berlinTime = (d: Date) =>
|
||||
new Intl.DateTimeFormat('de-DE', { timeZone: TZ, hour: '2-digit', minute: '2-digit' }).format(d);
|
||||
|
||||
export function team(): TeamMember[] {
|
||||
return db
|
||||
.select({ id: users.id, name: users.name })
|
||||
.from(users)
|
||||
.orderBy(asc(users.name))
|
||||
.all()
|
||||
.map((u) => ({ ...u, initials: initials(u.name) }));
|
||||
}
|
||||
|
||||
/** Kalenderraster für einen Monat: von Montag vor dem 1. bis Sonntag nach dem Letzten. */
|
||||
export function monthGrid(month: string) {
|
||||
const first = `${month}-01`;
|
||||
const d = new Date(`${first}T12:00:00Z`);
|
||||
const weekday = (d.getUTCDay() + 6) % 7; // Montag = 0
|
||||
const start = addDays(first, -weekday);
|
||||
const next = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 1, 12));
|
||||
const last = addDays(next.toISOString().slice(0, 10), -1);
|
||||
const lastWeekday = (new Date(`${last}T12:00:00Z`).getUTCDay() + 6) % 7;
|
||||
const end = addDays(last, 6 - lastWeekday);
|
||||
const days: string[] = [];
|
||||
for (let x = start; x <= end; x = addDays(x, 1)) days.push(x);
|
||||
return { first, last, start, end, days };
|
||||
}
|
||||
|
||||
export type Filters = { person: number | null; kind: EditorialKind | null; hideDone: boolean };
|
||||
|
||||
function planConditions(f: Filters): SQL[] {
|
||||
const c: SQL[] = [];
|
||||
if (f.person) c.push(eq(editorialItems.assigneeId, f.person));
|
||||
if (f.kind) c.push(eq(editorialItems.kind, f.kind));
|
||||
if (f.hideDone) c.push(ne(editorialItems.status, 'done'));
|
||||
return c;
|
||||
}
|
||||
|
||||
function commentCounts(ids: number[]) {
|
||||
if (!ids.length) return new Map<number, number>();
|
||||
return new Map(
|
||||
db
|
||||
.select({ id: editorialComments.itemId, n: sql<number>`count(*)` })
|
||||
.from(editorialComments)
|
||||
.where(inArray(editorialComments.itemId, ids))
|
||||
.groupBy(editorialComments.itemId)
|
||||
.all()
|
||||
.map((r) => [r.id, r.n])
|
||||
);
|
||||
}
|
||||
|
||||
function toPlanEntries(rows: (typeof editorialItems.$inferSelect)[]): CalendarEntry[] {
|
||||
const counts = commentCounts(rows.map((r) => r.id));
|
||||
return rows.map((r) => ({
|
||||
type: 'plan',
|
||||
id: r.id,
|
||||
title: r.title,
|
||||
notes: r.notes,
|
||||
kind: r.kind,
|
||||
status: r.status,
|
||||
date: r.date,
|
||||
dueDate: r.dueDate,
|
||||
assigneeId: r.assigneeId,
|
||||
postId: r.postId,
|
||||
pageId: r.pageId,
|
||||
commentCount: counts.get(r.id) ?? 0
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle Einträge zwischen from und to: Planungen, Meldungen (nach Erscheinungsdatum)
|
||||
* und – als Orientierung – Termine & Schließzeiten.
|
||||
*/
|
||||
export function entriesBetween(from: string, to: string, f: Filters, opts = { posts: true, events: true }): CalendarEntry[] {
|
||||
const out: CalendarEntry[] = toPlanEntries(
|
||||
db
|
||||
.select()
|
||||
.from(editorialItems)
|
||||
.where(and(gte(editorialItems.date, from), lte(editorialItems.date, to), ...planConditions(f)))
|
||||
.orderBy(asc(editorialItems.date), asc(editorialItems.id))
|
||||
.all()
|
||||
);
|
||||
|
||||
// Meldungen zeigen nur, wenn nicht nach Person gefiltert wird oder die Art „Meldung“ passt
|
||||
if (opts.posts && !f.person && (!f.kind || f.kind === 'post')) {
|
||||
const now = Date.now();
|
||||
const rows = db
|
||||
.select({ id: posts.id, title: posts.title, publishedAt: posts.publishedAt, published: posts.published })
|
||||
.from(posts)
|
||||
// großzügiges Fenster, genau wird unten nach deutscher Zeit gefiltert
|
||||
.where(and(gte(posts.publishedAt, new Date(`${addDays(from, -1)}T00:00:00Z`)), lte(posts.publishedAt, new Date(`${addDays(to, 1)}T23:59:59Z`))))
|
||||
.all();
|
||||
for (const p of rows) {
|
||||
const date = berlinDate(p.publishedAt);
|
||||
if (date < from || date > to) continue;
|
||||
out.push({
|
||||
type: 'post',
|
||||
id: p.id,
|
||||
title: p.title,
|
||||
date,
|
||||
time: berlinTime(p.publishedAt),
|
||||
published: p.published,
|
||||
live: p.published && p.publishedAt.getTime() <= now
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.events && !f.person && !f.kind) {
|
||||
const endOrStart = sql<string>`coalesce(nullif(${events.endDate}, ''), ${events.startDate})`;
|
||||
const rows = db
|
||||
.select()
|
||||
.from(events)
|
||||
.where(and(lte(events.startDate, to), gte(endOrStart, from)))
|
||||
.orderBy(asc(events.startDate))
|
||||
.all();
|
||||
for (const e of rows) {
|
||||
out.push({ type: 'event', id: e.id, title: e.title, date: e.startDate, endDate: e.endDate, closure: e.kind === 'closure' });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Ideenspeicher: Planungen ohne Datum */
|
||||
export function unscheduled(f: Filters): CalendarEntry[] {
|
||||
return toPlanEntries(
|
||||
db
|
||||
.select()
|
||||
.from(editorialItems)
|
||||
.where(and(eq(editorialItems.date, ''), ...planConditions(f)))
|
||||
.orderBy(asc(editorialItems.id))
|
||||
.all()
|
||||
);
|
||||
}
|
||||
|
||||
/** Alle Planungen (für Board und Liste), optional gefiltert */
|
||||
export function allPlans(f: Filters): CalendarEntry[] {
|
||||
return toPlanEntries(
|
||||
db
|
||||
.select()
|
||||
.from(editorialItems)
|
||||
.where(and(...planConditions(f)))
|
||||
.orderBy(sql`${editorialItems.date} = ''`, asc(editorialItems.date), asc(editorialItems.id))
|
||||
.all()
|
||||
);
|
||||
}
|
||||
|
||||
/** Offene Aufgaben einer Person – überfällige zuerst */
|
||||
export function myTasks(userId: number, limit = 6) {
|
||||
const rows = db
|
||||
.select()
|
||||
.from(editorialItems)
|
||||
.where(and(eq(editorialItems.assigneeId, userId), ne(editorialItems.status, 'done')))
|
||||
.all();
|
||||
const t = today();
|
||||
const key = (r: (typeof rows)[number]) => r.dueDate || r.date || '9999';
|
||||
return rows
|
||||
.sort((a, b) => key(a).localeCompare(key(b)))
|
||||
.slice(0, limit)
|
||||
.map((r) => ({
|
||||
id: r.id,
|
||||
title: r.title,
|
||||
status: r.status,
|
||||
kind: r.kind,
|
||||
date: r.date,
|
||||
dueDate: r.dueDate,
|
||||
overdue: !!r.dueDate && r.dueDate < t
|
||||
}));
|
||||
}
|
||||
|
||||
export function commentsFor(itemId: number) {
|
||||
return db
|
||||
.select({ id: editorialComments.id, body: editorialComments.body, createdAt: editorialComments.createdAt, userId: editorialComments.userId, name: users.name })
|
||||
.from(editorialComments)
|
||||
.leftJoin(users, eq(editorialComments.userId, users.id))
|
||||
.where(eq(editorialComments.itemId, itemId))
|
||||
.orderBy(asc(editorialComments.id))
|
||||
.all()
|
||||
.map((c) => ({ ...c, name: c.name ?? 'Ehemaliges Mitglied', createdAt: c.createdAt.toISOString() }));
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import LayoutDashboard from '@lucide/svelte/icons/layout-dashboard';
|
||||
import CalendarRange from '@lucide/svelte/icons/calendar-range';
|
||||
import Newspaper from '@lucide/svelte/icons/newspaper';
|
||||
import FolderTree from '@lucide/svelte/icons/folder-tree';
|
||||
import CalendarDays from '@lucide/svelte/icons/calendar-days';
|
||||
|
|
@ -24,7 +25,10 @@
|
|||
const sections = $derived([
|
||||
{
|
||||
title: '',
|
||||
items: [{ href: '/admin', label: 'Übersicht', icon: LayoutDashboard }]
|
||||
items: [
|
||||
{ href: '/admin', label: 'Übersicht', icon: LayoutDashboard },
|
||||
{ href: '/admin/redaktion', label: 'Redaktionskalender', icon: CalendarRange }
|
||||
]
|
||||
},
|
||||
{
|
||||
title: 'Inhalte',
|
||||
|
|
|
|||
|
|
@ -2,11 +2,13 @@ import { desc, eq, sql } from 'drizzle-orm';
|
|||
import { db } from '$lib/server/db';
|
||||
import { events, messages, pages, posts, media } from '$lib/server/db/schema';
|
||||
import { upcomingEvents } from '$lib/server/content';
|
||||
import { myTasks } from '$lib/server/editorial';
|
||||
|
||||
const count = (table: typeof posts | typeof pages | typeof events | typeof media) =>
|
||||
db.select({ n: sql<number>`count(*)` }).from(table).get()?.n ?? 0;
|
||||
|
||||
export const load = () => ({
|
||||
export const load = ({ locals }) => ({
|
||||
tasks: myTasks(locals.user!.id),
|
||||
stats: {
|
||||
posts: count(posts),
|
||||
pages: count(pages),
|
||||
|
|
|
|||
|
|
@ -7,7 +7,10 @@
|
|||
import ArrowRight from '@lucide/svelte/icons/arrow-right';
|
||||
import Inbox from '@lucide/svelte/icons/inbox';
|
||||
import PageHeader from '$lib/admin/PageHeader.svelte';
|
||||
import CalendarRange from '@lucide/svelte/icons/calendar-range';
|
||||
import AlarmClock from '@lucide/svelte/icons/alarm-clock';
|
||||
import { formatShort, relative, eventWhen } from '$lib/dates';
|
||||
import { EDITORIAL_STATUS, STATUS_TONE } from '$lib/editorial';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
|
|
@ -47,6 +50,34 @@
|
|||
</a>
|
||||
{/if}
|
||||
|
||||
<section class="card p-5 mb-6" aria-labelledby="aufgaben">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<h2 id="aufgaben" class="text-lg font-bold flex items-center gap-2"><CalendarRange class="size-5 text-accent" />Meine Aufgaben</h2>
|
||||
<a href="/admin/redaktion?person=ich&ansicht=liste" class="text-sm font-semibold text-brand-ink">Redaktionskalender</a>
|
||||
</div>
|
||||
{#if data.tasks.length}
|
||||
<ul class="divide-y divide-line">
|
||||
{#each data.tasks as t (t.id)}
|
||||
<li class="flex flex-wrap items-center gap-x-3 gap-y-1 py-2.5">
|
||||
<span class="tone-{STATUS_TONE[t.status]} inline-flex items-center gap-1.5 rounded-full bg-tone-soft text-tone-ink px-2.5 py-0.5 text-xs font-bold">
|
||||
<span class="size-1.5 rounded-full bg-tone" aria-hidden="true"></span>{EDITORIAL_STATUS[t.status]}
|
||||
</span>
|
||||
<a href="/admin/redaktion?monat={(t.date || t.dueDate || '').slice(0, 7)}" class="flex-1 min-w-0 font-semibold truncate hover:text-brand-ink">{t.title}</a>
|
||||
{#if t.dueDate}
|
||||
<span class="text-sm tabular-nums inline-flex items-center gap-1 {t.overdue ? 'text-danger font-bold' : 'text-ink-3'}">
|
||||
<AlarmClock class="size-3.5" />{t.overdue ? 'überfällig seit' : 'bis'} {formatShort(t.dueDate)}
|
||||
</span>
|
||||
{:else if t.date}
|
||||
<span class="text-sm text-ink-3 tabular-nums">erscheint {formatShort(t.date)}</span>
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{:else}
|
||||
<p class="text-ink-3">Dir ist gerade nichts zugewiesen. <a href="/admin/redaktion" class="font-semibold text-brand-ink underline underline-offset-2">Zum Kalender</a></p>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<div class="grid lg:grid-cols-2 gap-6">
|
||||
<section class="card p-5">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
|
|
|
|||
186
src/routes/admin/(panel)/redaktion/+page.server.ts
Normal file
186
src/routes/admin/(panel)/redaktion/+page.server.ts
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
import { error, fail } from '@sveltejs/kit';
|
||||
import { asc, eq } from 'drizzle-orm';
|
||||
import { db } from '$lib/server/db';
|
||||
import { editorialComments, editorialItems, pages, posts } from '$lib/server/db/schema';
|
||||
import { allPlans, entriesBetween, monthGrid, team, unscheduled, type Filters } from '$lib/server/editorial';
|
||||
import { fields, uniqueSlug } from '$lib/server/forms';
|
||||
import { fromLocalInput, toLocalInput, today } from '$lib/dates';
|
||||
import { isKind, isStatus } from '$lib/editorial';
|
||||
|
||||
|
||||
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
||||
const VIEWS = ['monat', 'board', 'liste'] as const;
|
||||
type View = (typeof VIEWS)[number];
|
||||
|
||||
export const load = ({ url, locals }) => {
|
||||
const view: View = (VIEWS as readonly string[]).includes(url.searchParams.get('ansicht') ?? '')
|
||||
? (url.searchParams.get('ansicht') as View)
|
||||
: 'monat';
|
||||
const monthParam = url.searchParams.get('monat') ?? '';
|
||||
const month = /^\d{4}-\d{2}$/.test(monthParam) ? monthParam : today().slice(0, 7);
|
||||
|
||||
const personParam = url.searchParams.get('person') ?? '';
|
||||
const person = personParam === 'ich' ? locals.user!.id : Number(personParam) || null;
|
||||
const kindParam = url.searchParams.get('art') ?? '';
|
||||
const filters: Filters = {
|
||||
person,
|
||||
kind: isKind(kindParam) ? kindParam : null,
|
||||
hideDone: url.searchParams.get('erledigt') !== 'zeigen'
|
||||
};
|
||||
|
||||
const grid = monthGrid(month);
|
||||
return {
|
||||
view,
|
||||
month,
|
||||
grid,
|
||||
today: today(),
|
||||
filters: { person: personParam, kind: kindParam, showDone: !filters.hideDone },
|
||||
team: team(),
|
||||
entries: view === 'monat' ? entriesBetween(grid.start, grid.end, filters) : [],
|
||||
plans: view === 'monat' ? [] : allPlans({ ...filters, hideDone: view === 'liste' ? filters.hideDone : false }),
|
||||
ideas: unscheduled(filters),
|
||||
pageOptions: db.select({ id: pages.id, title: pages.title }).from(pages).orderBy(asc(pages.title)).all(),
|
||||
postOptions: db
|
||||
.select({ id: posts.id, title: posts.title })
|
||||
.from(posts)
|
||||
.orderBy(asc(posts.title))
|
||||
.all()
|
||||
};
|
||||
};
|
||||
|
||||
function readItem(form: FormData) {
|
||||
const f = fields(form);
|
||||
const kind = f.str('kind');
|
||||
const status = f.str('status');
|
||||
const date = f.str('date');
|
||||
const dueDate = f.str('dueDate');
|
||||
return {
|
||||
title: f.str('title'),
|
||||
notes: f.str('notes', 5000),
|
||||
kind: isKind(kind) ? kind : 'post',
|
||||
status: isStatus(status) ? status : 'idea',
|
||||
date: DATE.test(date) ? date : '',
|
||||
dueDate: DATE.test(dueDate) ? dueDate : '',
|
||||
assigneeId: f.int('assigneeId'),
|
||||
postId: f.int('postId'),
|
||||
pageId: f.int('pageId')
|
||||
};
|
||||
}
|
||||
|
||||
const getItem = (id: number | null) => {
|
||||
const item = id ? db.select().from(editorialItems).where(eq(editorialItems.id, id)).get() : undefined;
|
||||
if (!item) error(404, 'Eintrag nicht gefunden');
|
||||
return item;
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
save: async ({ request, locals }) => {
|
||||
const form = await request.formData();
|
||||
const id = fields(form).int('id');
|
||||
const values = readItem(form);
|
||||
if (!values.title) return fail(400, { error: 'Bitte gib einen Titel ein.' });
|
||||
if (id) {
|
||||
getItem(id);
|
||||
db.update(editorialItems).set(values).where(eq(editorialItems.id, id)).run();
|
||||
return { saved: id };
|
||||
}
|
||||
const created = db
|
||||
.insert(editorialItems)
|
||||
.values({ ...values, createdBy: locals.user!.id })
|
||||
.returning({ id: editorialItems.id })
|
||||
.get();
|
||||
return { saved: created.id };
|
||||
},
|
||||
|
||||
/** Ziehen & Ablegen oder Tastatur: Planung oder Meldung auf einen anderen Tag legen */
|
||||
move: async ({ request }) => {
|
||||
const f = fields(await request.formData());
|
||||
const type = f.str('type');
|
||||
const id = f.int('id');
|
||||
const date = f.str('date');
|
||||
if (date && !DATE.test(date)) return fail(400, { error: 'Ungültiges Datum.' });
|
||||
|
||||
if (type === 'plan') {
|
||||
getItem(id);
|
||||
db.update(editorialItems).set({ date }).where(eq(editorialItems.id, id!)).run();
|
||||
return { moved: true };
|
||||
}
|
||||
if (type === 'post' && id && date) {
|
||||
const post = db.select().from(posts).where(eq(posts.id, id)).get();
|
||||
if (!post) error(404);
|
||||
if (post.published && post.publishedAt.getTime() <= Date.now())
|
||||
return fail(400, { error: 'Bereits veröffentlichte Meldungen lassen sich nicht verschieben.' });
|
||||
// Uhrzeit beibehalten, nur den Tag ändern
|
||||
const time = toLocalInput(post.publishedAt).slice(11);
|
||||
db.update(posts).set({ publishedAt: fromLocalInput(`${date}T${time}`)! }).where(eq(posts.id, id)).run();
|
||||
return { moved: true };
|
||||
}
|
||||
return fail(400, { error: 'Dieser Eintrag lässt sich nicht verschieben.' });
|
||||
},
|
||||
|
||||
/** Status wechseln (Board) */
|
||||
status: async ({ request }) => {
|
||||
const f = fields(await request.formData());
|
||||
const id = f.int('id');
|
||||
const status = f.str('status');
|
||||
if (!isStatus(status)) return fail(400, { error: 'Unbekannter Status.' });
|
||||
getItem(id);
|
||||
db.update(editorialItems).set({ status }).where(eq(editorialItems.id, id!)).run();
|
||||
return { moved: true };
|
||||
},
|
||||
|
||||
delete: async ({ request }) => {
|
||||
const id = fields(await request.formData()).int('id');
|
||||
getItem(id);
|
||||
db.delete(editorialItems).where(eq(editorialItems.id, id!)).run();
|
||||
return { deleted: true };
|
||||
},
|
||||
|
||||
comment: async ({ request, locals }) => {
|
||||
const f = fields(await request.formData());
|
||||
const itemId = f.int('id');
|
||||
const body = f.str('body', 2000);
|
||||
if (!body) return fail(400, { error: 'Der Kommentar ist leer.' });
|
||||
getItem(itemId);
|
||||
db.insert(editorialComments).values({ itemId: itemId!, userId: locals.user!.id, body }).run();
|
||||
return { commented: true };
|
||||
},
|
||||
|
||||
deleteComment: async ({ request, locals }) => {
|
||||
const id = fields(await request.formData()).int('commentId');
|
||||
const c = id ? db.select().from(editorialComments).where(eq(editorialComments.id, id)).get() : undefined;
|
||||
if (!c) error(404);
|
||||
if (c.userId !== locals.user!.id && locals.user!.role !== 'admin')
|
||||
return fail(403, { error: 'Nur eigene Kommentare können gelöscht werden.' });
|
||||
db.delete(editorialComments).where(eq(editorialComments.id, c.id)).run();
|
||||
return { deleted: true };
|
||||
},
|
||||
|
||||
/** Aus einer Planung einen Meldungs-Entwurf erzeugen und verknüpfen */
|
||||
createPost: async ({ request }) => {
|
||||
const item = getItem(fields(await request.formData()).int('id'));
|
||||
if (item.postId) return { postId: item.postId };
|
||||
const paragraphs = item.notes
|
||||
.split(/\n{2,}/)
|
||||
.map((p) => p.trim())
|
||||
.filter(Boolean)
|
||||
.map((p) => `<p>${p.replace(/[&<>]/g, (ch) => ({ '&': '&', '<': '<', '>': '>' })[ch]!).replace(/\n/g, '<br>')}</p>`)
|
||||
.join('');
|
||||
const created = db
|
||||
.insert(posts)
|
||||
.values({
|
||||
title: item.title,
|
||||
slug: uniqueSlug(posts, item.title),
|
||||
content: paragraphs,
|
||||
published: false,
|
||||
publishedAt: item.date ? fromLocalInput(`${item.date}T09:00`)! : new Date()
|
||||
})
|
||||
.returning({ id: posts.id })
|
||||
.get();
|
||||
db.update(editorialItems)
|
||||
.set({ postId: created.id, status: item.status === 'idea' ? 'progress' : item.status })
|
||||
.where(eq(editorialItems.id, item.id))
|
||||
.run();
|
||||
return { postId: created.id };
|
||||
}
|
||||
};
|
||||
132
src/routes/admin/(panel)/redaktion/+page.svelte
Normal file
132
src/routes/admin/(panel)/redaktion/+page.svelte
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/state';
|
||||
import Plus from '@lucide/svelte/icons/plus';
|
||||
import ChevronLeft from '@lucide/svelte/icons/chevron-left';
|
||||
import ChevronRight from '@lucide/svelte/icons/chevron-right';
|
||||
import CalendarDays from '@lucide/svelte/icons/calendar-days';
|
||||
import Columns3 from '@lucide/svelte/icons/columns-3';
|
||||
import List from '@lucide/svelte/icons/list';
|
||||
import PageHeader from '$lib/admin/PageHeader.svelte';
|
||||
import MonthView from '$lib/admin/calendar/MonthView.svelte';
|
||||
import BoardView from '$lib/admin/calendar/BoardView.svelte';
|
||||
import ListView from '$lib/admin/calendar/ListView.svelte';
|
||||
import ItemDialog from '$lib/admin/calendar/ItemDialog.svelte';
|
||||
import { EDITORIAL_KINDS, kindKeys, type CalendarEntry, type EditorialStatus } from '$lib/editorial';
|
||||
import { formatMonthYear } from '$lib/dates';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
type Plan = Extract<CalendarEntry, { type: 'plan' }>;
|
||||
let editing = $state<Plan | null>(null);
|
||||
|
||||
/** URL-Parameter setzen (Ansicht, Monat, Filter) – ohne Scroll-Sprung */
|
||||
function setParam(patch: Record<string, string>) {
|
||||
const url = new URL(page.url);
|
||||
for (const [k, v] of Object.entries(patch)) v ? url.searchParams.set(k, v) : url.searchParams.delete(k);
|
||||
goto(url, { noScroll: true, keepFocus: true });
|
||||
}
|
||||
|
||||
function shiftMonth(delta: number) {
|
||||
const [y, m] = data.month.split('-').map(Number);
|
||||
const d = new Date(Date.UTC(y, m - 1 + delta, 1));
|
||||
setParam({ monat: d.toISOString().slice(0, 7) });
|
||||
}
|
||||
|
||||
function open(entry: CalendarEntry) {
|
||||
if (entry.type === 'plan') editing = { ...entry };
|
||||
else if (entry.type === 'post') goto(`/admin/meldungen/${entry.id}`);
|
||||
else goto(`/admin/termine/${entry.id}`);
|
||||
}
|
||||
|
||||
function create(date: string, status: EditorialStatus = date ? 'ready' : 'idea') {
|
||||
editing = {
|
||||
type: 'plan', id: 0, title: '', notes: '', kind: 'post', status, date, dueDate: '',
|
||||
assigneeId: data.user.id, postId: null, pageId: null, commentCount: 0
|
||||
};
|
||||
}
|
||||
|
||||
const views = [
|
||||
{ value: 'monat', label: 'Monat', icon: CalendarDays },
|
||||
{ value: 'board', label: 'Board', icon: Columns3 },
|
||||
{ value: 'liste', label: 'Liste', icon: List }
|
||||
] as const;
|
||||
</script>
|
||||
|
||||
<svelte:head><title>Redaktionskalender · {data.brand.appName}</title></svelte:head>
|
||||
|
||||
<PageHeader title="Redaktionskalender" description="Planen, verteilen und abstimmen – was erscheint wann, und wer kümmert sich?">
|
||||
{#snippet actions()}
|
||||
<button type="button" class="btn btn-primary" onclick={() => create('')}><Plus class="size-4" />Neue Planung</button>
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
<!-- Werkzeugleiste -->
|
||||
<div class="flex flex-wrap items-center gap-3 mb-6">
|
||||
<nav aria-label="Ansicht" class="inline-flex rounded-full bg-surface-2 p-1">
|
||||
{#each views as v (v.value)}
|
||||
<a
|
||||
href="?{new URLSearchParams({ ...Object.fromEntries(page.url.searchParams), ansicht: v.value })}"
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3.5 py-1.5 text-sm font-bold transition {data.view === v.value ? 'bg-surface text-brand-ink shadow-card' : 'text-ink-2 hover:text-ink'}"
|
||||
aria-current={data.view === v.value ? 'page' : undefined}
|
||||
data-sveltekit-noscroll
|
||||
>
|
||||
<v.icon class="size-4" />{v.label}
|
||||
</a>
|
||||
{/each}
|
||||
</nav>
|
||||
|
||||
{#if data.view === 'monat'}
|
||||
<div class="inline-flex items-center gap-1">
|
||||
<button type="button" class="btn btn-ghost btn-icon btn-sm" aria-label="Vorheriger Monat" onclick={() => shiftMonth(-1)}><ChevronLeft class="size-5" /></button>
|
||||
<h2 class="font-bold text-lg min-w-40 text-center" aria-live="polite">{formatMonthYear(`${data.month}-01`)}</h2>
|
||||
<button type="button" class="btn btn-ghost btn-icon btn-sm" aria-label="Nächster Monat" onclick={() => shiftMonth(1)}><ChevronRight class="size-5" /></button>
|
||||
{#if data.month !== data.today.slice(0, 7)}
|
||||
<button type="button" class="btn btn-soft btn-sm ml-1" onclick={() => setParam({ monat: '' })}>Heute</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2 ml-auto">
|
||||
<label class="sr-only" for="f-person">Nach Person filtern</label>
|
||||
<select id="f-person" class="field min-h-9 py-1 text-sm w-auto" value={data.filters.person} onchange={(e) => setParam({ person: e.currentTarget.value })}>
|
||||
<option value="">Alle Personen</option>
|
||||
<option value="ich">Nur meine</option>
|
||||
{#each data.team as m (m.id)}<option value={String(m.id)}>{m.name}</option>{/each}
|
||||
</select>
|
||||
<label class="sr-only" for="f-kind">Nach Art filtern</label>
|
||||
<select id="f-kind" class="field min-h-9 py-1 text-sm w-auto" value={data.filters.kind} onchange={(e) => setParam({ art: e.currentTarget.value })}>
|
||||
<option value="">Alle Arten</option>
|
||||
{#each kindKeys as k (k)}<option value={k}>{EDITORIAL_KINDS[k]}</option>{/each}
|
||||
</select>
|
||||
{#if data.view !== 'board'}
|
||||
<label class="inline-flex items-center gap-2 text-sm font-semibold cursor-pointer">
|
||||
<input type="checkbox" class="size-4 accent-[var(--brand)]" checked={data.filters.showDone} onchange={(e) => setParam({ erledigt: e.currentTarget.checked ? 'zeigen' : '' })} />
|
||||
Erledigte zeigen
|
||||
</label>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if data.view === 'monat'}
|
||||
<MonthView days={data.grid.days} month={data.month} entries={data.entries} ideas={data.ideas} team={data.team} today={data.today} onopen={open} oncreate={(d) => create(d)} />
|
||||
<p class="hint mt-4 flex flex-wrap gap-x-5 gap-y-1">
|
||||
<span>Einträge per Maus auf einen anderen Tag ziehen – oder öffnen und das Datum ändern.</span>
|
||||
<span><span class="inline-block size-2.5 rounded-sm bg-brand align-middle mr-1"></span>Meldung online</span>
|
||||
<span><span class="inline-block size-2.5 rounded-sm border border-dashed border-brand bg-brand-soft align-middle mr-1"></span>Meldung geplant / Entwurf</span>
|
||||
</p>
|
||||
{:else if data.view === 'board'}
|
||||
<BoardView plans={data.plans} team={data.team} today={data.today} onopen={open} oncreate={create} />
|
||||
<p class="hint mt-2">Karten zwischen den Spalten ziehen, um den Status zu ändern – oder öffnen und den Status wählen.</p>
|
||||
{:else}
|
||||
<ListView plans={data.plans} team={data.team} today={data.today} onopen={open} />
|
||||
{/if}
|
||||
|
||||
<ItemDialog
|
||||
bind:item={editing}
|
||||
team={data.team}
|
||||
me={data.user.id}
|
||||
isAdmin={data.user.role === 'admin'}
|
||||
postOptions={data.postOptions}
|
||||
pageOptions={data.pageOptions}
|
||||
/>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import { json } from '@sveltejs/kit';
|
||||
import { commentsFor } from '$lib/server/editorial';
|
||||
|
||||
export const GET = ({ params }) => json(commentsFor(Number(params.id)));
|
||||
Loading…
Add table
Add a link
Reference in a new issue