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