Files
cms.techvanguard.vn/controllers/_renderSingletonPageView.js
T
Tống Thành Đạt 7df3a6f6bf feat(cms): refactor page content management and implement detailed editors
Refactor the CMS page content system to use a more modular configuration-driven approach. This replaces the monolithic `pageContentConfig.js` with individual configuration files for each page and introduces a shared field utility to standardize editor components.
Key changes:
- Implement a generic `_renderSingletonPageView` helper to reduce duplication across controllers.
- Enhance `_createPageContentController` with `normalizeForEditor`, `normalizeForApi`, and `preparePayload` hooks for custom data transformation.
- Create dedicated configuration and view structures for Partnerships, History, Accreditation, Admissions, and Policies pages.
- Add a specialized section editor for Policies to manage complex nested content.
- Improve the frontend `page-content-editor.js` with support for visibility logic, auto-sequencing for arrays, and URL synchronization for active tabs.
- Update data JSON files to align with the new schema.
2026-04-20 19:43:28 +07:00

32 lines
941 B
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")}`;
return res.render(view, {
layout: "layouts/main",
title: editorConfig.title,
subtitle: editorConfig.subtitle,
data,
editorConfig,
activeTab: req.query.tab || editorConfig.tabs[0].key,
frontendUrl,
backendUrl,
previewUrl: `${frontendUrl}${editorConfig.previewPath}`,
currentPath: req.path,
user: req.session.user,
});
};
}
module.exports = createRenderSingletonPageView;