forked from UKSOURCE/cms.lams
Improve the CMS administration interface across multiple pages (Accreditation, Admissions, History, Partnerships, and Policies) with a focus on usability and data integrity. Key changes include: - Implement `ensureUniqueIds` utility to automatically generate and maintain unique slugs for content items, removing the need for manual ID entry in the UI. - Refactor the Admissions calculator to support detailed per-option editing via a new dedicated view and routes. - Replace basic datalists with a custom, searchable icon combobox component for better visual selection. - Update `_renderSingletonPageView` to handle active tab persistence via query parameters. - Streamline editor configurations by removing redundant fields and improving help text. - Enhance the Admissions "Key Dates" editor with a dynamic table interface for managing columns and rows. - Normalize data payloads in controllers to ensure consistent API responses and internal linking.
208 lines
6.4 KiB
JavaScript
208 lines
6.4 KiB
JavaScript
const {
|
|
text,
|
|
textarea,
|
|
icon,
|
|
url,
|
|
combobox,
|
|
object,
|
|
objectList,
|
|
stringList,
|
|
variantList,
|
|
} = require("./sharedFields");
|
|
|
|
const baseConfig = {
|
|
key: "policies",
|
|
title: "Policies Management",
|
|
subtitle: "Manage the 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 Sections",
|
|
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: "policySections",
|
|
title: `Policy Sections: ${policy.title || policy.id}`,
|
|
subtitle: "Manage section content and paragraph order for this policy",
|
|
routeBase: `/admin/policies/${policy.id}/section`,
|
|
previewPath: "/policies",
|
|
imageType: "policies",
|
|
tabs: [
|
|
{
|
|
key: "sections",
|
|
label: "Sections",
|
|
icon: "fas fa-file-lines",
|
|
schema: variantList(
|
|
"sections",
|
|
"Sections",
|
|
{
|
|
text: {
|
|
label: "Text section",
|
|
schema: object("section", "Text section", [
|
|
text("heading", "Section heading", { maxLength: 60 }),
|
|
objectList(
|
|
"paragraphs",
|
|
"Paragraphs",
|
|
[
|
|
textarea("text", "Paragraph text", {
|
|
maxLength: 500,
|
|
rows: 4,
|
|
}),
|
|
objectList(
|
|
"links",
|
|
"Inline links",
|
|
[
|
|
text("label", "Link label", { maxLength: 50 }),
|
|
url("href", "Link URL", { maxLength: 255 }),
|
|
combobox("tabId", "Switch to policy", {
|
|
maxLength: 40,
|
|
options: policyOptions,
|
|
helpText:
|
|
"Optional. Choose another policy to open when this link is clicked.",
|
|
}),
|
|
],
|
|
{
|
|
itemLabel: "Link",
|
|
sortable: true,
|
|
emptyText: "No inline links yet.",
|
|
},
|
|
),
|
|
],
|
|
{
|
|
itemLabel: "Paragraph",
|
|
sortable: true,
|
|
emptyText: "No paragraphs yet.",
|
|
},
|
|
),
|
|
]),
|
|
},
|
|
list: {
|
|
label: "List section",
|
|
schema: object("section", "List section", [
|
|
text("heading", "Section heading", { maxLength: 60 }),
|
|
textarea("intro", "Intro text", { maxLength: 220, rows: 3 }),
|
|
stringList("items", "List items", {
|
|
itemLabel: "List item",
|
|
maxLength: 180,
|
|
fieldType: "textarea",
|
|
sortable: true,
|
|
emptyText: "No list items yet.",
|
|
}),
|
|
]),
|
|
},
|
|
cards: {
|
|
label: "Card section",
|
|
schema: object("section", "Card section", [
|
|
objectList(
|
|
"cards",
|
|
"Cards",
|
|
[
|
|
icon("icon", "Card icon"),
|
|
text("title", "Card title", { maxLength: 50 }),
|
|
textarea("description", "Card description", {
|
|
maxLength: 220,
|
|
rows: 4,
|
|
}),
|
|
object("link", "Card link", [
|
|
text("label", "Link label", { maxLength: 50 }),
|
|
url("href", "Link URL", { maxLength: 255 }),
|
|
combobox("tabId", "Switch to policy", {
|
|
maxLength: 40,
|
|
options: policyOptions,
|
|
}),
|
|
]),
|
|
],
|
|
{
|
|
itemLabel: "Card",
|
|
sortable: true,
|
|
emptyText: "No cards yet.",
|
|
},
|
|
),
|
|
]),
|
|
},
|
|
},
|
|
{
|
|
itemLabel: "Section",
|
|
sortable: true,
|
|
emptyText: "No sections yet.",
|
|
},
|
|
),
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
baseConfig,
|
|
createPoliciesSectionEditorConfig,
|
|
};
|