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) { export function fetchCmsContentForPage(issPage) {
const store = useMainStore() const store = useMainStore()
const clientName = store.issConfig.clientName; const clientName = "ClientOverrideTest";//store.issConfig.clientName;
const pageName = issPage + (clientName.length == 0 ? "" : "_" + clientName); const pageName = issPage + (clientName.length == 0 ? "" : "_" + clientName);
return store.getPageData(pageName)
.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) return store.getPageData(issPage)
.then((response) => { .then(
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. // 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 = {}; const pageDataFromCms = {};
let widgets = [];
response.data.Result.forEach((widget) => { 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);
widgets.forEach((widget) => {
// Global state value replacement.
let widgetWithReplacements = findAndReplaceGlobalStateValues( let widgetWithReplacements = findAndReplaceGlobalStateValues(
widget.Model, widget.Model,
widget.Name widget.Name