Venues, map blocks and event blocks; schedule entries link to them
Data → Venues: a map picture with its locations marked as pins or boxes (088). A Map block draws a venue with its locations listed; a schedule names a venue and its entries pick a location, linking to the map on the page with it lit up. Entries and sub-items can name an event (a workshop) and take what they leave blank from it, and an Events block shows event cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3d087da005
commit
818d648e91
18 changed files with 964 additions and 35 deletions
|
|
@ -64,6 +64,7 @@ import { tags } from "./admin-schema/tags.js";
|
|||
import { contactTypes } from "./admin-schema/contactTypes.js";
|
||||
import { redirects } from "./admin-schema/redirects.js";
|
||||
import { pages } from "./admin-schema/sitePages.js";
|
||||
import { venues } from "./admin-schema/venues.js";
|
||||
|
||||
export const ENTITIES = {
|
||||
organizations,
|
||||
|
|
@ -73,6 +74,7 @@ export const ENTITIES = {
|
|||
tags,
|
||||
contact_types: contactTypes,
|
||||
redirects,
|
||||
venues,
|
||||
teams,
|
||||
awards,
|
||||
timeline,
|
||||
|
|
@ -106,6 +108,15 @@ export const OPTION_QUERIES = {
|
|||
contact_types: "SELECT id, name AS label FROM contact_types ORDER BY sort_order, name",
|
||||
// Link fields with `redirects: true` pick from these (068).
|
||||
redirects: "SELECT id, id || ' (' || target_url || ')' AS label FROM redirects ORDER BY id",
|
||||
// A map block's venue; its locations ride along (as JSON) for a
|
||||
// schedule's entries to pick from and for the block's preview.
|
||||
venues: `
|
||||
SELECT v.id, v.name AS label, v.map_image, v.map_alt,
|
||||
(SELECT json_group_array(json_object('key', l.location_key, 'name', l.name, 'detail', l.detail,
|
||||
'x', l.x, 'y', l.y, 'w', l.w, 'h', l.h))
|
||||
FROM (SELECT * FROM venue_locations WHERE venue_id = v.id ORDER BY sort_order) l) AS locations
|
||||
FROM venues v
|
||||
ORDER BY v.name`,
|
||||
blog_posts: "SELECT id, title AS label FROM blog_posts ORDER BY published_on DESC, title",
|
||||
// Navigation's Under page: a page by its address (080).
|
||||
site_pages: "SELECT path AS id, title || ' (' || path || ')' AS label FROM site_pages ORDER BY sort_order, title",
|
||||
|
|
|
|||
|
|
@ -154,6 +154,9 @@ export const blocksChild = (ownerKind) => ({
|
|||
"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",
|
||||
],
|
||||
{ required: true },
|
||||
),
|
||||
|
|
@ -170,6 +173,8 @@ export const blocksChild = (ownerKind) => ({
|
|||
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"),
|
||||
],
|
||||
children: [
|
||||
{
|
||||
|
|
@ -198,6 +203,10 @@ export const blocksChild = (ownerKind) => ({
|
|||
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"),
|
||||
],
|
||||
children: [
|
||||
{
|
||||
|
|
@ -223,6 +232,8 @@ export const blocksChild = (ownerKind) => ({
|
|||
text("map_image"),
|
||||
bool("featured"),
|
||||
text("tags"),
|
||||
text("event_id"),
|
||||
text("location_key"),
|
||||
],
|
||||
},
|
||||
],
|
||||
|
|
|
|||
44
server/src/admin-schema/venues.js
Normal file
44
server/src/admin-schema/venues.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { text, real } from "./columns.js";
|
||||
|
||||
/* ── Venues (088_venues.sql) ─────────────────────────────────────
|
||||
|
||||
A place we gather, with its map picture and the locations marked
|
||||
on it. Map blocks draw it, and schedule entries link to its
|
||||
locations. Its own entity because content_blocks.venue_id points
|
||||
at it; nothing points at a location's row, entries name one by
|
||||
location_key, so the locations can be replaced wholesale. */
|
||||
|
||||
export const venues = {
|
||||
key: "venues",
|
||||
table: "venues",
|
||||
idColumn: "id",
|
||||
idKind: "slug",
|
||||
|
||||
list: {
|
||||
columns: ["id", "name", "address"],
|
||||
filters: [],
|
||||
search: ["name", "id", "address"],
|
||||
order: "name",
|
||||
},
|
||||
|
||||
columns: [text("name", { required: true }), text("address"), text("map_image"), text("map_alt")],
|
||||
|
||||
children: [
|
||||
{
|
||||
key: "locations",
|
||||
table: "venue_locations",
|
||||
owner: { column: "venue_id" },
|
||||
order: "sort_order",
|
||||
columns: [
|
||||
// Made by the admin as the row is added, so it isn't input.
|
||||
text("location_key", { required: true, seeded: true }),
|
||||
text("name", { required: true }),
|
||||
text("detail"),
|
||||
real("x"),
|
||||
real("y"),
|
||||
real("w"),
|
||||
real("h"),
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
125
server/src/migrations/088_venues.sql
Normal file
125
server/src/migrations/088_venues.sql
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 088 VENUES, MAP BLOCKS AND EVENT BLOCKS
|
||||
--
|
||||
-- Data → Venues: a place we gather (a camp, a church), with one map
|
||||
-- picture and its marked locations, each a pin (x, y) or a box
|
||||
-- (x, y, w, h), in percent of the picture from its top left.
|
||||
--
|
||||
-- A 'map' content block draws a venue's map with its locations
|
||||
-- listed beside it; a schedule block names a venue too, and its
|
||||
-- entries and sub-items pick one of its locations (location_key),
|
||||
-- which links to the map block on the same page, the location
|
||||
-- lit up. The venue's locations are rewritten on every save, so an
|
||||
-- entry names one by `location_key` (made in the admin when the
|
||||
-- location is added), as schedule tags do (087).
|
||||
--
|
||||
-- An 'events' content block shows events as cards, an item each
|
||||
-- (event_id); a schedule entry or sub-item can name an event too
|
||||
-- (a workshop), and takes what it leaves blank from it.
|
||||
--
|
||||
-- content_blocks.type's CHECK can't change in place, so the table
|
||||
-- is rebuilt (as in 079), then its index and owner trigger made
|
||||
-- again.
|
||||
-- ═══════════════════════════════════════════════════════════════
|
||||
|
||||
CREATE TABLE venues (
|
||||
id TEXT PRIMARY KEY
|
||||
CONSTRAINT "A venue's URL ID can use only lowercase letters, numbers and hyphens, eg. camp-hebron."
|
||||
CHECK (id <> '' AND id NOT GLOB '*[^a-z0-9-]*'),
|
||||
name TEXT NOT NULL,
|
||||
address TEXT,
|
||||
map_image TEXT, -- an upload
|
||||
map_alt TEXT
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE venue_locations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
venue_id TEXT NOT NULL REFERENCES venues (id) ON DELETE CASCADE,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
location_key TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
detail TEXT,
|
||||
x REAL CHECK (x BETWEEN 0 AND 100),
|
||||
y REAL CHECK (y BETWEEN 0 AND 100),
|
||||
w REAL CHECK (w > 0 AND w <= 100), -- null: a pin
|
||||
h REAL CHECK (h > 0 AND h <= 100),
|
||||
UNIQUE (venue_id, location_key)
|
||||
) STRICT;
|
||||
|
||||
ALTER TABLE content_block_items ADD COLUMN event_id TEXT
|
||||
REFERENCES events (id) ON DELETE SET NULL;
|
||||
ALTER TABLE content_block_items ADD COLUMN location_key TEXT;
|
||||
ALTER TABLE content_block_subitems ADD COLUMN event_id TEXT
|
||||
REFERENCES events (id) ON DELETE SET NULL;
|
||||
ALTER TABLE content_block_subitems ADD COLUMN location_key TEXT;
|
||||
|
||||
CREATE TABLE content_blocks_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
owner_kind TEXT NOT NULL
|
||||
CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post', 'page_section',
|
||||
'newsletter')),
|
||||
owner_id TEXT NOT NULL,
|
||||
slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body', 'both')),
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
type TEXT NOT NULL
|
||||
CHECK (type IN ('heading', 'subheading', 'paragraph',
|
||||
'list', 'links', 'quote', 'image', 'divider',
|
||||
'video', 'button', 'callout', 'schedule', 'table', 'cards',
|
||||
'people', 'tab', 'map', 'events')),
|
||||
text TEXT,
|
||||
media TEXT,
|
||||
href TEXT,
|
||||
alt TEXT,
|
||||
cite TEXT,
|
||||
team_id TEXT REFERENCES teams (id) ON DELETE SET NULL,
|
||||
captions TEXT,
|
||||
word_motion TEXT CHECK (word_motion IN ('slide', 'flip', 'fade', 'type', 'mirror')),
|
||||
word_direction TEXT CHECK (word_direction IN ('top', 'bottom')),
|
||||
word_seconds INTEGER CHECK (word_seconds BETWEEN 1 AND 20),
|
||||
-- Map and schedule blocks: whose map, and whose locations.
|
||||
venue_id TEXT REFERENCES venues (id) ON DELETE SET NULL
|
||||
) STRICT;
|
||||
|
||||
INSERT INTO content_blocks_new
|
||||
(id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id, captions,
|
||||
word_motion, word_direction, word_seconds)
|
||||
SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id, captions,
|
||||
word_motion, word_direction, word_seconds
|
||||
FROM content_blocks;
|
||||
|
||||
PRAGMA legacy_alter_table = ON;
|
||||
DROP TABLE content_blocks;
|
||||
ALTER TABLE content_blocks_new RENAME TO content_blocks;
|
||||
PRAGMA legacy_alter_table = OFF;
|
||||
|
||||
CREATE INDEX content_blocks_owner_idx
|
||||
ON content_blocks (owner_kind, owner_id, slot, sort_order);
|
||||
|
||||
CREATE TRIGGER content_blocks_owner_exists
|
||||
BEFORE INSERT ON content_blocks
|
||||
BEGIN
|
||||
SELECT CASE
|
||||
WHEN new.owner_kind = 'event'
|
||||
AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such event')
|
||||
WHEN new.owner_kind = 'organization'
|
||||
AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such organization')
|
||||
WHEN new.owner_kind = 'person'
|
||||
AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such person')
|
||||
WHEN new.owner_kind = 'team'
|
||||
AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such team')
|
||||
WHEN new.owner_kind = 'blog_post'
|
||||
AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such blog post')
|
||||
WHEN new.owner_kind = 'page_section'
|
||||
AND NOT EXISTS (SELECT 1 FROM page_sections WHERE CAST(id AS TEXT) = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such page section')
|
||||
WHEN new.owner_kind = 'newsletter'
|
||||
AND NOT EXISTS (SELECT 1 FROM newsletters WHERE CAST(id AS TEXT) = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such newsletter')
|
||||
END;
|
||||
END;
|
||||
|
|
@ -79,6 +79,7 @@ const MEMBERS = ["showcase-member-1", "showcase-member-2", "showcase-member-3"];
|
|||
const EVENT = "showcase-event";
|
||||
const SERIES = "showcase-series";
|
||||
const PAST = "showcase-past-event";
|
||||
const VENUE = "showcase-venue";
|
||||
|
||||
/* ── Content ───────────────────────────────────────────────── */
|
||||
|
||||
|
|
@ -87,21 +88,24 @@ const PAST = "showcase-past-event";
|
|||
a description, graphic and map, one linked, a heading, a featured
|
||||
entry, a block with sub-items, a break, typed and picked times,
|
||||
tags (one a tab of its own in its color, one with No tab), and one
|
||||
with no day (it lands in a tab of its own). */
|
||||
with no day (it lands in a tab of its own). Its venue's locations
|
||||
(088) are picked on some entries, one with no typed Location, and
|
||||
one sub-item is the showcase workshop, filled in from it. */
|
||||
const SCHEDULE = [
|
||||
"schedule",
|
||||
{ text: "The weekend at a glance. Tap an entry for more." },
|
||||
{ text: "The weekend at a glance. Tap an entry for more.", venue_id: VENUE },
|
||||
[
|
||||
{ day: "Friday", start_time: "16:00", text: "Arrivals and check-in", location: "Front desk", tags: "showcase-youth,showcase-all" },
|
||||
{ day: "Friday", kind: "heading", text: "Evening", detail: "A heading across the day" },
|
||||
{ day: "Friday", time: "7:00 to 8:30pm", text: "Opening session", location: "Main Hall", person_id: "showcase-person", detail: "Welcome and worship", description: "The **opening session** sets the theme for the weekend.\n\nBring a notebook.", media: "/uploads/showcase.jpg", map: "Camp Hebron, Halifax PA", map_image: "/uploads/showcase.jpg" },
|
||||
{ day: "Friday", time: "7:00 to 8:30pm", text: "Opening session", location_key: "hall", person_id: "showcase-person", detail: "Welcome and worship", description: "The **opening session** sets the theme for the weekend.\n\nBring a notebook.", media: "/uploads/showcase.jpg", map: "Camp Hebron, Halifax PA", map_image: "/uploads/showcase.jpg" },
|
||||
{ day: "Saturday", start_time: "08:00", end_time: "09:00", kind: "break", text: "Breakfast", location: "Dining hall" },
|
||||
{ day: "Saturday", start_time: "09:00", end_time: "10:30", kind: "block", text: "Workshops", location: "Classrooms", detail: "Pick one of three", items: [
|
||||
{ start_time: "09:00", end_time: "09:45", text: "Leading worship", location: "Room A", person_id: "showcase-member-2", url: "/blog/content-block-showcase" },
|
||||
{ start_time: "09:00", end_time: "09:45", text: "Leading worship", location: "Room A", location_key: "rooma", person_id: "showcase-member-2", url: "/blog/content-block-showcase" },
|
||||
{ start_time: "09:00", end_time: "09:45", text: "Showcase Past Workshop", event_id: PAST, location_key: "rooma" },
|
||||
{ start_time: "09:00", end_time: "09:45", text: "Speaking with confidence", location: "Room B", featured: 1, tags: "showcase-youth", description: "A featured sub-item that folds out." },
|
||||
{ time: "After the first round", text: "Open questions", location: "Room C" },
|
||||
] },
|
||||
{ day: "Saturday", start_time: "19:00", featured: 1, tags: "showcase-youth", text: "Talent night", location: "Main Hall", person_id: "showcase-member-3", description: "Sign up at the front desk by noon." },
|
||||
{ day: "Saturday", start_time: "19:00", featured: 1, tags: "showcase-youth", text: "Talent night", location: "Main Hall", location_key: "hall", person_id: "showcase-member-3", description: "Sign up at the front desk by noon." },
|
||||
{ day: "Sunday", time: "10:00am", text: "Closing service", location: "Chapel", map: "Main Street, Halifax PA" },
|
||||
{ time: "Any time", text: "Quiet room open", location: "Library", detail: "An entry with no day" },
|
||||
],
|
||||
|
|
@ -141,6 +145,13 @@ const ALL_BLOCKS = [
|
|||
["image", { media: IMAGE, alt: "The same picture, linked", href: "/history" }],
|
||||
["subheading", { text: "Schedule" }],
|
||||
SCHEDULE,
|
||||
["subheading", { text: "Map" }],
|
||||
["map", { venue_id: VENUE }],
|
||||
["subheading", { text: "Events" }],
|
||||
["events", {}, [
|
||||
{ event_id: PAST, text: "Showcase Past Workshop" },
|
||||
{ event_id: "showcase-event", text: "A card with its own title", detail: "And its own text in place of the event's." },
|
||||
]],
|
||||
["subheading", { text: "Video" }],
|
||||
["video", { href: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", text: "A YouTube video, with its own thumbnail" }],
|
||||
["video", { href: "https://vimeo.com/76979871", media: IMAGE, text: "A Vimeo video with an uploaded still" }],
|
||||
|
|
@ -255,6 +266,7 @@ tx(db, () => {
|
|||
db.prepare(`DELETE FROM awards WHERE id LIKE 'showcase-%'`).run();
|
||||
db.prepare(`DELETE FROM affiliations WHERE person_id LIKE 'showcase-%' OR org_id LIKE 'showcase-%'`).run();
|
||||
db.prepare(`DELETE FROM teams WHERE id LIKE 'showcase-%'`).run();
|
||||
db.prepare(`DELETE FROM venues WHERE id LIKE 'showcase-%'`).run();
|
||||
db.prepare(`DELETE FROM people WHERE id LIKE 'showcase-%'`).run();
|
||||
db.prepare(`DELETE FROM organizations WHERE id = ?`).run(GROUP);
|
||||
db.prepare(`DELETE FROM organizations WHERE id LIKE 'showcase-%'`).run();
|
||||
|
|
@ -412,7 +424,6 @@ tx(db, () => {
|
|||
{ kind: "social", platform: "instagram", label: "@showcaseretreat", url: "https://instagram.com/showcaseretreat" },
|
||||
]);
|
||||
blocks("event", EVENT, "both", cardText("event"));
|
||||
blocks("event", EVENT, "body", [...pageBody("event"), ["heading", { text: "Schedule" }], SCHEDULE]);
|
||||
|
||||
insert("events", {
|
||||
id: SERIES,
|
||||
|
|
@ -458,6 +469,23 @@ tx(db, () => {
|
|||
insert("event_people", { event_id: PAST, person_id: PERSON, role: "host", is_public: 1, sort_order: 0 });
|
||||
blocks("event", PAST, "card", cardText("past event"));
|
||||
|
||||
/* ── Venue (088): a pin, a box and an unmarked location ── */
|
||||
insert("venues", { id: VENUE, name: "Showcase Retreat Center", address: "123 Example Road, Exampletown PA", map_image: IMAGE });
|
||||
[
|
||||
{ location_key: "hall", name: "Main Hall", detail: "Sessions and talent night", x: 30, y: 40 },
|
||||
{ location_key: "rooma", name: "Room A", detail: "Workshops", x: 55, y: 20, w: 25, h: 30 },
|
||||
{ location_key: "desk", name: "Front desk", detail: "Not marked on the map" },
|
||||
].forEach((location, i) => insert("venue_locations", { venue_id: VENUE, sort_order: i, ...location }));
|
||||
|
||||
// The retreat's page, after the workshop and venue its schedule names.
|
||||
blocks("event", EVENT, "body", [
|
||||
...pageBody("event"),
|
||||
["heading", { text: "Schedule" }],
|
||||
SCHEDULE,
|
||||
["heading", { text: "Map" }],
|
||||
["map", { venue_id: VENUE }],
|
||||
]);
|
||||
|
||||
/* ── Award ── */
|
||||
insert("awards", {
|
||||
id: AWARD,
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
|
|||
|
||||
const blockRows = db
|
||||
.prepare(
|
||||
`SELECT id, owner_id, type, text, media, href, alt, cite, captions, team_id,
|
||||
`SELECT id, owner_id, type, text, media, href, alt, cite, captions, team_id, venue_id,
|
||||
word_motion, word_direction, word_seconds
|
||||
FROM content_blocks
|
||||
WHERE owner_kind = ? AND slot IN (?, 'both') AND owner_id IN (${placeholders(ids.length)})
|
||||
|
|
@ -92,6 +92,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
|
|||
cite: row.cite,
|
||||
captions: row.captions,
|
||||
team_id: row.team_id,
|
||||
venue_id: row.venue_id,
|
||||
// Its rotating words' motion (084), when it has its own.
|
||||
words: row.word_motion || row.word_direction || row.word_seconds
|
||||
? { motion: row.word_motion, direction: row.word_direction, seconds: row.word_seconds }
|
||||
|
|
@ -109,6 +110,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
|
|||
|
||||
const ENTRY_FIELDS = `i.text, i.detail, i.url, i.start_time, i.end_time, i.time, i.location,
|
||||
i.description, i.media, i.media_alt, i.map, i.map_image, i.featured, i.tags,
|
||||
i.event_id, i.location_key,
|
||||
p.id AS person_id, p.display_name AS person_name,
|
||||
p.photo AS person_photo, p.tagline AS person_tagline`;
|
||||
|
||||
|
|
@ -172,9 +174,107 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
|
|||
block.items.forEach(cut);
|
||||
}
|
||||
|
||||
attachVenues(db, [...byId.values()]);
|
||||
attachEvents(db, [...byId.values()]);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/* A map or schedule block's venue (088), its locations in order,
|
||||
and each entry's location_key made its place on it: `place` is
|
||||
the location, and the location's name stands in for a blank
|
||||
typed Location. A key the venue no longer has is dropped. */
|
||||
function attachVenues(db, blocks) {
|
||||
const ids = [...new Set(blocks.map((block) => block.venue_id).filter(Boolean))];
|
||||
if (ids.length === 0) return;
|
||||
const venues = new Map(
|
||||
db
|
||||
.prepare(`SELECT id, name, address, map_image, map_alt FROM venues WHERE id IN (${placeholders(ids.length)})`)
|
||||
.all(...ids)
|
||||
.map((row) => [row.id, { ...row, locations: [] }]),
|
||||
);
|
||||
const locationRows = db
|
||||
.prepare(
|
||||
`SELECT venue_id, location_key AS key, name, detail, x, y, w, h
|
||||
FROM venue_locations
|
||||
WHERE venue_id IN (${placeholders(ids.length)})
|
||||
ORDER BY venue_id, sort_order`,
|
||||
)
|
||||
.all(...ids);
|
||||
for (const { venue_id, ...location } of locationRows) venues.get(venue_id)?.locations.push(location);
|
||||
|
||||
for (const block of blocks) {
|
||||
const venue = venues.get(block.venue_id);
|
||||
block.venue = venue ?? null;
|
||||
const place = (entry) => {
|
||||
const location = venue?.locations.find((l) => l.key === entry.location_key) ?? null;
|
||||
entry.place = location ? { venue_id: venue.id, key: location.key, name: location.name } : null;
|
||||
if (location && !entry.location) entry.location = location.name;
|
||||
entry.items?.forEach(place);
|
||||
};
|
||||
block.items.forEach(place);
|
||||
}
|
||||
}
|
||||
|
||||
/* The events named by items (088): an events block's cards, and a
|
||||
schedule entry or sub-item that is a workshop, which takes what
|
||||
it leaves blank from its event: the link, the description (its
|
||||
card text), the graphic (its photo) and the person (a person
|
||||
host). An unpublished event is no event. */
|
||||
function attachEvents(db, blocks) {
|
||||
const entries = [];
|
||||
const walk = (entry) => {
|
||||
entries.push(entry);
|
||||
entry.items?.forEach(walk);
|
||||
};
|
||||
blocks.forEach((block) => block.items.forEach(walk));
|
||||
const ids = [...new Set(entries.map((entry) => entry.event_id).filter(Boolean))];
|
||||
if (ids.length === 0) return;
|
||||
|
||||
const rows = db
|
||||
.prepare(
|
||||
`SELECT e.id, e.title, e.tagline, e.event_type, e.starts_on, e.ends_on, e.date_label,
|
||||
e.effective_color AS color, COALESCE(e.card_image, e.photo) AS image, e.photo_alt,
|
||||
p.id AS person_id, p.display_name AS person_name, p.photo AS person_photo,
|
||||
p.tagline AS person_tagline
|
||||
FROM v_events e
|
||||
LEFT JOIN v_people_public p ON e.host_kind = 'person' AND p.id = e.host_id AND p.is_published = 1
|
||||
WHERE e.is_published = 1 AND e.id IN (${placeholders(ids.length)})`,
|
||||
)
|
||||
.all(...ids);
|
||||
const cards = loadBlocks(db, "event", rows.map((row) => row.id), "card");
|
||||
const events = new Map(rows.map((row) => [row.id, row]));
|
||||
|
||||
for (const entry of entries) {
|
||||
const row = events.get(entry.event_id);
|
||||
if (!row) {
|
||||
entry.event = null;
|
||||
continue;
|
||||
}
|
||||
const blurb = paragraphs(cards.get(row.id) ?? []).join("\n\n") || row.tagline || null;
|
||||
entry.event = {
|
||||
id: row.id,
|
||||
title: row.title,
|
||||
event_type: row.event_type,
|
||||
starts_on: row.starts_on,
|
||||
ends_on: row.ends_on,
|
||||
date_label: row.date_label,
|
||||
color: row.color,
|
||||
image: row.image,
|
||||
blurb,
|
||||
};
|
||||
entry.url ||= `/events/${row.id}`;
|
||||
entry.description ||= blurb;
|
||||
if (!entry.media && row.image) {
|
||||
entry.media = row.image;
|
||||
entry.media_alt = row.photo_alt;
|
||||
}
|
||||
if (!entry.person && row.person_id) {
|
||||
entry.person = { id: row.person_id, name: row.person_name, photo: row.person_photo, tagline: row.person_tagline };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* A schedule entry or sub-item as the page gets it. `time` is what
|
||||
to show: the typed override, else the picked times (086). An
|
||||
unpublished person comes back as no person. */
|
||||
|
|
@ -194,6 +294,8 @@ function scheduleEntry(row) {
|
|||
map_image: row.map_image,
|
||||
featured: row.featured === 1,
|
||||
tags: row.tags ? row.tags.split(",").filter(Boolean) : [],
|
||||
event_id: row.event_id,
|
||||
location_key: row.location_key,
|
||||
person: row.person_id
|
||||
? {
|
||||
id: row.person_id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue