72 lines
2.6 KiB
JavaScript
72 lines
2.6 KiB
JavaScript
// Shared admin-UI rendering helpers for site-sync route modules.
|
|
//
|
|
// Every admin page renders in the ACTIVE Saltcorn theme via res.sendWrap, built
|
|
// from the same native markup primitives the core admin pages use (mkTable /
|
|
// renderForm / post_btn), so the pages inherit the theme by construction. Route
|
|
// handlers are split across phase modules (routes.js, plan.js, apply.js, ...) and
|
|
// all import these helpers so there is one rendering path and one nav.
|
|
|
|
const { mkTable, post_btn, renderForm, link, tags } = require("@saltcorn/markup");
|
|
const { p, code, pre, span, strong } = tags;
|
|
const Form = require("@saltcorn/data/models/form");
|
|
|
|
// requireAdmin / escapeHtml / csrfField / navPills / flashRedirect are shared by
|
|
// the plugins (lib/common/); re-exported below so handler modules import from
|
|
// one place.
|
|
const { escapeHtml } = require("./common/htmlEscape");
|
|
const { csrfField, navPills, flashRedirect } = require("./common/adminHtml");
|
|
const { requireAdmin } = require("./common/adminGate");
|
|
|
|
|
|
// Every admin URL, in one place (routes.js registers them; nav + forms link them).
|
|
const ADMIN_BASE = "/admin/site-sync";
|
|
const ADMIN_URLS = {
|
|
DASHBOARD: `${ADMIN_BASE}/`,
|
|
SETTINGS: `${ADMIN_BASE}/settings`,
|
|
PEERS: `${ADMIN_BASE}/peers`,
|
|
PEERS_ADD: `${ADMIN_BASE}/peers/add`,
|
|
PEERS_ROTATE: `${ADMIN_BASE}/peers/rotate`,
|
|
PEERS_DELETE: `${ADMIN_BASE}/peers/delete`,
|
|
PLAN: `${ADMIN_BASE}/plan`,
|
|
APPLY: `${ADMIN_BASE}/apply`,
|
|
ROLLBACK: `${ADMIN_BASE}/rollback`,
|
|
TABLES: `${ADMIN_BASE}/tables`,
|
|
TABLES_SET: `${ADMIN_BASE}/tables/set`
|
|
};
|
|
|
|
|
|
// Nav tabs for the whole plugin.
|
|
const SS_NAV = [
|
|
[ADMIN_URLS.DASHBOARD, "Dashboard"],
|
|
[ADMIN_URLS.PEERS, "Peers"],
|
|
[ADMIN_URLS.PLAN, "Plan"],
|
|
[ADMIN_URLS.TABLES, "Tables"],
|
|
];
|
|
|
|
|
|
// Render an admin page: breadcrumbs + sub-nav + the given content segments (cards
|
|
// or strings), all via res.sendWrap (which also renders any req.flash messages).
|
|
const adminPage = (req, res, title, ...segments) => {
|
|
const above = [
|
|
{ type: "breadcrumbs", crumbs: [{ text: "Settings", href: "/settings" }, { text: "site-sync" }, { text: title }] },
|
|
navPills(req, SS_NAV),
|
|
];
|
|
res.sendWrap(`site-sync ${title}`, { above: above.concat(segments) });
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
ADMIN_URLS,
|
|
requireAdmin,
|
|
escapeHtml,
|
|
csrfField,
|
|
adminPage,
|
|
flashRedirect,
|
|
// markup primitives re-exported so handler modules import from one place
|
|
mkTable,
|
|
post_btn,
|
|
renderForm,
|
|
link,
|
|
Form,
|
|
p, code, pre, span, strong
|
|
};
|