Group pages: framed facts, tags for organizations and events, every website and email (migration 070)

- Email buttons went to the link's label, not its URL (splitLinks took
  the label); they use the URL now, with or without mailto:.
- Every website and email row is listed, each with its own label,
  instead of only the first.
- The facts at the top of an organization page sit in a framed card:
  City, Part of <name> Region, Ministry, Meets, Since, and its tags.
- Tags (070): Data -> Tags (Online, In-Person to start) replace the
  Online checkbox on organizations and events. Ticked records get the
  Online tag; v_events reads the "online" tag as is_online, so the
  calendar filter and place lines are unchanged. Tags show on the
  record's page and on group entries in the Community map list and
  grid. The map no longer keeps online groups off their state's tile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-10-06 04:58:56 -05:00
parent 07c15ce96d
commit b55b088e16
23 changed files with 344 additions and 93 deletions

View file

@ -55,6 +55,7 @@ import { blogPosts } from "./admin-schema/blog.js";
import { siteSettings } from "./admin-schema/siteSettings.js";
import { newsletters } from "./admin-schema/newsletters.js";
import { personTagTypes } from "./admin-schema/personTags.js";
import { tags } from "./admin-schema/tags.js";
import { contactTypes } from "./admin-schema/contactTypes.js";
import { redirects } from "./admin-schema/redirects.js";
import {
@ -70,6 +71,7 @@ export const ENTITIES = {
events,
people,
person_tag_types: personTagTypes,
tags,
contact_types: contactTypes,
redirects,
teams,
@ -105,6 +107,7 @@ export const OPTION_QUERIES = {
events: "SELECT id, title AS label FROM events ORDER BY starts_on DESC, title",
people: "SELECT id, display_name AS label FROM people ORDER BY sort_name, display_name",
person_tag_types: "SELECT id, name AS label FROM person_tag_types ORDER BY sort_order, name",
tags: "SELECT id, name AS label FROM tags ORDER BY sort_order, name",
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",

View file

@ -28,7 +28,6 @@ export const placeColumns = [
text("location_label"),
real("latitude"),
real("longitude"),
bool("is_online"),
];
/* The affiliation's own fields, minus whichever end owns the row.

View file

@ -1,4 +1,5 @@
import { text, int, bool, date, time, enumeration, placeColumns, timelineExtension, linksChild, blocksChild, hostsChild } from "./columns.js";
import { tagsChild } from "./tags.js";
/* ── Events ──────────────────────────────────────────────────── */
@ -85,6 +86,7 @@ export const events = {
children: [
hostsChild,
tagsChild("event_tags", "event_id"),
linksChild("event"),
blocksChild("event"),
{

View file

@ -1,4 +1,5 @@
import { text, int, real, bool, enumeration, placeColumns, timelineExtension, linksChild, blocksChild } from "./columns.js";
import { tagsChild } from "./tags.js";
/* ── Organizations ───────────────────────────────────────────── */
@ -67,6 +68,7 @@ export const organizations = {
],
children: [
tagsChild("organization_tags", "org_id"),
linksChild("organization"),
blocksChild("organization"),
// Who to write to there, by role (064_org_contacts.sql): private,

View file

@ -0,0 +1,35 @@
import { text, int } from "./columns.js";
/* ── Tags (070_tags.sql) ─────────────────────────────────────────
Descriptor tags for organizations and events (Online, In-Person).
Its own entity, not a repeater, because organization_tags and
event_tags point at it: deleting a tag takes it off every record
(cascade). Which records carry a tag is edited on the record. The
URL ID "online" is what v_events reads as an online event. */
export const tags = {
key: "tags",
table: "tags",
idColumn: "id",
idKind: "slug",
list: {
columns: ["id", "name", "sort_order"],
filters: [],
search: ["name", "id"],
order: "sort_order, name",
},
columns: [text("name", { required: true }), int("sort_order")],
};
/* The Tags repeater on an organization or event: owner is the
record's id column in that tag table. */
export const tagsChild = (table, owner) => ({
key: "tags",
table,
owner: { column: owner },
order: "sort_order",
columns: [text("tag_id", { required: true })],
});

View file

@ -0,0 +1,84 @@
-- ═══════════════════════════════════════════════════════════════
-- 070 TAGS
--
-- Descriptor tags for organizations and events (Data → Tags), in
-- place of the Online checkbox: Online and In-Person to start, more
-- as they're needed. A record's tags show on its page and, for
-- groups, on the Community map's list and grid.
--
-- The tag with URL ID "online" still means online to the site:
-- v_events turns it back into is_online, which the calendar's
-- online filter, the "Online" place line and an event's search data
-- read. Records ticked Online get the tag; nothing gets In-Person
-- automatically.
-- ═══════════════════════════════════════════════════════════════
CREATE TABLE tags (
id TEXT PRIMARY KEY
CONSTRAINT "A tag's URL ID can use only lowercase letters, numbers and hyphens, eg. in-person."
CHECK (id <> '' AND id NOT GLOB '*[^a-z0-9-]*'),
name TEXT NOT NULL, -- 'In-Person', as shown
sort_order INTEGER NOT NULL DEFAULT 0
) STRICT;
INSERT INTO tags (id, name, sort_order) VALUES
('online', 'Online', 0),
('in-person', 'In-Person', 1);
CREATE TABLE organization_tags (
org_id TEXT NOT NULL REFERENCES organizations (id) ON DELETE CASCADE,
tag_id TEXT NOT NULL REFERENCES tags (id) ON DELETE CASCADE,
sort_order INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (org_id, tag_id)
) STRICT;
CREATE INDEX organization_tags_tag_idx ON organization_tags (tag_id);
CREATE TABLE event_tags (
event_id TEXT NOT NULL REFERENCES events (id) ON DELETE CASCADE,
tag_id TEXT NOT NULL REFERENCES tags (id) ON DELETE CASCADE,
sort_order INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (event_id, tag_id)
) STRICT;
CREATE INDEX event_tags_tag_idx ON event_tags (tag_id);
INSERT INTO organization_tags (org_id, tag_id) SELECT id, 'online' FROM organizations WHERE is_online = 1;
INSERT INTO event_tags (event_id, tag_id) SELECT id, 'online' FROM events WHERE is_online = 1;
-- v_events reads e.*, so it goes while the column does and comes
-- back with is_online from the tag.
DROP VIEW v_events;
ALTER TABLE organizations DROP COLUMN is_online;
ALTER TABLE events DROP COLUMN is_online;
CREATE VIEW v_events AS
SELECT
e.*,
EXISTS (SELECT 1 FROM event_tags et WHERE et.event_id = e.id AND et.tag_id = 'online')
AS is_online,
CASE WHEN eh.id IS NULL THEN NULL
WHEN eh.person_id IS NULL THEN 'organization' ELSE 'person' END
AS host_kind,
COALESCE(eh.org_id, eh.person_id) AS host_id,
COALESCE(o.name, p.display_name) AS host_name,
o.kind AS host_org_kind,
COALESCE(e.org_logo, o.logo) AS effective_org_logo,
COALESCE(e.color, o.color) AS effective_color,
COALESCE(
e.status,
CASE WHEN e.ends_on IS NOT NULL AND e.ends_on < date('now')
THEN 'past' ELSE 'upcoming' END
) AS effective_status
FROM events e
LEFT JOIN event_hosts eh
ON eh.id = (
SELECT x.id
FROM event_hosts x
LEFT JOIN organizations xo ON xo.id = x.org_id
LEFT JOIN people xp ON xp.id = x.person_id
WHERE x.event_id = e.id
AND COALESCE(xo.is_published, xp.is_published) = 1
ORDER BY x.sort_order, x.id
LIMIT 1
)
LEFT JOIN organizations o ON o.id = eh.org_id
LEFT JOIN people p ON p.id = eh.person_id;

View file

@ -62,6 +62,7 @@ import {
paragraphs,
shapeSeries,
splitLinks,
attachTags,
} from "../shape.js";
const content = new Hono();
@ -166,7 +167,7 @@ function shapeEvent(row, links, cardBlocks, hosts = []) {
/* The common card surface every organization has, whatever kind it
is. Kind-specific fields go in `details`, attached by the caller. */
function shapeOrganization(row, links, cardBlocks, bodyBlocks) {
const { actions, socials, website, email, instagram } = splitLinks(links);
const { actions, socials, websites, emails, website, email, instagram } = splitLinks(links);
return {
id: row.id,
@ -183,16 +184,18 @@ function shapeOrganization(row, links, cardBlocks, bodyBlocks) {
state_code: row.state_code,
country: row.country,
location_label: row.location_label,
is_online: asBool(row.is_online),
sort_order: row.sort_order,
description: paragraphs(cardBlocks),
blocks: bodyBlocks,
links: actions,
socials,
websites,
emails,
website,
email,
instagram,
tags: [],
details: {},
leadership: [],
@ -583,14 +586,10 @@ content.get("/events/:id", (c) => {
citation: r.citation,
}));
return json(c, {
event: {
...shapeEvent(row, links, cards, hosts),
blocks: body,
people,
awards,
},
});
const event = { ...shapeEvent(row, links, cards, hosts), blocks: body, people, awards };
attachTags(db, "event", [event]);
return json(c, { event });
});
/* ── Organizations ─────────────────────────────────────────────
@ -647,6 +646,7 @@ content.get("/organizations", (c) => {
attachRegionDetails(db, organizations);
attachGroupDetails(db, organizations);
attachTags(db, "organization", organizations);
return json(c, { organizations });
});
@ -669,6 +669,7 @@ content.get("/organizations/:id", (c) => {
attachRegionDetails(db, one);
attachGroupDetails(db, one);
attachTags(db, "organization", one);
attachLeadership(db, one);
attachTeams(db, one);
attachAwards(db, one);

View file

@ -179,6 +179,10 @@ const standardLinks = (name) => [
{ kind: "social", platform: "youtube", label: "YouTube", url: "https://youtube.com/@showcase" },
{ kind: "website", label: "Website", url: "https://example.org" },
{ kind: "email", label: "showcase@example.org", url: "mailto:showcase@example.org" },
// A second of each, labeled unlike its address: both listed, each
// going to its own URL.
{ kind: "website", label: "Our blog", url: "https://example.org/blog" },
{ kind: "email", label: "Prayer requests", url: "prayer@example.org" },
];
/* ── Writing ───────────────────────────────────────────────── */
@ -246,7 +250,6 @@ tx(db, () => {
color: "#7a5ea8",
logo: IMAGE,
...place,
is_online: 0,
is_published: 1,
is_listed: LISTED,
sort_order: 99,
@ -269,12 +272,12 @@ tx(db, () => {
logo: IMAGE,
...place,
venue: "Showcase Community Hall",
is_online: 1,
is_published: 1,
is_listed: LISTED,
sort_order: 99,
});
insert("groups", { id: GROUP, region_id: REGION, meets: "2nd Sundays, 6:00pm", started: "Since 2021" });
["in-person", "online"].forEach((tag_id, i) => insert("organization_tags", { org_id: GROUP, tag_id, sort_order: i }));
links("organization", GROUP, standardLinks("Showcase Group"));
blocks("organization", GROUP, "card", cardText("group"));
blocks("organization", GROUP, "body", pageBody("group"));
@ -364,7 +367,6 @@ tx(db, () => {
ends_on: db.prepare(`SELECT date('now', '+47 days') AS d`).get().d,
date_label: "Three days, six weeks from now",
...place,
is_online: 0,
org_logo: IMAGE,
event_logo: IMAGE,
color: "#d62976",
@ -402,7 +404,6 @@ tx(db, () => {
starts_on: db.prepare(`SELECT date('now', '-14 days') AS d`).get().d,
ends_on: db.prepare(`SELECT date('now', '+90 days') AS d`).get().d,
location_label: "Online",
is_online: 1,
color: "#138ba0",
is_series: 1,
series_frequency: "weekly",
@ -416,6 +417,7 @@ tx(db, () => {
is_listed: LISTED,
});
insert("event_hosts", { event_id: SERIES, org_id: GROUP, sort_order: 0 });
insert("event_tags", { event_id: SERIES, tag_id: "online" });
links("event", SERIES, [{ kind: "action", label: "Join on Zoom", url: "https://example.org/zoom" }]);
blocks("event", SERIES, "card", cardText("series"));

View file

@ -160,12 +160,42 @@ export function paragraphs(blocks = []) {
underlying rows are the same table.
───────────────────────────────────────────────────────────── */
/* ── Tags (070_tags.sql) ───────────────────────────────────────
Sets `tags` ([{ id, name }], in the record's order) on each of
these shaped organizations or events, in one query. */
const TAG_TABLES = { organization: ["organization_tags", "org_id"], event: ["event_tags", "event_id"] };
export function attachTags(db, kind, records) {
if (records.length === 0) return;
const [table, owner] = TAG_TABLES[kind];
const rows = db
.prepare(
`SELECT x.${owner} AS owner_id, t.id, t.name
FROM ${table} x
JOIN tags t ON t.id = x.tag_id
WHERE x.${owner} IN (${placeholders(records.length)})
ORDER BY x.sort_order, t.sort_order, t.name`,
)
.all(...records.map((record) => record.id));
for (const record of records) {
record.tags = rows.filter((row) => row.owner_id === record.id).map(({ id, name }) => ({ id, name }));
}
}
export function splitLinks(links = []) {
const websites = links.filter((link) => link.kind === "website");
// An email row's URL is the address, with or without mailto:.
const emails = links
.filter((link) => link.kind === "email")
.map((link) => ({ ...link, url: link.url.replace(/^mailto:/i, "") }));
return {
actions: links.filter((link) => link.kind === "action"),
socials: links.filter((link) => link.kind === "social"),
website: links.find((link) => link.kind === "website")?.url ?? null,
email: links.find((link) => link.kind === "email")?.label ?? null,
// Every one, for a record's own page; the first, for cards.
websites,
emails,
website: websites[0]?.url ?? null,
email: emails[0]?.url ?? null,
instagram:
links.find((link) => link.platform === "instagram")?.label ?? null,
};