forked from UKSOURCE/cms.lams
Replace the legacy section-based policy editor with a flexible block-based system. This transition enables real-time previews, a wider variety of content types (headings, quotes, callouts), and improved data normalization. - Implement `policies-block-editor.js` for dynamic content management - Add `normalizePoliciesDocument` and `validateContent` utilities to handle data migration and integrity - Update `policiesController.js` to support the new block structure and validation logic - Migrate `policies.json` from `sections` array to a `content.blocks` structure - Remove obsolete section editor views and partials - Update `policiesConfig.js` to reflect the new editor capabilities
108 lines
3.0 KiB
JavaScript
108 lines
3.0 KiB
JavaScript
const {
|
|
text,
|
|
textarea,
|
|
icon,
|
|
url,
|
|
combobox,
|
|
object,
|
|
objectList,
|
|
stringList,
|
|
variantList,
|
|
} = require("./sharedFields");
|
|
|
|
const baseConfig = {
|
|
key: "policies",
|
|
title: "Policies Management",
|
|
subtitle: "Manage policy metadata and block-based content for the policies page",
|
|
routeBase: "/admin/policies",
|
|
apiPath: "/api/policies",
|
|
previewPath: "/policies",
|
|
dataFile: "policies",
|
|
imageType: "policies",
|
|
tabs: [
|
|
{
|
|
key: "hero",
|
|
label: "Hero",
|
|
icon: "fas fa-scale-balanced",
|
|
schema: object("hero", "Hero", [
|
|
text("badge", "Eyebrow label", { maxLength: 40 }),
|
|
icon("icon", "Hero icon", {
|
|
helpText: "Policies uses icon-only controls and does not require image upload.",
|
|
}),
|
|
text("titlePrefix", "Headline prefix", { maxLength: 50 }),
|
|
text("titleHighlight", "Headline highlight", { maxLength: 40 }),
|
|
textarea("description", "Supporting text", {
|
|
maxLength: 220,
|
|
rows: 4,
|
|
}),
|
|
]),
|
|
},
|
|
{
|
|
key: "sidebar",
|
|
label: "Sidebar",
|
|
icon: "fas fa-bars",
|
|
schema: object("sidebar", "Sidebar", [
|
|
text("heading", "Sidebar heading", { maxLength: 30 }),
|
|
text("helperText", "Helper text", { maxLength: 60 }),
|
|
text("contactLabel", "Contact link label", { maxLength: 40 }),
|
|
url("contactHref", "Contact URL", { maxLength: 255 }),
|
|
]),
|
|
},
|
|
{
|
|
key: "policies",
|
|
label: "Policies",
|
|
icon: "fas fa-file-lines",
|
|
schema: objectList(
|
|
"policies",
|
|
"Policies",
|
|
[
|
|
text("navLabel", "Sidebar label", { maxLength: 40 }),
|
|
text("title", "Policy title", { maxLength: 70 }),
|
|
text("effectiveDate", "Effective date", { maxLength: 50 }),
|
|
textarea("intro", "Intro text", { maxLength: 260, rows: 4 }),
|
|
],
|
|
{
|
|
itemLabel: "Policy",
|
|
sortable: true,
|
|
itemTitleKey: "title",
|
|
itemSubtitleKey: "effectiveDate",
|
|
emptyText: "No policies yet.",
|
|
itemActions: [
|
|
{
|
|
label: "Edit Content",
|
|
icon: "fas fa-pen-to-square",
|
|
hrefTemplate: "/admin/policies/{id}/section",
|
|
className: "btn btn-outline-primary btn-sm",
|
|
},
|
|
],
|
|
},
|
|
),
|
|
},
|
|
],
|
|
};
|
|
|
|
function createPoliciesSectionEditorConfig(policy, allPolicies = []) {
|
|
const policyOptions = allPolicies
|
|
.filter((item) => item.id && item.id !== policy.id)
|
|
.map((item) => ({
|
|
value: item.id,
|
|
label: item.title || item.navLabel || item.id,
|
|
}));
|
|
|
|
return {
|
|
key: "policyContent",
|
|
title: `Policy Content: ${policy.title || policy.id}`,
|
|
subtitle: "Edit block-based policy content with realtime preview",
|
|
routeBase: `/admin/policies/${policy.id}/section`,
|
|
previewPath: "/policies",
|
|
imageType: "policies",
|
|
policyId: policy.id,
|
|
policyOptions,
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
baseConfig,
|
|
createPoliciesSectionEditorConfig,
|
|
};
|