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
|
|
@ -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