Base merging implementation.
This commit is contained in:
parent
53b2e89309
commit
88abd55ecc
1 changed files with 47 additions and 16 deletions
|
|
@ -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)
|
return store.getPageData(issPage)
|
||||||
.then(
|
.then(
|
||||||
// Get the client specific page if it exists.
|
// Get the base/default page first.
|
||||||
(response) => { return processPageData(response); },
|
(baseResponse) => {
|
||||||
(error) => {
|
store.getPageData(pageName)
|
||||||
// If the client specific page does not exist, get the base page.
|
.then(
|
||||||
if ( clientName.length > 0 )
|
// Get the client overridge if it exists.
|
||||||
{
|
(clientResponse) => {
|
||||||
return store.getPageData(issPage)
|
return processPageData(baseResponse, clientResponse);
|
||||||
.then((response) => {
|
},
|
||||||
return processPageData(response);
|
(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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue