From a60398a55bb7717427c0eb8e7f9e85211400c666 Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Wed, 12 Oct 2022 10:53:12 -0400 Subject: [PATCH] CSR-731 | Working version before refactor --- .../button-question/button-question.vue | 10 +- src/constants/dynamic-strings.js | 3 +- src/helpers/cms-content-helper.js | 103 +++++- .../license-plate-lookup.vue | 1 + src/layouts/quote/quote.vue | 79 +++-- .../service-package-question.vue | 56 ++- .../service-package-radio.vue | 333 +++++++++++++++--- src/mixins/base-mixin.js | 8 + src/mixins/input-button-wrapper-mixin.js | 4 +- src/store/index.js | 7 +- 10 files changed, 488 insertions(+), 116 deletions(-) diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index 92276c9d4..be8c1fb82 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -52,7 +52,8 @@ :selectOnKeypress="selectOnKeypress" @blur="handleBlur" @focus="handleFocus" - @buttonClicked="handleAnswerChange" /> + @buttonClicked="handleAnswerChange" + :additionalData="additionalData" />
^.+?)(?=(?:{if))|(?{if:)(?.*?:)(?.*?)}(?.*?)(?=(?:{(?:end|else|if:.*?)}))|(?{else})(?.*?)(?=(?:{(?:end|else|if:.*?)}))|(?{end})(?.*?)(?=(?:{(?:end|else|if:.*?)})|$)", "g"); + const regexMatches = [...str.matchAll(regexExp)]; + // Find and evaluate full globalState if statements + if (regexMatches.length) { + regexMatches.forEach((match, index) => { + if(match.groups.ifOperator) { + if(regexMatches[index+1].groups.endOperator) { + processIfStatement(regexMatches.slice(index, index+2), ifConditionString, replaceStringCallback) + regexMatches[index+1].groups.endTrailingString; + } + else if(regexMatches[index+2].groups.endOperator) { + processIfStatement(regexMatches.slice(index, index+3), ifConditionString, replaceStringCallback)+ regexMatches[index+2].groups.endTrailingString; + } + } + }); + const processedString = joinProcessedRegexArray(regexMatches); + return checkForIfStatements(processedString, ifConditionString, replaceStringCallback); + } else { + return str; + } +} + +function reconstructPageLevelIfStatements(str) { + return str.replaceAll("(((", "{").replaceAll(")))","}"); +} + +function joinProcessedRegexArray(regexMatches) { + let processedString = ""; + regexMatches.forEach((match) => { + processedString += match.groups.cleanString ?? match[0]; + }); + return processedString; +} + +function processIfStatement(ifStatementArray, ifConditionString, replaceStringCallback) { + if(ifStatementArray[0].groups.ifConditionType.includes(ifConditionString)) { + //replace the if condition with a real value + const ifCondition = replaceStringCallback(ifStatementArray[0].groups.ifCondition); + //convert the entire if statement + let processedIfStatementString; + if (ifCondition) { + processedIfStatementString = ifStatementArray[0].groups.ifTrailingString; + } else { + processedIfStatementString = ifStatementArray[1].groups.elseTrailingString ?? ""; + } + ifStatementArray.forEach((entry) => { + if (entry.groups.ifOperator) { + entry.groups.cleanString = processedIfStatementString; + } else if (entry.groups.endOperator) { + entry.groups.cleanString = entry.groups.endTrailingString; + } else { + entry.groups.cleanString = ""; + } + }) + } else { + // stow the if statement to reconstruct later when passing to the page + ifStatementArray.forEach((entry) => { + const groups = entry.groups; + if (groups.ifOperator) + groups.cleanString = "(((if:" + groups.ifConditionType + groups.ifCondition + ")))" + groups.ifTrailingString; + else if (groups.elseOperator) + groups.cleanString = "(((else)))" + groups.elseTrailingString; + else + groups.cleanString = "(((end)))" + groups.endTrailingString; + }); + } +} + +function getStoreValueFromString(str) { + let storeOrStateObject = str.includes('getters') ? store :store.state; + for (const s of str.split(".")) { + if (storeOrStateObject[s] != undefined) { + storeOrStateObject = storeOrStateObject[s]; + } else { + return ""; // if we can't map our string to state data, return an empty string. + } + } + return storeOrStateObject; +} + + + export function doesCopyContainRouterLink(copy) { return copy.includes(this.dynamicStrings.ROUTER_LINK); diff --git a/src/layouts/license-plate-lookup/license-plate-lookup.vue b/src/layouts/license-plate-lookup/license-plate-lookup.vue index 90a447258..43afbc971 100644 --- a/src/layouts/license-plate-lookup/license-plate-lookup.vue +++ b/src/layouts/license-plate-lookup/license-plate-lookup.vue @@ -64,6 +64,7 @@ - { - console.log("cmsContent", cmsContent); vm.setCmsContent(cmsContent); - vm.isInsurance = vm.getDefaultIsInsuranceValue(); + vm.isInsuranceSelected = vm.getDefaultIsInsuranceSelectedValue(); vm.selectedPackage = vm.getDefaultSelectedPackageValue(); + vm.lineItems = [ + { + PartNumber : "001", + Description : "Windshield with Recal", + PartType : "Windshield", + Quantity : "1", + BasePartNumber : "001", + Color : "Green", + CanSafeliteRecalibrate: true, + Price : 350.00 + }, + { + PartNumber : "002", + Description : "Front Wipers", + PartType : "frontWiper", + Quantity : "1", + Price : 35.00, + }, + { + PartNumber : "003", + Description : "Rear Wiper", + PartType : "rearWiper", + Quantity : "1", + Price : 25.00, + }, + { + PartNumber : "004", + Description : "Rain Defense", + PartType : "rainDefense", + Quantity : "1", + Price : 30.00, + }, + { + PartNumber : "005", + Description : "Recalibration", + PartType : "recalibration", + Quantity : "1", + Price : 150.00, + }, + ]; }); }, data(){ return { cashOrInsuranceThreshhold: 600, pricingRequestResult: null, - isInsurance: null, + isInsuranceSelected: null, selectedPackage: null, - } - }, - watch: { - selectedPackage(newPackage, oldPackage) { - console.log("new package: ", newPackage); - console.log("old package: ", oldPackage); + lineItems: null, } }, methods: { arePagePrerequisitesValid() { return store.getters.order.damage.isRepair || (store.getters.order.lineItems?.glassParts != null && store.getters.order.lineItems.glassParts.length > 0); }, - getDefaultIsInsuranceValue() { - var defaultIsInsuranceValue = this.$store.getters.order.payment.isInsurance; - if(defaultIsInsuranceValue != null) { - return defaultIsInsuranceValue; + getDefaultIsInsuranceSelectedValue() { + const defaultIsInsuranceSelectedValue = this.$store.getters.order.payment.isInsurance; + if(defaultIsInsuranceSelectedValue != null) { + return defaultIsInsuranceSelectedValue; } else { return this.economyPackagePrice > this.cashOrInsuranceThreshhold; } @@ -194,16 +228,6 @@ export default { }, }, computed: { - years() { - return ["2011", "2012"]; - }, - answersFromCms() { - return ["Pay on my own", "Pay with insurance"]; - }, - economyPackagePrice() { - //TODO build out the pricing logic CSR-504 - return 0; - }, selectedChipCountValues: { get: function() { return this.modelValue; @@ -219,7 +243,6 @@ export default { vehicleBanner, funnelSubHeader, Form, - radioServicePackage, textBlock, cashOrInsuranceQuestion, servicePackageQuestion, diff --git a/src/layouts/quote/service-package-question/service-package-question.vue b/src/layouts/quote/service-package-question/service-package-question.vue index a73bdd0e1..0e527856d 100644 --- a/src/layouts/quote/service-package-question/service-package-question.vue +++ b/src/layouts/quote/service-package-question/service-package-question.vue @@ -1,13 +1,22 @@ \ No newline at end of file + diff --git a/src/layouts/quote/service-package-question/service-package-radio/service-package-radio.vue b/src/layouts/quote/service-package-question/service-package-radio/service-package-radio.vue index 70a0a71d5..29694b09a 100644 --- a/src/layouts/quote/service-package-question/service-package-radio/service-package-radio.vue +++ b/src/layouts/quote/service-package-question/service-package-radio/service-package-radio.vue @@ -1,27 +1,50 @@ - + diff --git a/src/mixins/base-mixin.js b/src/mixins/base-mixin.js index c6c8a89b7..aaa8aff42 100644 --- a/src/mixins/base-mixin.js +++ b/src/mixins/base-mixin.js @@ -56,6 +56,14 @@ export default { isServiceable: serviceZipValidationResponse.data.isServiceable, state: serviceZipValidationResponse.data.state }; + }, + getEconomyPackagePrice(lineItems) { + const nonVapsItems = lineItems.filter((lineItem) => { + return lineItem.PartType != "frontWiper" && lineItem.PartType != "rearWiper" && lineItem.PartType != "rainDefense"; + }); + let totalPrice = 0; + nonVapsItems.forEach(item => totalPrice += item.Price); + return totalPrice; } }, computed: { diff --git a/src/mixins/input-button-wrapper-mixin.js b/src/mixins/input-button-wrapper-mixin.js index f2b34a83f..c8424504f 100644 --- a/src/mixins/input-button-wrapper-mixin.js +++ b/src/mixins/input-button-wrapper-mixin.js @@ -16,7 +16,8 @@ export default { valueToLogType: String, validationRules: String, isWide: Boolean, - isRequired: Boolean + isRequired: Boolean, + additionalData: null, }, data() { return { @@ -31,7 +32,6 @@ export default { if (this.preHandleAnswerChange) { this.preHandleAnswerChange(e) } - this.$emit("change", e); }, }, diff --git a/src/store/index.js b/src/store/index.js index 0d664c09f..e5915cc9e 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -50,7 +50,7 @@ const getDefaultState = () => { glassToReplace: null, partQuestionAnswers: null, moldingQuestionAnswers: null, - capabilityQuestionAnswers: null + capabilityQuestionAnswers: null, }, lineItems: { glassParts: null @@ -372,6 +372,10 @@ export const getters = { }, eventBus: (state) => state.applicationUser.eventBus, damage: (state) => state.order.damage, + hasAnyNonWindshieldGlassParts: (state) => { + const nonWindshieldItems = state.order.damage.glassToReplace.filter(glassToReplace => glassToReplace.glassLocation != "Windshield"); + return !!nonWindshieldItems.length; + }, lineItems: (state) => state.order.lineItems, pageData: (state) => (page) => { return state.applicationUser.pageData[page]; }, applicationUser: (state) => state.applicationUser, @@ -1133,7 +1137,6 @@ function getHasRecalibrationPart(state) { } else { // Does not have 'requiresRecalibration' return false; } - } function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) {