CSR-110: updates to other question pages for consistency

This commit is contained in:
Adam Caouette 2022-08-26 10:36:31 -04:00
parent d9f1076987
commit d288282c5e
2 changed files with 104 additions and 118 deletions

View file

@ -9,11 +9,11 @@
<alert ref="alertFewMoreQuestions" class="my-5" alertClass="alert-warning" <alert ref="alertFewMoreQuestions" class="my-5" alertClass="alert-warning"
:manualHeadline="AlertFewMoreQuestionsHeader" :manualCopy="AlertFewMoreQuestionsCopy" :manualHeadline="AlertFewMoreQuestionsHeader" :manualCopy="AlertFewMoreQuestionsCopy"
v-bind:isDismissible="false" /> v-bind:isDismissible="false" />
<div v-for="(part, i) in capabilityQuestionsData" :key="part.key"> <div v-for="(glassPart, i) in capabilityQuestionsData" :key="glassPart.key">
<questionChain ref="questionChain" :keyString="part.key" <questionChain ref="questionChain" :keyString="glassPart.key"
v-model="selectedAnswers[part.glassLocation + '-' + part.glassName]" v-model="selectedAnswers[glassPart.glassLocation + '-' + glassPart.glassName]"
:questionData="part.capabilityQuestions" :partIndex="i" :questionData="glassPart.capabilityQuestions" :glassPartIndex="i"
v-if="showThisPartQuestionChain(part, i)" v-if="showThisQuestionChain(glassPart, i)"
validationRules="questions-required" /> validationRules="questions-required" />
</div> </div>
<funnel-footer ref="funnelFooter" cmsWidgetName="FunnelFooterWidget" <funnel-footer ref="funnelFooter" cmsWidgetName="FunnelFooterWidget"
@ -73,11 +73,9 @@ export default {
}, },
data() { data() {
return { return {
selectedAnswer: [],
capabilityQuestionsData: store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS).partsOrQuestions, capabilityQuestionsData: store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS).partsOrQuestions,
selectedAnswers: {}, selectedAnswers: {},
currentQuestionChainIndex: 0, currentQuestionChainIndex: 0,
newAnswersArray: [],
foundDuplicateQuestions: [], foundDuplicateQuestions: [],
}; };
}, },
@ -102,33 +100,33 @@ export default {
this.loadInitialCapabilityQuestionsData(); this.loadInitialCapabilityQuestionsData();
}, },
methods: { methods: {
showThisPartQuestionChain(part, i) { showThisQuestionChain(glassPart, i) {
if (part.capabilityQuestions?.length < 1 || part.isSuppressedPart) { return false; } // return false if no capabilityQuestions or if suppressed if (glassPart.capabilityQuestions?.length < 1 || glassPart.isSuppressedPart) { return false; } // return false if no capabilityQuestions or if suppressed
return this.currentQuestionChainIndex === i || part.answerData?.answerResult?.length > 0 return this.currentQuestionChainIndex === i || glassPart.answerData?.answerResult?.length > 0;
}, },
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
const capabilityQuestionsPageData = store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS); const capabilityQuestionsPageData = store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS);
return capabilityQuestionsPageData && Object.keys(capabilityQuestionsPageData).length > 0; return capabilityQuestionsPageData && Object.keys(capabilityQuestionsPageData).length > 0;
}, },
async forwardButtonAction() { async forwardButtonAction() {
const capabilityQuestionsAnswersArray = this.capabilityQuestionsData.map((item) => { const capabilityQuestionsAnswersArray = this.capabilityQuestionsData.map((glassPart) => {
const selectedAnswerResult1 = item.answerData.answerResult; const selectedAnswerResult1 = glassPart.answerData.answerResult;
const selectedAnswerResult2 = item.answerData.answerResult2; const selectedAnswerResult2 = glassPart.answerData.answerResult2;
return { return {
glassLocation: item.glassLocation, glassLocation: glassPart.glassLocation,
glassName: item.glassName, glassName: glassPart.glassName,
result: item.answerData.answerResult, result: glassPart.answerData.answerResult,
result1: selectedAnswerResult1, result1: selectedAnswerResult1,
result2: selectedAnswerResult2, result2: selectedAnswerResult2,
answeredQuestions: item.answerData.answeredQuestions, answeredQuestions: glassPart.answerData.answeredQuestions,
isSuppressedPart: item.isSuppressedPart, isSuppressedPart: glassPart.isSuppressedPart,
}; };
}); });
// clear out answerData for future page loads; must occur prior to store save // clear out answerData for future page loads; must occur prior to store save
this.capabilityQuestionsData.forEach((part) => { this.capabilityQuestionsData.forEach((glassPart) => {
part.answerData = {}; glassPart.answerData = {};
}); });
// save to vuex store as order.damage.capabilityQuestionAnswers (array) // save to vuex store as order.damage.capabilityQuestionAnswers (array)
@ -160,16 +158,9 @@ export default {
"questionText": "Is your Grand Cherokee the Laredo model?", "questionText": "Is your Grand Cherokee the Laredo model?",
"selectedAnswerText": "Yes", "selectedAnswerText": "Yes",
"questionNum": 1, "questionNum": 1,
"extra": {
"Text": "Yes",
"nextQuestionSequence": null,
"answerResult": "DD11132",
"questionSequence": 1,
"questionType": "answer"
}
} }
], ],
"partIndex": 0 "glassPartIndex": 0
} }
*/ */
@ -195,7 +186,7 @@ export default {
this.capabilityQuestionsData.forEach((glassPart, gpIndex) => { this.capabilityQuestionsData.forEach((glassPart, gpIndex) => {
// only look for duplicates forward... to parts that follow after the currently being answered part // only look for duplicates forward... to parts that follow after the currently being answered part
if (gpIndex > answer.partIndex) { if (gpIndex > answer.glassPart) {
let suppressUntil; let suppressUntil;
// reset this glass part, in case user is changing their previous answers // reset this glass part, in case user is changing their previous answers
@ -346,10 +337,10 @@ export default {
// "glassPart2": [7, 10] // "glassPart2": [7, 10]
// }; // };
const thisPartsDupes = this.foundDuplicateQuestions["glassPart" + answer.partIndex]; const thisPartsDupes = this.foundDuplicateQuestions["glassPart" + answer.glassPartIndex];
const completeAnsweredQuestions = answer.answeredQuestions ? [...answer.answeredQuestions] : []; const completeAnsweredQuestions = answer.answeredQuestions ? [...answer.answeredQuestions] : [];
const glassPartAnswered = this.capabilityQuestionsData[answer.partIndex]; const glassPartAnswered = this.capabilityQuestionsData[answer.glassPartIndex];
debugger; // eslint-disable-line no-debugger
thisPartsDupes?.forEach((dupe) => { thisPartsDupes?.forEach((dupe) => {
// dupe is a single integer // dupe is a single integer
const dupeQuestion = glassPartAnswered.capabilityQuestions[dupe - 1]; const dupeQuestion = glassPartAnswered.capabilityQuestions[dupe - 1];
@ -404,7 +395,7 @@ export default {
} }
// this part has been fully answered, so advance to next part's question chain // this part has been fully answered, so advance to next part's question chain
for (let i = answer.partIndex + 1; i < this.capabilityQuestionsData.length; i++) { for (let i = answer.glassPartIndex + 1; i < this.capabilityQuestionsData.length; i++) {
// if this part has not yet been fully answered, then make it the current part // if this part has not yet been fully answered, then make it the current part
if (!this.capabilityQuestionsData[i].answerData?.answerResult) { if (!this.capabilityQuestionsData[i].answerData?.answerResult) {
this.currentQuestionChainIndex = i; this.currentQuestionChainIndex = i;
@ -425,11 +416,11 @@ export default {
// are there alreadyAnsweredQuestions? // are there alreadyAnsweredQuestions?
const alreadyAnsweredQuestions = store.getters.damage.capabilityQuestionAnswers; const alreadyAnsweredQuestions = store.getters.damage.capabilityQuestionAnswers;
this.capabilityQuestionsData = this.pageData.partsOrQuestions.filter(x => x.capabilityQuestions).map((part, i) => { this.capabilityQuestionsData = this.pageData.partsOrQuestions.filter(x => x.capabilityQuestions).map((glassPart, i) => {
part.key = part.glassLocation + "-" + part.glassName; glassPart.key = glassPart.glassLocation + "-" + glassPart.glassName;
this.selectedAnswers[part.key] = []; this.selectedAnswers[glassPart.key] = [];
if (!alreadyAnsweredQuestions) { if (!alreadyAnsweredQuestions) {
part.answerData = null; glassPart.answerData = null;
} }
alreadyAnsweredQuestions?.forEach((savedPart) => { alreadyAnsweredQuestions?.forEach((savedPart) => {
@ -437,7 +428,7 @@ export default {
if (!savedPart.glassLocation || !savedPart.glassName || !savedPart.answeredQuestions || !savedPart.result) { if (!savedPart.glassLocation || !savedPart.glassName || !savedPart.answeredQuestions || !savedPart.result) {
return; return;
} }
if (part.glassLocation === savedPart.glassLocation && part.glassName === savedPart.glassName) { if (glassPart.glassLocation === savedPart.glassLocation && glassPart.glassName === savedPart.glassName) {
let answerString = ""; let answerString = "";
// matches; loop through answeredQuestions for matches // matches; loop through answeredQuestions for matches
@ -446,7 +437,7 @@ export default {
return; return;
} }
// determine which answer was previously chosen // determine which answer was previously chosen
const theAns = part.capabilityQuestions[aq.questionNum - 1].answers.find((a) => { const theAns = glassPart.capabilityQuestions[aq.questionNum - 1].answers.find((a) => {
return a.answerText.toUpperCase() === aq.selectedAnswerText.toUpperCase(); return a.answerText.toUpperCase() === aq.selectedAnswerText.toUpperCase();
}); });
if (theAns.nextQuestionSequence) { if (theAns.nextQuestionSequence) {
@ -456,18 +447,18 @@ export default {
} }
// mark this partQuestion as answered (question-chain will read this) // mark this partQuestion as answered (question-chain will read this)
part.capabilityQuestions[aq.questionNum - 1].answerSelected = answerString; glassPart.capabilityQuestions[aq.questionNum - 1].answerSelected = answerString;
// mark this partQuestion as duplicate if it is (question-chain will read this) // mark this partQuestion as duplicate if it is (question-chain will read this)
if (aq.suppressQuestion) { if (aq.suppressQuestion) {
part.capabilityQuestions[aq.questionNum - 1].suppressQuestion = true; glassPart.capabilityQuestions[aq.questionNum - 1].suppressQuestion = true;
} }
}); });
// advance the currentQuestionChainIndex // advance the currentQuestionChainIndex
this.currentQuestionChainIndex = i; this.currentQuestionChainIndex = i;
// add answerData to current part // add answerData to current glassPart
part.answerData = { glassPart.answerData = {
answerResult: savedPart.result, answerResult: savedPart.result,
answerResult1: savedPart.result, answerResult1: savedPart.result,
answerResult2: this.getCorrespondingAnswerResult2(savedPart.result), answerResult2: this.getCorrespondingAnswerResult2(savedPart.result),
@ -477,14 +468,14 @@ export default {
}); });
// Set up watch for each set of part questions, which gets updated when all questions for a part have been answered // Set up watch for each set of glassPart questions, which gets updated when all questions for a glassPart have been answered
this.$watch("selectedAnswers." + part.key, (newValue) => { this.$watch("selectedAnswers." + glassPart.key, (newValue) => {
if (newValue) { if (newValue) {
this.handleAnswerUpdates(newValue); this.handleAnswerUpdates(newValue);
} }
}, { deep: true }) }, { deep: true })
return part; return glassPart;
}); });
}, },

View file

@ -20,14 +20,14 @@
:manualCopy="AlertFewMoreQuestionsCopy" :manualCopy="AlertFewMoreQuestionsCopy"
v-bind:isDismissible="false" v-bind:isDismissible="false"
/> />
<div v-for="(part, i) in partsQuestionsData" :key="part.key"> <div v-for="(glassPart, i) in partsQuestionsData" :key="glassPart.key">
<questionChain <questionChain
ref="questionChain" ref="questionChain"
:keyString="part.key" :keyString="glassPart.key"
v-model="selectedAnswers[part.glassLocation + '-' + part.glassName]" v-model="selectedAnswers[glassPart.glassLocation + '-' + glassPart.glassName]"
:questionData="part.partQuestions" :questionData="glassPart.questions"
:partIndex="i" :glassPartIndex="i"
v-if="showThisPartQuestionChain(part, i)" v-if="showThisQuestionChain(glassPart, i)"
validationRules="questions-required" validationRules="questions-required"
/> />
</div> </div>
@ -91,13 +91,9 @@ export default {
}, },
data() { data() {
return { return {
partsQuestionsFromApi: this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS)?.partsOrQuestions.filter((p) => { partsQuestionsData: store.getters.pageData(fmgPageValues.PART_QUESTIONS).partsOrQuestions,
return Array.isArray(p.partQuestions) && p.partQuestions.length > 0;
}),
selectedAnswers: {}, selectedAnswers: {},
currentPartNum: 0, currentPartNum: 0,
newAnswersArray: [],
partsQuestionsData: [],
foundDuplicateQuestions: [], foundDuplicateQuestions: [],
}; };
}, },
@ -108,35 +104,41 @@ export default {
AlertFewMoreQuestionsCopy() { AlertFewMoreQuestionsCopy() {
return this.getCmsContent("AlertPartsQuestions", "BodyText"); return this.getCmsContent("AlertPartsQuestions", "BodyText");
}, },
pageData() {
return this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS);
}
}, },
mixins: [vehicleQuestionsMixin], mixins: [vehicleQuestionsMixin],
mounted() { mounted() {
this.LoadInitialPartsData(); this.LoadInitialData();
}, },
methods: { methods: {
showThisPartQuestionChain(part, i) { arePagePrerequisitesValid() {
if (part.partQuestions?.length < 1 || part.isSuppressedPart) { return false; } // return false if no partQuestions or if suppressed const partQuestionsFromPageData = store.getters.pageData(fmgPageValues.PART_QUESTIONS);
if (this.currentPartNum === i || part.answerData?.answerResult?.length > 0) { return true; } return partQuestionsFromPageData && Object.keys(partQuestionsFromPageData).length > 0;
return false; },
showThisQuestionChain(glassPart, i) {
if (glassPart.questions?.length < 1 || glassPart.isSuppressedPart) { return false; } // return false if no questions or if suppressed
return this.currentPartNum === i || glassPart.answerData?.answerResult?.length > 0;
}, },
async forwardButtonAction() { async forwardButtonAction() {
const partQuestionAnswersArray = this.partsQuestionsData.map((item) => { const questionAnswersArray = this.partsQuestionsData.map((glassPart) => {
return { return {
glassLocation: item.glassLocation, glassLocation: glassPart.glassLocation,
glassName: item.glassName, glassName: glassPart.glassName,
result: item.answerData.answerResult, result: glassPart.answerData.answerResult,
answeredQuestions: item.answerData.answeredQuestions, answeredQuestions: glassPart.answerData.answeredQuestions,
isSuppressedPart: item.isSuppressedPart, isSuppressedPart: glassPart.isSuppressedPart,
}; };
}); });
// clear out answerData for future page loads; must occur prior to store save // clear out answerData for future page loads; must occur prior to store save
this.partsQuestionsData.forEach((part) => { this.partsQuestionsData.forEach((glassPart) => {
part.answerData = {}; glassPart.answerData = {};
}); });
// save to vuex store as order.damage.partQuestionAnswers (array) // save to vuex store as order.damage.partQuestionAnswers (array)
await this.dispatchStoreAction(this.storeActions.SAVE_PART_QUESTION_ANSWERS, partQuestionAnswersArray, false); await this.dispatchStoreAction(this.storeActions.SAVE_PART_QUESTION_ANSWERS, questionAnswersArray, false);
// call API parts method // call API parts method
const partsLookup = await this.dispatchStoreAction(storeActions.GET_PARTS) const partsLookup = await this.dispatchStoreAction(storeActions.GET_PARTS)
@ -145,12 +147,9 @@ export default {
}); });
const glassNameAndPartsForStore = partsLookup.data.glassNameAndParts; const glassNameAndPartsForStore = partsLookup.data.glassNameAndParts;
this.navigateForward(glassNameAndPartsForStore); this.navigateForward(glassNameAndPartsForStore);
}, },
arePagePrerequisitesValid() {
const partQuestionsFromPageData = store.getters.pageData(fmgPageValues.PART_QUESTIONS);
return partQuestionsFromPageData && Object.keys(partQuestionsFromPageData).length > 0;
},
handleAnswerUpdates(key, answer) { handleAnswerUpdates(key, answer) {
// only runs when all questions in a question-chain have been answered // only runs when all questions in a question-chain have been answered
// when selectedAnswers updates, user has completed this part's question chain and has a final answer // when selectedAnswers updates, user has completed this part's question chain and has a final answer
@ -166,16 +165,9 @@ export default {
"questionText": "Is your Grand Cherokee the Laredo model?", "questionText": "Is your Grand Cherokee the Laredo model?",
"selectedAnswerText": "Yes", "selectedAnswerText": "Yes",
"questionNum": 1, "questionNum": 1,
"extra": {
"Text": "Yes",
"nextQuestionSequence": null,
"answerResult": "DD11132",
"questionSequence": 1,
"questionType": "answer"
}
} }
], ],
"partIndex": 0 "glassPartIndex": 0
} }
*/ */
@ -201,15 +193,15 @@ export default {
this.partsQuestionsData.forEach((glassPart, gpIndex) => { this.partsQuestionsData.forEach((glassPart, gpIndex) => {
// only look for duplicates forward... to parts that follow after the currently being answered part // only look for duplicates forward... to parts that follow after the currently being answered part
if (gpIndex > answer.partIndex) { if (gpIndex > answer.glassPartIndex) {
let suppressUntil; let suppressUntil;
// reset this glass part, in case user is changing their previous answers // reset this glass part, in case user is changing their previous answers
glassPart.answerData = null; glassPart.answerData = null;
glassPart.isSuppressedPart = null; glassPart.isSuppressedPart = null;
// loop through this glass part's part questions, looking for a questionText match // loop through this glass part's questions, looking for a questionText match
glassPart.partQuestions.forEach((pq, pqIndex) => { glassPart.questions.forEach((pq, pqIndex) => {
// clear out any previously set answers // clear out any previously set answers
pq.answerSelected = null; pq.answerSelected = null;
@ -229,11 +221,11 @@ export default {
// if these match then we have a duplicate question // if these match then we have a duplicate question
if (pq.questionText.toUpperCase() === answeredQuestionText) { if (pq.questionText.toUpperCase() === answeredQuestionText) {
const thisAnsweredPartQuestion = glassPart.partQuestions[pqIndex]; const thisAnsweredQuestion = glassPart.questions[pqIndex];
let matchedAnswer; let matchedAnswer;
let rejectedAnswers = []; // set as an array, in case we ever have questions with more than 2 answers... let rejectedAnswers = []; // set as an array, in case we ever have questions with more than 2 answers...
// which one of this partQuestions' answers matches our answer? // which one of this questions' answers matches our answer?
pq.answers.forEach((ans) => { pq.answers.forEach((ans) => {
if (ans.answerText.toUpperCase() === answeredQuestionAnswer) { if (ans.answerText.toUpperCase() === answeredQuestionAnswer) {
matchedAnswer = ans; matchedAnswer = ans;
@ -251,7 +243,7 @@ export default {
if (matchedAnswer.nextQuestionSequence) { if (matchedAnswer.nextQuestionSequence) {
// ensure that the question that the accepted answer has set to be next is NOT suppressed // ensure that the question that the accepted answer has set to be next is NOT suppressed
glassPart.partQuestions[matchedAnswer.nextQuestionSequence - 1].suppressQuestion = null; glassPart.questions[matchedAnswer.nextQuestionSequence - 1].suppressQuestion = null;
// if the duplicate is the 1ST question, then set suppressUntil var to lowest nextQuestion number // if the duplicate is the 1ST question, then set suppressUntil var to lowest nextQuestion number
if (pqIndex === 0) { if (pqIndex === 0) {
if (!suppressUntil) { suppressUntil = matchedAnswer.nextQuestionSequence } if (!suppressUntil) { suppressUntil = matchedAnswer.nextQuestionSequence }
@ -260,7 +252,7 @@ export default {
} }
// handle suppressing upstream in this question chain // handle suppressing upstream in this question chain
glassPart.partQuestions.forEach((q) => { glassPart.questions.forEach((q) => {
q.answers.forEach((thisAns) => { q.answers.forEach((thisAns) => {
// restore any of the answers that formerly led to the duplicated question // restore any of the answers that formerly led to the duplicated question
if (thisAns.originalNextQuestionSequence === pq.questionSequence) { if (thisAns.originalNextQuestionSequence === pq.questionSequence) {
@ -290,19 +282,19 @@ export default {
}); });
// suppress current question // suppress current question
thisAnsweredPartQuestion.suppressQuestion = true; thisAnsweredQuestion.suppressQuestion = true;
const thisGlassPart = "glassPart" + gpIndex; const thisGlassPart = "glassPart" + gpIndex;
if (this.foundDuplicateQuestions[thisGlassPart]) { if (this.foundDuplicateQuestions[thisGlassPart]) {
if (!this.foundDuplicateQuestions[thisGlassPart].includes(thisAnsweredPartQuestion.questionSequence)) { if (!this.foundDuplicateQuestions[thisGlassPart].includes(thisAnsweredQuestion.questionSequence)) {
this.foundDuplicateQuestions[thisGlassPart].push(thisAnsweredPartQuestion.questionSequence); this.foundDuplicateQuestions[thisGlassPart].push(thisAnsweredQuestion.questionSequence);
} }
} else { } else {
this.foundDuplicateQuestions[thisGlassPart] = [thisAnsweredPartQuestion.questionSequence]; this.foundDuplicateQuestions[thisGlassPart] = [thisAnsweredQuestion.questionSequence];
} }
// are there any questions left that are not suppressed? // are there any questions left that are not suppressed?
const remainingQuestions = glassPart.partQuestions.filter((q) => { const remainingQuestions = glassPart.questions.filter((q) => {
return !q.suppressQuestion; return !q.suppressQuestion;
}); });
@ -351,16 +343,16 @@ export default {
// "glassPart2": [7, 10] // "glassPart2": [7, 10]
// }; // };
const thisPartsDupes = this.foundDuplicateQuestions["glassPart" + answer.partIndex]; const thisPartsDupes = this.foundDuplicateQuestions["glassPart" + answer.glassPartIndex];
const completeAnsweredQuestions = answer.answeredQuestions ? [...answer.answeredQuestions] : []; const completeAnsweredQuestions = answer.answeredQuestions ? [...answer.answeredQuestions] : [];
const glassPartAnswered = this.partsQuestionsData[answer.partIndex]; const glassPartAnswered = this.partsQuestionsData[answer.glassPartIndex];
thisPartsDupes?.forEach((dupe) => { thisPartsDupes?.forEach((dupe) => {
// dupe is a single integer // dupe is a single integer
const dupeQuestion = glassPartAnswered.partQuestions[dupe - 1]; const dupeQuestion = glassPartAnswered.questions[dupe - 1];
const dupeQuestionAnswer = dupeQuestion.answers.find((q) => q.selected === true); const dupeQuestionAnswer = dupeQuestion.answers.find((q) => q.selected === true);
glassPartAnswered.partQuestions.forEach((q) => { glassPartAnswered.questions.forEach((q) => {
let includeThisDupeInAnsweredQuestions = false; let includeThisDupeInAnsweredQuestions = false;
// did one of the answers of this question point to the duplicated question? // did one of the answers of this question point to the duplicated question?
@ -404,7 +396,7 @@ export default {
} }
// this part has been fully answered, so advance to next part's question chain // this part has been fully answered, so advance to next part's question chain
for (let i = answer.partIndex + 1; i < this.partsQuestionsData.length; i++) { for (let i = answer.glassPartIndex + 1; i < this.partsQuestionsData.length; i++) {
// if this part has not yet been fully answered, then make it the current part // if this part has not yet been fully answered, then make it the current part
if (!this.partsQuestionsData[i].answerData?.answerResult) { if (!this.partsQuestionsData[i].answerData?.answerResult) {
this.currentPartNum = i; this.currentPartNum = i;
@ -413,16 +405,19 @@ export default {
} }
}, },
LoadInitialPartsData() { LoadInitialData() {
// are there alreadyAnsweredQuestions? // are there alreadyAnsweredQuestions?
const alreadyAnsweredQuestions = store.getters.damage.partQuestionAnswers; const alreadyAnsweredQuestions = store.getters.damage.partQuestionAnswers;
this.partsQuestionsData = this.partsQuestionsFromApi.map((part, i) => { this.partsQuestionsData = this.pageData.partsOrQuestions.filter(x => x.partQuestions).map((glassPart, i) => {
part.key = part.glassLocation + "-" + part.glassName; glassPart.key = glassPart.glassLocation + "-" + glassPart.glassName;
this.selectedAnswers[part.key] = []; // NOTE: property "questions" can differ between layouts
glassPart.questions = glassPart.partQuestions;
this.selectedAnswers[glassPart.key] = [];
if (!alreadyAnsweredQuestions) { if (!alreadyAnsweredQuestions) {
part.answerData = null; glassPart.answerData = null;
} }
alreadyAnsweredQuestions?.forEach((savedPart) => { alreadyAnsweredQuestions?.forEach((savedPart) => {
@ -430,7 +425,7 @@ export default {
if (!savedPart.glassLocation || !savedPart.glassName || !savedPart.answeredQuestions || !savedPart.result) { if (!savedPart.glassLocation || !savedPart.glassName || !savedPart.answeredQuestions || !savedPart.result) {
return; return;
} }
if (part.glassLocation === savedPart.glassLocation && part.glassName === savedPart.glassName) { if (glassPart.glassLocation === savedPart.glassLocation && glassPart.glassName === savedPart.glassName) {
let answerString = ""; let answerString = "";
// matches; loop through answeredQuestions for matches // matches; loop through answeredQuestions for matches
@ -439,7 +434,7 @@ export default {
return; return;
} }
// determine which answer was previously chosen // determine which answer was previously chosen
const theAns = part.partQuestions[aq.questionNum-1].answers.find((a) => { const theAns = glassPart.questions[aq.questionNum-1].answers.find((a) => {
return a.answerText.toUpperCase() === aq.selectedAnswerText.toUpperCase(); return a.answerText.toUpperCase() === aq.selectedAnswerText.toUpperCase();
}); });
if (theAns.nextQuestionSequence) { if (theAns.nextQuestionSequence) {
@ -448,19 +443,19 @@ export default {
answerString = `${aq.questionNum}|answer|${theAns.answerResult}|${theAns.answerText}` answerString = `${aq.questionNum}|answer|${theAns.answerResult}|${theAns.answerText}`
} }
// mark this partQuestion as answered (question-chain will read this) // mark this question as answered (question-chain will read this)
part.partQuestions[aq.questionNum-1].answerSelected = answerString; glassPart.questions[aq.questionNum-1].answerSelected = answerString;
// mark this partQuestion as duplicate if it is (question-chain will read this) // mark this question as duplicate if it is (question-chain will read this)
if (aq.suppressQuestion) { if (aq.suppressQuestion) {
part.partQuestions[aq.questionNum-1].suppressQuestion = true; glassPart.questions[aq.questionNum-1].suppressQuestion = true;
} }
}); });
// advance the currentPartNum // advance the currentPartNum
this.currentPartNum = i; this.currentPartNum = i;
// add answerData to current part // add answerData to current glassPart
part.answerData = { glassPart.answerData = {
answerResult: savedPart.result, answerResult: savedPart.result,
answeredQuestions: savedPart.answeredQuestions answeredQuestions: savedPart.answeredQuestions
} }
@ -468,14 +463,14 @@ export default {
}); });
// Set up watch for each set of part questions, which gets updated when all questions for a part have been answered // Set up watch for each set of glassPart questions, which gets updated when all questions for a glassPart have been answered
this.$watch("selectedAnswers." + part.key, (newValue) => { this.$watch("selectedAnswers." + glassPart.key, (newValue) => {
if (newValue) { if (newValue) {
this.handleAnswerUpdates(part.key, newValue); this.handleAnswerUpdates(glassPart.key, newValue);
} }
}, {deep: true}) }, {deep: true})
return part; return glassPart;
}); });
}, },