updates to bailout page

use tpa flag
sub header router link
This commit is contained in:
Bill Richardson 2023-08-14 14:36:11 -04:00
parent ad92c94cca
commit f05ff0ddf6
4 changed files with 124 additions and 79 deletions

View file

@ -5,28 +5,32 @@ export function fetchCmsContentForPage(issPage) {
const store = useMainStore(); const store = useMainStore();
const { clientName } = store.issConfig; const { clientName } = store.issConfig;
const { accountNumber } = store.issConfig; const { accountNumber } = store.issConfig;
const clientOverride = (clientName.length > 0 && accountNumber > 0); const clientOverride = clientName.length > 0 && accountNumber > 0;
return store.getPageData(issPage) return (
// Get the base/default page first. store
.then((baseResponse) => { .getPageData(issPage)
if (!clientOverride) { // Get the base/default page first.
// Return the base page if there are no client override. .then((baseResponse) => {
return processPageData(baseResponse, null); if (!clientOverride) {
} // Return the base page if there are no client override.
// Else get the client override page.
const pageName = `${issPage}_${clientName.toLowerCase().replace(/ /g, '')}`;
return store.getPageData(pageName)
.then((clientResponse) =>
// Process the client override if it exists.
processPageData(baseResponse, clientResponse),
(error) => {
console.error(error);
// Process the just the base if no client override exists.
return processPageData(baseResponse, null); return processPageData(baseResponse, null);
}); }
}); // Else get the client override page.
const pageName = `${issPage}_${clientName.toLowerCase().replace(/ /g, '')}`;
return store.getPageData(pageName).then(
(clientResponse) =>
// Process the client override if it exists.
processPageData(baseResponse, clientResponse),
(error) => {
console.error(error);
// Process the just the base if no client override exists.
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.
@ -44,7 +48,7 @@ function processPageData(baseResponse, clientResponse) {
if (!clientResponse?.data?.Result) { if (!clientResponse?.data?.Result) {
widgets = baseResponse.data.Result; widgets = baseResponse.data.Result;
} else { } else {
// Override any base widgets with the client override widgets if found. // Override any base widgets with the client override widgets if found.
baseResponse.data.Result.forEach((baseWidget) => { baseResponse.data.Result.forEach((baseWidget) => {
let found = false; let found = false;
clientResponse.data.Result.forEach((clientWidget) => { clientResponse.data.Result.forEach((clientWidget) => {
@ -75,9 +79,8 @@ function processPageData(baseResponse, clientResponse) {
} }
widgets.forEach((widget) => { widgets.forEach((widget) => {
// Global state value replacement. // Global state value replacement.
const widgetWithReplacements = findAndReplaceGlobalStateValues(widget.Model, const widgetWithReplacements = findAndReplaceGlobalStateValues(widget.Model, widget.Name);
widget.Name);
// If we already have this widget, push it on the collection // If we already have this widget, push it on the collection
if (widgetWithReplacements.Name in pageDataFromCms) { if (widgetWithReplacements.Name in pageDataFromCms) {
@ -85,9 +88,7 @@ function processPageData(baseResponse, clientResponse) {
return; return;
} }
pageDataFromCms[widgetWithReplacements.Name] = [ pageDataFromCms[widgetWithReplacements.Name] = [widgetWithReplacements.Model];
widgetWithReplacements.Model
];
}); });
Object.keys(pageDataFromCms).forEach((key) => { Object.keys(pageDataFromCms).forEach((key) => {
@ -108,8 +109,7 @@ function findAndReplaceGlobalStateValues(widgetModel, widgetName) {
}; };
Object.keys(widgetModel).forEach((key) => { Object.keys(widgetModel).forEach((key) => {
const modelWithReplacements = processWidgetItemForReplacement(widgetModel, const modelWithReplacements = processWidgetItemForReplacement(widgetModel, key);
key);
objWithReplacements.Model[key] = modelWithReplacements; objWithReplacements.Model[key] = modelWithReplacements;
}); });
@ -123,9 +123,11 @@ function processWidgetItemForReplacement(widgetModel, key) {
// If we have a string, and it needs to be replaced. // If we have a string, and it needs to be replaced.
if (typeof widgetModel[key] === 'string') { if (typeof widgetModel[key] === 'string') {
if (widgetModel[key].includes('{if:')) { if (widgetModel[key].includes('{if:')) {
widgetModel[key] = processIfStatements(widgetModel[key], widgetModel[key] = processIfStatements(
widgetModel[key],
dynamicStrings.GLOBAL_STATE, dynamicStrings.GLOBAL_STATE,
getStoreValueFromString); getStoreValueFromString
);
} }
if (widgetModel[key].includes(dynamicStrings.MODAL_LINK)) { if (widgetModel[key].includes(dynamicStrings.MODAL_LINK)) {
@ -141,8 +143,7 @@ function processWidgetItemForReplacement(widgetModel, key) {
} }
// If we have an object. array, etc // If we have an object. array, etc
if (typeof widgetModel[key] === 'object' if (typeof widgetModel[key] === 'object' && Object.keys(widgetModel[key]).length) {
&& Object.keys(widgetModel[key]).length) {
Object.keys(widgetModel[key]).forEach((item) => { Object.keys(widgetModel[key]).forEach((item) => {
processWidgetItemForReplacement(widgetModel[key], item); processWidgetItemForReplacement(widgetModel[key], item);
}); });
@ -159,11 +160,13 @@ function mapStringToModal(str) {
let linkToReplace = str.substring(startIndex, str.length); let linkToReplace = str.substring(startIndex, str.length);
linkToReplace = linkToReplace.substring(0, linkToReplace.indexOf('}') + 1); linkToReplace = linkToReplace.substring(0, linkToReplace.indexOf('}') + 1);
const params = linkToReplace.substring((dynamicStrings.MODAL_LINK).length + 2, linkToReplace.length - 1); const params = linkToReplace.substring(
dynamicStrings.MODAL_LINK.length + 2,
linkToReplace.length - 1
);
const splitParams = params.split(','); const splitParams = params.split(',');
const bodyText const bodyText = `<a href="#" modalTarget="${splitParams[0]}" class="modal-text" aria-label="Modal window">${splitParams[1]}</a>`;
= `<a href="#" modalTarget="${splitParams[0]}" class="modal-text" aria-label="Modal window">${splitParams[1]}</a>`;
let returnVal = str.replace(linkToReplace, bodyText); let returnVal = str.replace(linkToReplace, bodyText);
@ -178,7 +181,10 @@ function mapStringToLink(str) {
let linkToReplace = str.substring(startIndex, str.length); let linkToReplace = str.substring(startIndex, str.length);
linkToReplace = linkToReplace.substring(0, linkToReplace.indexOf('}') + 1); linkToReplace = linkToReplace.substring(0, linkToReplace.indexOf('}') + 1);
const params = linkToReplace.substring((dynamicStrings.EXTERNAL_LINK).length + 2, linkToReplace.length - 1); const params = linkToReplace.substring(
dynamicStrings.EXTERNAL_LINK.length + 2,
linkToReplace.length - 1
);
const splitParams = params.split(','); const splitParams = params.split(',');
const bodyText = `<a href="${splitParams[0]}" class="external-text" target="_blank">${splitParams[1]}</a>`; const bodyText = `<a href="${splitParams[0]}" class="external-text" target="_blank">${splitParams[1]}</a>`;
@ -196,7 +202,9 @@ function mapStringToState(str) {
// Pull all matches out of the string. // Pull all matches out of the string.
const regexExp = /{([^{}]*?):([^{}]*?)}/g; const regexExp = /{([^{}]*?):([^{}]*?)}/g;
const regexMatches = [...str.matchAll(regexExp)]; const regexMatches = [...str.matchAll(regexExp)];
const globalStateMatches = regexMatches.filter((match) => match[1] === dynamicStrings.GLOBAL_STATE); const globalStateMatches = regexMatches.filter(
(match) => match[1] === dynamicStrings.GLOBAL_STATE
);
// Our final string value that will be built from the matches. // Our final string value that will be built from the matches.
const stringBuilder = ''; const stringBuilder = '';
@ -257,14 +265,17 @@ export function processIfStatements(str, ifConditionKeyword, replacePlaceholderC
} }
const ifStatementRegexExpression = getIfStatementRegexExpression(); const ifStatementRegexExpression = getIfStatementRegexExpression();
const ifStatementRegexMatches = [...str.matchAll(ifStatementRegexExpression)]; const ifStatementRegexMatches = [...str.matchAll(ifStatementRegexExpression)];
const completeIfStatementArray = getAndFlagFirstNonNestedIfStatementWithKeyword(ifStatementRegexMatches, const completeIfStatementArray = getAndFlagFirstNonNestedIfStatementWithKeyword(
ifConditionKeyword); ifStatementRegexMatches,
executeIfStatementAndSetProcessedStrings(completeIfStatementArray, ifConditionKeyword
replacePlaceholderCallback); );
executeIfStatementAndSetProcessedStrings(completeIfStatementArray, replacePlaceholderCallback);
const reconstructedPostProcessedString = joinProcessedRegexArray(ifStatementRegexMatches); const reconstructedPostProcessedString = joinProcessedRegexArray(ifStatementRegexMatches);
return processIfStatements(reconstructedPostProcessedString, return processIfStatements(
reconstructedPostProcessedString,
ifConditionKeyword, ifConditionKeyword,
replacePlaceholderCallback); replacePlaceholderCallback
);
} }
function getAndFlagFirstNonNestedIfStatementWithKeyword(matches, ifConditionKeyword) { function getAndFlagFirstNonNestedIfStatementWithKeyword(matches, ifConditionKeyword) {
@ -357,38 +368,28 @@ function getIfStatementRegexExpression() {
// {if:...} or {else} or {end} // {if:...} or {else} or {end}
const anyLogicOperatorNonCapture = '(?:{(?:end|else|if:.*?)})'; const anyLogicOperatorNonCapture = '(?:{(?:end|else|if:.*?)})';
// NOTE: ?<variableName> syntax stores the captured match like so: match.groups.variableName // NOTE: ?<variableName> syntax stores the captured match like so: match.groups.variableName
const matchStartOfString const matchStartOfString =
= '(?<processedString>^.+?)' // Match and Capture all characters (lazy), cannot be empty '(?<processedString>^.+?)' + // Match and Capture all characters (lazy), cannot be empty
+ '(?=(?:{if))'; // Looks ahead but does not capture {if '(?=(?:{if))'; // Looks ahead but does not capture {if
const matchIfOperator const matchIfOperator =
= '(?<isIfStatement>{if:)' // Match & Capture {if: '(?<isIfStatement>{if:)' + // Match & Capture {if:
+ '(?<ifConditionType>.*?):' // Match all chars up to and including next ':' - Capture all chars up to ':' '(?<ifConditionType>.*?):' + // Match all chars up to and including next ':' - Capture all chars up to ':'
+ '(?<ifCondition>.*?)}' // Match all chars up to and including next '}' - Capture all chars up to '}' '(?<ifCondition>.*?)}' + // Match all chars up to and including next '}' - Capture all chars up to '}'
+ '(?<ifTrailingString>.*?)' // Match and Capture all characters (lazy), can be empty '(?<ifTrailingString>.*?)' + // Match and Capture all characters (lazy), can be empty
+ `(?=${ `(?=${anyLogicOperatorNonCapture})`; // Looks ahead but does not capture the next logic operator
anyLogicOperatorNonCapture const matchElseOperator =
})`; // Looks ahead but does not capture the next logic operator '(?<isElseStatement>{else})' + // Match & Capture {else}
const matchElseOperator '(?<elseTrailingString>.*?)' + // Match & Capture all characters (lazy), can be empty
= '(?<isElseStatement>{else})' // Match & Capture {else} `(?=${anyLogicOperatorNonCapture})`; // Looks ahead but does not capture the next logic operator
+ '(?<elseTrailingString>.*?)' // Match & Capture all characters (lazy), can be empty const matchEndOperator =
+ `(?=${ '(?<isEndStatement>{end})' + // Match & Capture {end}
anyLogicOperatorNonCapture '(?<endTrailingString>.*?)' + // Match & Capture all characters (lazy), can be empty
})`; // Looks ahead but does not capture the next logic operator `(?=${anyLogicOperatorNonCapture}|$)`; // Looks ahead but does not capture the next logic operator
const matchEndOperator
= '(?<isEndStatement>{end})' // Match & Capture {end}
+ '(?<endTrailingString>.*?)' // Match & Capture all characters (lazy), can be empty
+ `(?=${
anyLogicOperatorNonCapture
}|$)`; // Looks ahead but does not capture the next logic operator
// Combine all matching patterns, separated by 'or' pipes // Combine all matching patterns, separated by 'or' pipes
return new RegExp(`${matchStartOfString return new RegExp(
}|${ `${matchStartOfString}|${matchIfOperator}|${matchElseOperator}|${matchEndOperator}`,
matchIfOperator 'g'
}|${ );
matchElseOperator
}|${
matchEndOperator}`,
'g');
} }
/// /////////////////////////////////////// /// ///////////////////////////////////////
@ -446,6 +447,16 @@ export function getRouterLinkDisplayTextFromCopy(copy) {
return copy.split(':')[1].split(',')[1]; return copy.split(':')[1].split(',')[1];
} }
/**
* Returns a router link as an 'a' tag element
* @returns string
*/
export function getRouterLinkHtmlStringFromCopy(copy) {
return `<a href='/?issPage=${getRouterLinkRouteFromCopy(
copy
)}' class='router-link'>${getRouterLinkDisplayTextFromCopy(copy)}</a>`;
}
// Copy returned from the CMS that has newlines will return blocks wrapped in // Copy returned from the CMS that has newlines will return blocks wrapped in
// <p ... >...</p> // <p ... >...</p>
// This function returns an array of each paragraph, works with or without html // This function returns an array of each paragraph, works with or without html

View file

@ -0,0 +1,8 @@
/**
* Returns string with inline style tag stripped out
* @returns string
*/
export function stripRteStyle(stringWithStyleTag) {
const regexExp = /[\s*]style="(.*?)"/g;
return stringWithStyleTag.replace(regexExp, '');
}

View file

@ -24,6 +24,15 @@
<script> <script>
import buttonBack from '@/iss-components/site-sub-header/button-back/button-back'; import buttonBack from '@/iss-components/site-sub-header/button-back/button-back';
import {
doesCopyContainRouterLink,
splitCopyOnCMSPlaceHolder,
getRouterLinkRouteFromCopy,
getRouterLinkDisplayTextFromCopy,
getRouterLinkHtmlStringFromCopy
} from '@/helpers/cms-content-helper';
import { stripRteStyle } from '@/helpers/text-helper';
export default { export default {
name: 'site-sub-header', name: 'site-sub-header',
@ -44,14 +53,26 @@ export default {
return this.getCmsContent(this.cmsWidgetName, this.contentProperty ?? 'SubHeaderText'); return this.getCmsContent(this.cmsWidgetName, this.contentProperty ?? 'SubHeaderText');
}, },
subText() { subText() {
let subText = this.getCmsContent( let subTextFromCms = this.getCmsContent(
this.cmsWidgetName, this.cmsWidgetName,
this.subContentProperty ?? 'SecondaryText' this.subContentProperty ?? 'SecondaryText'
); );
if (this.stripRteStyle) { if (this.stripRteStyle) {
const regexExp = /[\s*]style="(.*?)"/g; subTextFromCms = stripRteStyle(subTextFromCms);
subText = subText.replace(regexExp, ''); }
let subText = '';
if (this.doesCopyContainRouterLink(subTextFromCms)) {
splitCopyOnCMSPlaceHolder(subTextFromCms).forEach((sc) => {
if (this.doesCopyContainRouterLink(sc)) {
subText = subText + getRouterLinkHtmlStringFromCopy(sc);
} else {
subText = subText + sc;
}
});
} else {
subText = subTextFromCms;
} }
return subText ?? ''; return subText ?? '';
@ -76,6 +97,11 @@ export default {
} }
}, },
methods: { methods: {
doesCopyContainRouterLink,
splitCopyOnCMSPlaceHolder,
getRouterLinkRouteFromCopy,
getRouterLinkDisplayTextFromCopy,
getRouterLinkHtmlStringFromCopy,
clickEvent() { clickEvent() {
this.$emit('click-event'); this.$emit('click-event');
} }

View file

@ -118,7 +118,7 @@ export default {
}, },
computed: { computed: {
isNoTpa() { isNoTpa() {
return true; // not sure what in the data flags this. return !this.mainStore.issConfig.enableTPAFlow;
} }
}, },
methods: { methods: {