Schedule tags: a block's own tags, tag tabs, chips, a tag filter and tag slides

A schedule block gets its own tags (content_block_tags, migration 087):
a name, a color and whether it's a tab. Entries and sub-items pick them
from a checklist. Each tag is a tab after the days, gathering what it's
on from every day under the day's name; a tagged entry comes whole and
an untagged block brings only its tagged sub-items. Rows show their tags
as chips. The presentation can show only one tag's entries and adds a
slide per tag after the days.

Entries name a tag by a key the admin makes when the tag is added, so a
rename keeps them, since the block's rows are rewritten on every save.
For that the admin engine gets a function blank (fresh values for every
new row and copy, with a `seeded` column that doesn't count as input),
`lends` (a row's options for the collections nested in it) and a
checklist widget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-11-03 02:04:06 -06:00
parent 7885d10249
commit 71d58318b6
12 changed files with 539 additions and 122 deletions

View file

@ -494,6 +494,8 @@ function isBlankChildRow(child, raw) {
if (!raw || typeof raw !== "object") return true;
for (const column of child.columns) {
// A value the admin seeds every new row with (`seeded`), not input.
if (column.seeded) continue;
const value = raw[column.name];
if (value === undefined || value === null || value === "") continue;
// An unchecked box is the default state of a new row, not input.

View file

@ -196,6 +196,8 @@ export const blocksChild = (ownerKind) => ({
time("start_time"),
time("end_time"),
bool("featured"),
// The block's tags it has, by key, comma-separated (087).
text("tags"),
],
children: [
{
@ -220,10 +222,26 @@ export const blocksChild = (ownerKind) => ({
text("map"),
text("map_image"),
bool("featured"),
text("tags"),
],
},
],
},
{
// 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"),
],
},
],
});

View file

@ -0,0 +1,28 @@
-- ═══════════════════════════════════════════════════════════════
-- 087 SCHEDULE TAGS
--
-- A schedule block's own tags, eg. Youth or Worship: entries and
-- sub-items are tagged with them, a tag can be a tab of its own
-- gathering every entry it's on (across the days), and the schedule
-- presentation can show only one tag's entries and a slide per tag.
--
-- These are the block's, not Data → Tags (070). The block's rows are
-- rewritten on every save, so entries name a tag by `tag_key` (made
-- in the admin when the tag is added, kept when it's renamed), not
-- by its row id. An entry's `tags` is its keys, comma-separated; a
-- key no tag has any more is skipped.
-- ═══════════════════════════════════════════════════════════════
CREATE TABLE content_block_tags (
id INTEGER PRIMARY KEY AUTOINCREMENT,
block_id INTEGER NOT NULL REFERENCES content_blocks (id) ON DELETE CASCADE,
sort_order INTEGER NOT NULL DEFAULT 0,
tag_key TEXT NOT NULL,
name TEXT NOT NULL,
color TEXT, -- null: the event's accent
no_tab INTEGER NOT NULL DEFAULT 0 CHECK (no_tab IN (0, 1)),
UNIQUE (block_id, tag_key)
) STRICT;
ALTER TABLE content_block_items ADD COLUMN tags TEXT;
ALTER TABLE content_block_subitems ADD COLUMN tags TEXT;

View file

@ -86,24 +86,29 @@ const PAST = "showcase-past-event";
plain entry, one with a location and person, one folding out with
a description, graphic and map, one linked, a heading, a featured
entry, a block with sub-items, a break, typed and picked times,
and one with no day (it lands in a tab of its own). */
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). */
const SCHEDULE = [
"schedule",
{ text: "The weekend at a glance. Tap an entry for more." },
[
{ day: "Friday", start_time: "16:00", text: "Arrivals and check-in", location: "Front desk" },
{ 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: "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: "Speaking with confidence", location: "Room B", featured: 1, description: "A featured sub-item that folds out." },
{ 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, 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", 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" },
],
[
{ tag_key: "showcase-youth", name: "Youth", color: "#00748a" },
{ tag_key: "showcase-all", name: "Everyone", no_tab: 1 },
],
];
/* Every block type, for the blog showcase. [type, fields, items?] */
@ -208,7 +213,7 @@ function insert(table, row) {
}
function blocks(ownerKind, ownerId, slot, list) {
list.forEach(([type, f, items = []], order) => {
list.forEach(([type, f, items = [], tags = []], order) => {
const { lastInsertRowid } = insert("content_blocks", {
owner_kind: ownerKind,
owner_id: ownerId,
@ -221,6 +226,7 @@ function blocks(ownerKind, ownerId, slot, list) {
const entry = insert("content_block_items", { block_id: lastInsertRowid, sort_order: i, ...item });
subitems.forEach((sub, j) => insert("content_block_subitems", { item_id: entry.lastInsertRowid, sort_order: j, ...sub }));
});
tags.forEach((tag, i) => insert("content_block_tags", { block_id: lastInsertRowid, sort_order: i, ...tag }));
});
}

View file

@ -108,7 +108,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
const blockIds = [...byId.keys()];
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.description, i.media, i.media_alt, i.map, i.map_image, i.featured, i.tags,
p.id AS person_id, p.display_name AS person_name,
p.photo AS person_photo, p.tagline AS person_tagline`;
@ -146,6 +146,32 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
for (const row of subRows) itemsById.get(row.item_id)?.items.push(scheduleEntry(row));
}
// A schedule's own tags (087), and each entry's cut to the ones
// the block still has.
const tagRows = db
.prepare(
`SELECT block_id, tag_key, name, color, no_tab
FROM content_block_tags
WHERE block_id IN (${placeholders(blockIds.length)})
ORDER BY block_id, sort_order`,
)
.all(...blockIds);
for (const row of tagRows) {
const block = byId.get(row.block_id);
if (!block) continue;
block.tags ??= [];
block.tags.push({ key: row.tag_key, name: row.name, color: row.color, tab: row.no_tab === 0 });
}
for (const block of byId.values()) {
if (block.type !== "schedule") continue;
const known = new Set((block.tags ??= []).map((tag) => tag.key));
const cut = (entry) => {
entry.tags = entry.tags.filter((key) => known.has(key));
entry.items?.forEach(cut);
};
block.items.forEach(cut);
}
return out;
}
@ -167,6 +193,7 @@ function scheduleEntry(row) {
map: row.map,
map_image: row.map_image,
featured: row.featured === 1,
tags: row.tags ? row.tags.split(",").filter(Boolean) : [],
person: row.person_id
? {
id: row.person_id,