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.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
function createRenderSingletonPageView({
|
|
model,
|
|
editorConfig,
|
|
view,
|
|
normalizeForEditor,
|
|
}) {
|
|
return async function renderSingletonPageView(req, res) {
|
|
const doc = await model.getSingle();
|
|
const rawData = doc.toObject();
|
|
const data = normalizeForEditor ? normalizeForEditor(rawData, req) : rawData;
|
|
const frontendUrl = process.env.FRONTEND_URL || "http://localhost:3000";
|
|
const backendUrl =
|
|
process.env.BACKEND_URL ?? `${req.protocol}://${req.get("host")}`;
|
|
const defaultTab = editorConfig.tabs[0]?.key;
|
|
const requestedTab = req.query.tab;
|
|
const activeTab = editorConfig.tabs.some((tab) => tab.key === requestedTab)
|
|
? requestedTab
|
|
: defaultTab;
|
|
|
|
return res.render(view, {
|
|
layout: "layouts/main",
|
|
title: editorConfig.title,
|
|
subtitle: editorConfig.subtitle,
|
|
data,
|
|
editorConfig,
|
|
activeTab,
|
|
frontendUrl,
|
|
backendUrl,
|
|
previewUrl: `${frontendUrl}${editorConfig.previewPath}`,
|
|
currentPath: req.path,
|
|
user: req.session.user,
|
|
});
|
|
};
|
|
}
|
|
|
|
module.exports = createRenderSingletonPageView;
|