Base merging implementation.

This commit is contained in:
Jeremy Zimmerman 2022-12-08 14:40:39 -05:00
parent 53b2e89309
commit 88abd55ecc

View file

@ -3,31 +3,62 @@ import { useMainStore } from '@/store';
export function fetchCmsContentForPage(issPage) {
const store = useMainStore()
const clientName = store.issConfig.clientName;
const clientName = "ClientOverrideTest";//store.issConfig.clientName;
const pageName = issPage + (clientName.length == 0 ? "" : "_" + clientName);
return store.getPageData(pageName)
return store.getPageData(issPage)
.then(
// Get the client specific page if it exists.
(response) => { return processPageData(response); },
(error) => {
// If the client specific page does not exist, get the base page.
if ( clientName.length > 0 )
{
return store.getPageData(issPage)
.then((response) => {
return processPageData(response);
});
}
// Get the base/default page first.
(baseResponse) => {
store.getPageData(pageName)
.then(
// Get the client overridge if it exists.
(clientResponse) => {
return processPageData(baseResponse, clientResponse);
},
(error) => {
return processPageData(baseResponse, null);
}
);
}
);
}
};
// Support method for processing the page data from the CMS call.
function processPageData(response) {
// baseResponse = contains the widgets from the base page.
// clientResponse = contains the widgets from the client override page. (null if none)
function processPageData(baseResponse, clientResponse) {
const pageDataFromCms = {};
let widgets = [];
if ( clientResponse === null )
{
widgets = baseResponse.data.Result;
}
else
{
// Overide any base widgets with the client override widgets if found.
baseResponse.data.Result.forEach((baseWidget) => {
let found = false;
clientResponse.data.Result.forEach((clientWidget) => {
if ( clientWidget.Name == baseWidget.Name )
{
widgets.push(clientWidget);
found = true;
}
});
if ( !found )
widgets.push(baseWidget);
});
}
console.log(widgets);
response.data.Result.forEach((widget) => {
widgets.forEach((widget) => {
// Global state value replacement.
let widgetWithReplacements = findAndReplaceGlobalStateValues(
widget.Model,
widget.Name