NGU-Web/server/src/admin-schema/columns.js
Zaldimmar a0eb9d7e49 Image block: a Size (small, medium, large), centered
- image_size (101): blank the column's full width, else up to 20, 32
  or 48rem, centered and never wider than the column

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 05:58:49 -06:00

309 lines
10 KiB
JavaScript

/* Column helpers, and the field sets and child collections several
entities share. The descriptor anatomy is in ../admin-schema.js. */
/* ── Column helpers ──────────────────────────────────────────── */
export const text = (name, opts = {}) => ({ name, type: "text", ...opts });
// Text that is a link: refuses javascript:, data: and other schemes.
export const url = (name, opts = {}) => ({ name, type: "url", ...opts });
export const int = (name, opts = {}) => ({ name, type: "int", ...opts });
export const real = (name, opts = {}) => ({ name, type: "real", ...opts });
export const bool = (name, opts = {}) => ({ name, type: "bool", ...opts });
export const date = (name, opts = {}) => ({ name, type: "date", ...opts });
export const time = (name, opts = {}) => ({ name, type: "time", ...opts });
export const enumeration = (name, values, opts = {}) => ({
name,
type: "enum",
values,
...opts,
});
/* Place columns shared by organizations and events, in schema order. */
export const placeColumns = [
text("venue"),
text("address"),
text("locality"),
text("state_code"),
text("country"),
text("location_label"),
real("latitude"),
real("longitude"),
];
/* The affiliation's own fields, minus whichever end owns the row.
Both editors write the same shape so neither loses the other's
values on save. */
export const affiliationRole = [
text("title"),
enumeration("role", ["lead", "board", "staff", "volunteer", "member"], {
required: true,
}),
bool("is_owner"),
date("started_on"),
date("ended_on"),
bool("is_public"),
];
/* The editable half of a timeline entry, shared by the standalone
editor and by the in_timeline extension on events and organizations.
occurred_on is text, not date. "2012" and "2025-07" are legitimate
values (a backfilled entry often knows the year and nothing more),
and the date coercion would reject both. `precision` is what says how
much of it to believe. */
export const timelineFields = [
text("occurred_on"),
enumeration("precision", ["year", "month", "day"]),
text("title"),
text("blurb"),
text("meta"),
url("link_url"),
bool("is_featured"),
bool("is_published"),
int("sort_order"),
];
/* The extension that the in_timeline checkbox drives. Ticked, the row
is upserted; unticked, writeExtensions deletes it. Both happen in the
parent's transaction, so the flag and the row cannot disagree.
The conflict target is the UNIQUE (ref_kind, ref_id) constraint
on timeline_entries, which is also what stops a second save creating a
duplicate instead of updating the first. */
export const timelineExtension = (refKind) => ({
key: "timeline",
table: "timeline_entries",
owner: { column: "ref_id", kindColumn: "ref_kind", kindValue: refKind },
conflict: ["ref_kind", "ref_id"],
when: { column: "in_timeline", value: 1 },
columns: [
// Fixed for this end: an event's entry is always an event entry.
// Declared as a default rather than a form field so the column is
// written without asking.
enumeration(
"kind",
["milestone", "event", "organization", "award", "people"],
{ default: refKind === "organization" ? "organization" : refKind },
),
...timelineFields,
],
});
/* Featured cards (030_featured_cards.sql): polymorphic like links,
so the Community blog can own a set too. */
export const featuredCardsChild = (ownerKind) => ({
key: "featured_cards",
table: "featured_cards",
owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind },
order: "sort_order",
columns: [
enumeration("kind", ["record", "link", "video"], { required: true }),
enumeration("ref_kind", ["event", "organization", "person", "team", "award"]),
text("ref_id"),
url("url"),
text("eyebrow"),
text("title"),
text("blurb"),
text("image"),
// Its shape in the grid (073); only the Front page editor sets it.
enumeration("size", ["normal", "wide", "tall", "large"]),
],
});
/* The two polymorphic collections, parameterized by owner_kind. */
export const linksChild = (ownerKind) => ({
key: "links",
table: "links",
owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind },
order: "sort_order",
columns: [
enumeration("kind", ["action", "social", "website", "email"], {
required: true,
}),
text("platform"),
text("label", { required: true }),
url("url", { required: true }),
bool("is_primary"),
],
});
export const blocksChild = (ownerKind) => ({
key: "content_blocks",
table: "content_blocks",
owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind },
order: "sort_order",
columns: [
enumeration("slot", ["card", "body", "both"], { required: true }),
enumeration(
"type",
[
"heading",
"subheading",
"paragraph",
"list",
"links",
"quote",
"image",
"divider",
"video",
"button",
"callout",
"schedule",
"table",
"cards",
"people",
// A blog post's tab (079): its text is the tab's title.
"tab",
// A venue's map, and event cards (088).
"map",
"events",
// Organization cards (093).
"organizations",
],
{ required: true },
),
text("text"),
text("media"),
url("href"),
text("alt"),
text("cite"),
// Video blocks only (066): an uploaded video's WebVTT file.
text("captions"),
// Its rotating words (084): blank keeps the site's.
enumeration("word_motion", ["slide", "flip", "fade", "type", "mirror"]),
enumeration("word_direction", ["top", "bottom"]),
int("word_seconds"),
// People blocks only (054): whose team's tiles to show.
text("team_id"),
// Map and schedule blocks (088): whose map and locations.
text("venue_id"),
// List blocks (092): null bold text, 'plain' the old look.
enumeration("list_style", ["plain"]),
// Image blocks (101): null full width, else a narrower size.
enumeration("image_size", ["small", "medium", "large"]),
// Organizations blocks (093): the kind listed when none are picked.
enumeration("org_kind", ["region", "group", "partner", "ministry"]),
// How it's presented (095): EventPresent.tsx.
// Where it shows (099): null both, the page or the presentation.
enumeration("present_show", ["page", "presentation"]),
text("present_text"),
bool("present_map_split"),
bool("present_map_no_list"),
bool("present_map_no_details"),
enumeration("present_places", ["picked", "none"]),
text("present_place_keys"),
],
children: [
{
key: "items",
table: "content_block_items",
owner: { column: "block_id" },
order: "sort_order",
columns: [
text("text", { required: true }),
text("detail"),
url("url"),
// Schedule entries only (034_schedule_block.sql).
text("day"),
text("time"),
text("location"),
text("person_id"),
text("description"),
text("media"),
text("media_alt"),
text("map"),
text("map_image"),
// Its kind, picked times and Featured tick (086).
enumeration("kind", ["block", "break", "heading"]),
time("start_time"),
time("end_time"),
bool("featured"),
// The block's tags it has, by key, comma-separated (087).
text("tags"),
// A workshop or other event it is, and its place on the
// block's venue map (088).
text("event_id"),
text("location_key"),
// A featured event's heading and subheading (090).
text("heading"),
text("subheading"),
// An organizations block's organization (093).
text("org_id"),
],
children: [
{
// A block entry's sub-items (086).
key: "items",
table: "content_block_subitems",
owner: { column: "item_id" },
order: "sort_order",
when: { column: "kind", value: "block" },
columns: [
text("text", { required: true }),
text("detail"),
url("url"),
time("start_time"),
time("end_time"),
text("time"),
text("location"),
text("person_id"),
text("description"),
text("media"),
text("media_alt"),
text("map"),
text("map_image"),
bool("featured"),
text("tags"),
text("event_id"),
text("location_key"),
],
},
],
},
{
// A schedule's own tags (087).
key: "tags",
table: "content_block_tags",
owner: { column: "block_id" },
order: "sort_order",
when: { column: "type", value: "schedule" },
columns: [
// Made by the admin as the row is added, so it isn't input.
text("tag_key", { required: true, seeded: true }),
text("name", { required: true }),
text("color"),
bool("no_tab"),
],
},
{
// A map block's own sections of its venue's locations (094).
key: "map_sections",
table: "content_block_map_sections",
owner: { column: "block_id" },
order: "sort_order",
when: { column: "type", value: "map" },
columns: [text("name", { required: true }), text("location_keys")],
},
],
});
/* Hosts. One row is one host, ordered, each either an organization
or a person. The CHECK on event_hosts rejects both and the blank
filter drops neither, so the only bad row that reaches SQLite is
one with both selects filled, and that comes back keyed to the
row like any other field error.
Not parameterized the way links and blocks are: this table is
events-only, and the owner column says so.
sort_order isn't declared. The engine writes it from the row's
position because `order` is "sort_order", which is what makes
the first row the one v_events takes the logo and color from. */
export const hostsChild = {
key: "event_hosts",
table: "event_hosts",
owner: { column: "event_id" },
order: "sort_order",
// team_id (054): an organization host's team, shown in its place.
columns: [text("org_id"), text("person_id"), text("team_id")],
};