NGU-Web/src/lib/adminSchema/events.ts
Zaldimmar e4a9c96f7e Finish the audit leftovers
- One mediaUrl in media.ts instead of 12 identical aliases and a
  kind map; orgPath builds on hrefs.ts's orgHref
- One Logo component (hides itself or shows a fallback when the file
  is missing) for event cards, org lists and chapter marks
- useHistory is a thin wrapper over useRecord
- adminSchema.ts split into adminSchema/, one file per entity plus
  shared.ts; the registry is unchanged (checked by loading both)
- JS smooth scrolls respect reduced motion (lib/motion.ts)
- Content-Security-Policy in Report-Only, with /api/csp-report logging
  what it would block

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:49:07 -05:00

203 lines
6.3 KiB
TypeScript

import { mediaUrl } from "../media.ts";
import { PLACE_FIELDS, PUBLISHED_FIELD, LISTED_FIELD, timelineGroup, timelineDetailGroup, linksChild, hostsChild, blocksChild } from "./shared.ts";
/* ── Events ──────────────────────────────────────────────────── */
/* The panel the Series checkbox opens. Starts and Ends above stay
the series' bounds (the first meeting and the last day it can
meet), so nothing here repeats them. */
const SERIES_WEEKDAYS = [
["sun", "Sunday"],
["mon", "Monday"],
["tue", "Tuesday"],
["wed", "Wednesday"],
["thu", "Thursday"],
["fri", "Friday"],
["sat", "Saturday"],
];
const seriesGroup = {
legend: "Series",
when: { path: "is_series", value: 1 },
note:
"Starts is the first meeting and anchors the schedule; Ends, if set, is the last " +
"day it can meet. The weekdays only apply to a weekly series; with none ticked it " +
"meets on the start date's day. Leave Date label blank and the site describes " +
"the schedule itself.",
fields: [
{
path: "series_frequency",
label: "Repeats",
widget: "select",
options: [
["weekly", "Weekly, on the days ticked below"],
["monthly_date", "Monthly, on the day of the start date (eg. the 13th)"],
["monthly_weekday", "Monthly, on the weekday of the start date (eg. 2nd Tuesday)"],
],
blankLabel: "Default: weekly",
},
{
path: "series_interval",
label: "Every",
widget: "number",
help: "1 for every week or month, 2 for every other, and so on",
},
{ path: "series_start_time", label: "Start time", widget: "time" },
{ path: "series_end_time", label: "End time", widget: "time" },
{
path: "series_count",
label: "Number of meetings",
widget: "number",
help: "Stops after this many. Blank to run until Ends, or indefinitely",
},
...SERIES_WEEKDAYS.map(([day, name]) => ({
path: `series_${day}`,
label: name,
widget: "checkbox",
help: `Meets on ${name}s`,
})),
],
};
export const events = {
key: "events",
label: "Events",
singular: "event",
idLabel: "URL ID",
slugFrom: "title",
list: {
columns: [
{ key: "title", label: "Title", primary: true },
{ key: "scope_id", label: "Scope" },
{ key: "event_type", label: "Type" },
{ key: "date_label", label: "Dates" },
{ key: "status", label: "Status" },
{ key: "is_published", label: "Live", widget: "bool" },
{ key: "is_listed", label: "Listed", widget: "bool" },
],
filters: [
{ key: "scope_id", label: "Scope", optionsFrom: "event_scopes" },
{
key: "event_type",
label: "Type",
options: ["retreat", "class", "workshop", "meeting", "other"],
},
{ key: "status", label: "Status", options: ["upcoming", "past", "cancelled"] },
{ key: "is_published", label: "Published", options: [["1", "Live"], ["0", "Hidden"]] },
{ key: "is_listed", label: "Listed", options: [["1", "Listed"], ["0", "Link only"]] },
],
},
groups: [
{
legend: "Identity",
fields: [
{
path: "scope_id",
label: "Scope",
widget: "select",
optionsFrom: "event_scopes",
required: true,
help: "Whose gathering this is.",
},
{
path: "event_type",
label: "Type",
widget: "select",
options: ["retreat", "class", "workshop", "meeting", "other"],
required: true,
help: "What kind of gathering. Independent of the scope",
},
{ path: "title", label: "Title", required: true },
{ path: "theme", label: "Theme" },
{ path: "tagline", label: "Tagline", full: true },
],
},
{
legend: "When",
fields: [
{ path: "starts_on", label: "Starts", widget: "date" },
{ path: "ends_on", label: "Ends", widget: "date" },
{
path: "date_label",
label: "Date label",
help: "Text override of what the card shows (eg. March/April 2026)",
},
{
path: "status",
label: "Status",
widget: "select",
options: ["upcoming", "past", "cancelled"],
blankLabel: "Default: derive from end date",
},
{
path: "is_series",
label: "Series",
widget: "checkbox",
help: "Repeats on a schedule, such as a weekly class, a monthly meeting",
},
],
},
seriesGroup,
{ legend: "Where", fields: PLACE_FIELDS },
{
legend: "Appearance",
fields: [
{ path: "event_logo", label: "Event logo", widget: "image", resolve: mediaUrl, full: true },
{ path: "org_logo", label: "Org logo override", widget: "image", resolve: mediaUrl, full: true },
{ path: "color", label: "Colour", widget: "color" },
{
path: "card_image",
label: "Card background",
widget: "image",
resolve: mediaUrl,
full: true,
help: "A photo behind the event's card, faded so the text stays readable.",
},
],
},
timelineGroup("event"),
timelineDetailGroup("event"),
{ legend: "Publishing", fields: [PUBLISHED_FIELD, LISTED_FIELD] },
],
children: [
hostsChild,
{
key: "event_people",
label: "People at this event",
addLabel: "Add person",
title: (row, options) =>
options?.people?.find((p) => p.id === row.person_id)?.label ?? "New person",
blank: { person_id: "", role: "speaker", is_public: 1 },
fields: [
{
path: "person_id",
label: "Person",
widget: "select",
optionsFrom: "people",
required: true,
},
{
path: "role",
label: "Role",
widget: "select",
options: [
"speaker",
"leader",
"facilitator",
"host",
"musician",
"volunteer",
"attendee",
],
},
{ path: "title", label: "Title", help: "eg. Keynote Speaker" },
{ path: "is_public", label: "Show on the site", widget: "checkbox" },
],
},
linksChild,
blocksChild,
],
};