From f05ff0ddf616b2f6ef9b52f74843d54bb28767a1 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Mon, 14 Aug 2023 14:36:11 -0400 Subject: [PATCH] updates to bailout page use tpa flag sub header router link --- src/helpers/cms-content-helper.js | 161 ++++++++++-------- src/helpers/text-helper.js | 8 + .../site-sub-header/site-sub-header.vue | 32 +++- src/layouts/bailout-page/bailout-page.vue | 2 +- 4 files changed, 124 insertions(+), 79 deletions(-) create mode 100644 src/helpers/text-helper.js diff --git a/src/helpers/cms-content-helper.js b/src/helpers/cms-content-helper.js index 7ac4917b..96a6c375 100644 --- a/src/helpers/cms-content-helper.js +++ b/src/helpers/cms-content-helper.js @@ -5,28 +5,32 @@ export function fetchCmsContentForPage(issPage) { const store = useMainStore(); const { clientName } = store.issConfig; const { accountNumber } = store.issConfig; - const clientOverride = (clientName.length > 0 && accountNumber > 0); + const clientOverride = clientName.length > 0 && accountNumber > 0; - return store.getPageData(issPage) - // Get the base/default page first. - .then((baseResponse) => { - if (!clientOverride) { - // Return the base page if there are no client override. - 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 ( + store + .getPageData(issPage) + // Get the base/default page first. + .then((baseResponse) => { + if (!clientOverride) { + // Return the base page if there are no client override. 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. @@ -44,7 +48,7 @@ function processPageData(baseResponse, clientResponse) { if (!clientResponse?.data?.Result) { widgets = baseResponse.data.Result; } 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) => { let found = false; clientResponse.data.Result.forEach((clientWidget) => { @@ -75,9 +79,8 @@ function processPageData(baseResponse, clientResponse) { } widgets.forEach((widget) => { - // Global state value replacement. - const widgetWithReplacements = findAndReplaceGlobalStateValues(widget.Model, - widget.Name); + // Global state value replacement. + const widgetWithReplacements = findAndReplaceGlobalStateValues(widget.Model, widget.Name); // If we already have this widget, push it on the collection if (widgetWithReplacements.Name in pageDataFromCms) { @@ -85,9 +88,7 @@ function processPageData(baseResponse, clientResponse) { return; } - pageDataFromCms[widgetWithReplacements.Name] = [ - widgetWithReplacements.Model - ]; + pageDataFromCms[widgetWithReplacements.Name] = [widgetWithReplacements.Model]; }); Object.keys(pageDataFromCms).forEach((key) => { @@ -108,8 +109,7 @@ function findAndReplaceGlobalStateValues(widgetModel, widgetName) { }; Object.keys(widgetModel).forEach((key) => { - const modelWithReplacements = processWidgetItemForReplacement(widgetModel, - key); + const modelWithReplacements = processWidgetItemForReplacement(widgetModel, key); objWithReplacements.Model[key] = modelWithReplacements; }); @@ -123,9 +123,11 @@ function processWidgetItemForReplacement(widgetModel, key) { // If we have a string, and it needs to be replaced. if (typeof widgetModel[key] === 'string') { if (widgetModel[key].includes('{if:')) { - widgetModel[key] = processIfStatements(widgetModel[key], + widgetModel[key] = processIfStatements( + widgetModel[key], dynamicStrings.GLOBAL_STATE, - getStoreValueFromString); + getStoreValueFromString + ); } if (widgetModel[key].includes(dynamicStrings.MODAL_LINK)) { @@ -141,8 +143,7 @@ function processWidgetItemForReplacement(widgetModel, key) { } // If we have an object. array, etc - if (typeof widgetModel[key] === 'object' - && Object.keys(widgetModel[key]).length) { + if (typeof widgetModel[key] === 'object' && Object.keys(widgetModel[key]).length) { Object.keys(widgetModel[key]).forEach((item) => { processWidgetItemForReplacement(widgetModel[key], item); }); @@ -159,11 +160,13 @@ function mapStringToModal(str) { let linkToReplace = str.substring(startIndex, str.length); 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 bodyText - = `${splitParams[1]}`; + const bodyText = `${splitParams[1]}`; let returnVal = str.replace(linkToReplace, bodyText); @@ -178,7 +181,10 @@ function mapStringToLink(str) { let linkToReplace = str.substring(startIndex, str.length); 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 bodyText = `${splitParams[1]}`; @@ -196,7 +202,9 @@ function mapStringToState(str) { // Pull all matches out of the string. const regexExp = /{([^{}]*?):([^{}]*?)}/g; 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. const stringBuilder = ''; @@ -257,14 +265,17 @@ export function processIfStatements(str, ifConditionKeyword, replacePlaceholderC } const ifStatementRegexExpression = getIfStatementRegexExpression(); const ifStatementRegexMatches = [...str.matchAll(ifStatementRegexExpression)]; - const completeIfStatementArray = getAndFlagFirstNonNestedIfStatementWithKeyword(ifStatementRegexMatches, - ifConditionKeyword); - executeIfStatementAndSetProcessedStrings(completeIfStatementArray, - replacePlaceholderCallback); + const completeIfStatementArray = getAndFlagFirstNonNestedIfStatementWithKeyword( + ifStatementRegexMatches, + ifConditionKeyword + ); + executeIfStatementAndSetProcessedStrings(completeIfStatementArray, replacePlaceholderCallback); const reconstructedPostProcessedString = joinProcessedRegexArray(ifStatementRegexMatches); - return processIfStatements(reconstructedPostProcessedString, + return processIfStatements( + reconstructedPostProcessedString, ifConditionKeyword, - replacePlaceholderCallback); + replacePlaceholderCallback + ); } function getAndFlagFirstNonNestedIfStatementWithKeyword(matches, ifConditionKeyword) { @@ -357,38 +368,28 @@ function getIfStatementRegexExpression() { // {if:...} or {else} or {end} const anyLogicOperatorNonCapture = '(?:{(?:end|else|if:.*?)})'; // NOTE: ? syntax stores the captured match like so: match.groups.variableName - const matchStartOfString - = '(?^.+?)' // Match and Capture all characters (lazy), cannot be empty - + '(?=(?:{if))'; // Looks ahead but does not capture {if - const matchIfOperator - = '(?{if:)' // Match & Capture {if: - + '(?.*?):' // Match all chars up to and including next ':' - Capture all chars up to ':' - + '(?.*?)}' // Match all chars up to and including next '}' - Capture all chars up to '}' - + '(?.*?)' // Match and Capture all characters (lazy), can be empty - + `(?=${ - anyLogicOperatorNonCapture - })`; // Looks ahead but does not capture the next logic operator - const matchElseOperator - = '(?{else})' // Match & Capture {else} - + '(?.*?)' // Match & Capture all characters (lazy), can be empty - + `(?=${ - anyLogicOperatorNonCapture - })`; // Looks ahead but does not capture the next logic operator - const matchEndOperator - = '(?{end})' // Match & Capture {end} - + '(?.*?)' // Match & Capture all characters (lazy), can be empty - + `(?=${ - anyLogicOperatorNonCapture - }|$)`; // Looks ahead but does not capture the next logic operator + const matchStartOfString = + '(?^.+?)' + // Match and Capture all characters (lazy), cannot be empty + '(?=(?:{if))'; // Looks ahead but does not capture {if + const matchIfOperator = + '(?{if:)' + // Match & Capture {if: + '(?.*?):' + // Match all chars up to and including next ':' - Capture all chars up to ':' + '(?.*?)}' + // Match all chars up to and including next '}' - Capture all chars up to '}' + '(?.*?)' + // Match and Capture all characters (lazy), can be empty + `(?=${anyLogicOperatorNonCapture})`; // Looks ahead but does not capture the next logic operator + const matchElseOperator = + '(?{else})' + // Match & Capture {else} + '(?.*?)' + // Match & Capture all characters (lazy), can be empty + `(?=${anyLogicOperatorNonCapture})`; // Looks ahead but does not capture the next logic operator + const matchEndOperator = + '(?{end})' + // Match & Capture {end} + '(?.*?)' + // 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 - return new RegExp(`${matchStartOfString - }|${ - matchIfOperator - }|${ - matchElseOperator - }|${ - matchEndOperator}`, - 'g'); + return new RegExp( + `${matchStartOfString}|${matchIfOperator}|${matchElseOperator}|${matchEndOperator}`, + 'g' + ); } /// /////////////////////////////////////// @@ -446,6 +447,16 @@ export function getRouterLinkDisplayTextFromCopy(copy) { return copy.split(':')[1].split(',')[1]; } +/** + * Returns a router link as an 'a' tag element + * @returns string + */ +export function getRouterLinkHtmlStringFromCopy(copy) { + return `${getRouterLinkDisplayTextFromCopy(copy)}`; +} + // Copy returned from the CMS that has newlines will return blocks wrapped in //

...

// This function returns an array of each paragraph, works with or without html diff --git a/src/helpers/text-helper.js b/src/helpers/text-helper.js new file mode 100644 index 00000000..e1cd64dd --- /dev/null +++ b/src/helpers/text-helper.js @@ -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, ''); +} diff --git a/src/iss-components/site-sub-header/site-sub-header.vue b/src/iss-components/site-sub-header/site-sub-header.vue index b11144dd..39e10588 100644 --- a/src/iss-components/site-sub-header/site-sub-header.vue +++ b/src/iss-components/site-sub-header/site-sub-header.vue @@ -24,6 +24,15 @@