Organization cards: list partners, ministries or a hand-picked set (migration 067)
The Partners section's preset gets "Cards: list" (partners by default, ministries, or both) and an optional hand-picked list (page_section_orgs, partners or ministries only, enforced by trigger) that replaces it in its own order. /organizations takes kind=ministry and ids=; the plain list still leaves ministries out. Ministry cards link to their website only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
635dd21083
commit
fd7e1b6fc1
11 changed files with 146 additions and 23 deletions
|
|
@ -96,6 +96,9 @@ export const OPTION_QUERIES = {
|
|||
"SELECT id, name AS label FROM organizations WHERE kind = 'region' ORDER BY name",
|
||||
ministries:
|
||||
"SELECT id, name AS label FROM organizations WHERE kind = 'ministry' ORDER BY name",
|
||||
// What an organization cards section can hand-pick (067).
|
||||
card_orgs:
|
||||
"SELECT id, name || ' (' || kind || ')' AS label FROM organizations WHERE kind IN ('partner', 'ministry') ORDER BY kind, name",
|
||||
event_scopes: "SELECT id, name AS label FROM event_scopes ORDER BY sort_order",
|
||||
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",
|
||||
|
|
|
|||
|
|
@ -36,8 +36,20 @@ const sectionsChild = {
|
|||
enumeration("event_type", ["retreat", "class", "workshop", "meeting", "other"]),
|
||||
enumeration("view", ["carousel", "grid", "map"]),
|
||||
text("tag_id"),
|
||||
// Organization cards (067): the kinds listed by themselves.
|
||||
enumeration("org_kinds", ["partner", "ministry", "partner,ministry"]),
|
||||
],
|
||||
children: [
|
||||
blocksChild("page_section"),
|
||||
{
|
||||
// Organization cards (067): a hand-picked list, shown instead.
|
||||
key: "orgs",
|
||||
table: "page_section_orgs",
|
||||
owner: { column: "section_id" },
|
||||
order: "sort_order",
|
||||
columns: [text("org_id", { required: true })],
|
||||
},
|
||||
],
|
||||
children: [blocksChild("page_section")],
|
||||
};
|
||||
|
||||
const sitePage = (id, more = {}) => ({
|
||||
|
|
|
|||
42
server/src/migrations/067_section_orgs.sql
Normal file
42
server/src/migrations/067_section_orgs.sql
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 067 ORGANIZATION CARDS: WHICH ORGANIZATIONS
|
||||
--
|
||||
-- The organization cards preset (page_sections.preset 'partner_list',
|
||||
-- the Community page's Partners) can list ministries as well as
|
||||
-- partners, chosen two ways:
|
||||
--
|
||||
-- page_sections.org_kinds which kinds it lists by itself, every
|
||||
-- published, listed one by name:
|
||||
-- 'partner', 'ministry' or both
|
||||
-- ('partner,ministry'). Blank: partners
|
||||
-- page_section_orgs a hand-picked list, in order; when a
|
||||
-- section has any, it shows those instead
|
||||
-- (published ones, listed or not). Only
|
||||
-- partners and ministries (triggers below)
|
||||
-- ═══════════════════════════════════════════════════════════════
|
||||
|
||||
ALTER TABLE page_sections ADD COLUMN org_kinds TEXT
|
||||
CHECK (org_kinds IN ('partner', 'ministry', 'partner,ministry'));
|
||||
|
||||
CREATE TABLE page_section_orgs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
section_id INTEGER NOT NULL REFERENCES page_sections (id) ON DELETE CASCADE,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
org_id TEXT NOT NULL REFERENCES organizations (id) ON DELETE CASCADE
|
||||
) STRICT;
|
||||
|
||||
CREATE INDEX page_section_orgs_section_idx ON page_section_orgs (section_id, sort_order);
|
||||
|
||||
CREATE TRIGGER page_section_orgs_kind
|
||||
BEFORE INSERT ON page_section_orgs
|
||||
FOR EACH ROW WHEN (SELECT kind FROM organizations WHERE id = new.org_id) NOT IN ('partner', 'ministry')
|
||||
BEGIN
|
||||
SELECT RAISE(ABORT, 'Organization cards can list partners and ministries only.');
|
||||
END;
|
||||
|
||||
CREATE TRIGGER page_section_orgs_kind_update
|
||||
BEFORE UPDATE OF org_id ON page_section_orgs
|
||||
FOR EACH ROW WHEN (SELECT kind FROM organizations WHERE id = new.org_id) NOT IN ('partner', 'ministry')
|
||||
BEGIN
|
||||
SELECT RAISE(ABORT, 'Organization cards can list partners and ministries only.');
|
||||
END;
|
||||
|
|
@ -72,7 +72,7 @@ const content = new Hono();
|
|||
|
||||
// Kinds with a public page. A ministry (063_ministries.sql) has none:
|
||||
// it's only named on its groups' pages, so no route here serves one.
|
||||
const ORG_KINDS = ["national", "region", "group", "partner"];
|
||||
const ORG_KINDS = ["national", "region", "group", "partner", "ministry"];
|
||||
|
||||
/* ── Loaders ───────────────────────────────────────────────── */
|
||||
|
||||
|
|
@ -597,6 +597,11 @@ content.get("/events/:id", (c) => {
|
|||
GET /organizations every published, listed org
|
||||
GET /organizations?kind=region one kind
|
||||
GET /organizations?kind=region,group
|
||||
GET /organizations?ids=a,b these, published, listed or
|
||||
not (a hand-picked list, 067)
|
||||
|
||||
Ministries come only when asked for, by kind or id: they have no
|
||||
page, so the plain list leaves them out.
|
||||
|
||||
Whatever the kind, the common card fields are in the same
|
||||
places, so a list component reads `name`, `color`, `logo` and
|
||||
|
|
@ -616,19 +621,21 @@ content.get("/organizations", (c) => {
|
|||
return c.json({ error: `kind must be one of ${ORG_KINDS.join(", ")}` }, 400);
|
||||
}
|
||||
|
||||
const filter = kinds.length > 0 ? `AND kind IN (${marks(kinds.length)})` : "";
|
||||
const ids = (c.req.query("ids") ?? "").split(",").map((id) => id.trim()).filter(Boolean).slice(0, 100);
|
||||
const [where, params] =
|
||||
ids.length > 0
|
||||
? [`id IN (${marks(ids.length)})`, ids]
|
||||
: kinds.length > 0
|
||||
? [`is_listed = 1 AND kind IN (${marks(kinds.length)})`, kinds]
|
||||
: [`is_listed = 1 AND kind <> 'ministry'`, []];
|
||||
|
||||
const rows = db
|
||||
.prepare(
|
||||
`SELECT * FROM organizations
|
||||
WHERE is_published = 1 AND is_listed = 1 AND kind <> 'ministry' ${filter}
|
||||
ORDER BY kind, sort_order, name`,
|
||||
)
|
||||
.all(...kinds);
|
||||
.prepare(`SELECT * FROM organizations WHERE is_published = 1 AND ${where} ORDER BY kind, sort_order, name`)
|
||||
.all(...params);
|
||||
|
||||
const ids = rows.map((row) => row.id);
|
||||
const links = loadLinks(db, "organization", ids);
|
||||
const cards = loadBlocks(db, "organization", ids, "card");
|
||||
const found = rows.map((row) => row.id);
|
||||
const links = loadLinks(db, "organization", found);
|
||||
const cards = loadBlocks(db, "organization", found, "card");
|
||||
|
||||
// No body blocks or leadership: they grow with every organization
|
||||
// and only a group's own detail panel or page shows them, which
|
||||
|
|
|
|||
|
|
@ -37,11 +37,21 @@ sitePages.get("/site-pages/:id", (c) => {
|
|||
|
||||
const rows = db
|
||||
.prepare(
|
||||
`SELECT id, anchor, title, blurb, accent, preset, scope_id, event_type, view, tag_id
|
||||
`SELECT id, anchor, title, blurb, accent, preset, scope_id, event_type, view, tag_id, org_kinds
|
||||
FROM page_sections WHERE page_id = ? ORDER BY sort_order, id`,
|
||||
)
|
||||
.all(id);
|
||||
const blocks = loadBlocks(db, "page_section", rows.map((row) => String(row.id)));
|
||||
const picked = new Map();
|
||||
for (const { section_id, org_id } of db
|
||||
.prepare(
|
||||
`SELECT o.section_id, o.org_id FROM page_section_orgs o
|
||||
JOIN page_sections s ON s.id = o.section_id
|
||||
WHERE s.page_id = ? ORDER BY o.section_id, o.sort_order, o.id`,
|
||||
)
|
||||
.all(id)) {
|
||||
picked.set(section_id, [...(picked.get(section_id) ?? []), org_id]);
|
||||
}
|
||||
|
||||
return json(c, {
|
||||
page: {
|
||||
|
|
@ -49,6 +59,7 @@ sitePages.get("/site-pages/:id", (c) => {
|
|||
sections: rows.map(({ id: sectionId, ...section }) => ({
|
||||
...section,
|
||||
blocks: blocks.get(String(sectionId)) ?? [],
|
||||
org_ids: picked.get(sectionId) ?? [],
|
||||
})),
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue