CSR-110: revise 'glassPart' to just 'glass' for clarity on questions pages

This commit is contained in:
Adam Caouette 2022-08-26 11:21:03 -04:00
parent d288282c5e
commit 6e7a791e99
4 changed files with 151 additions and 151 deletions

View file

@ -33,7 +33,7 @@ export default {
questionData: Object, questionData: Object,
validationRules: String, validationRules: String,
modelValue: Array, modelValue: Array,
glassPartIndex: Number, glassIndex: Number,
keyString: String, keyString: String,
}, },
async created() { async created() {
@ -154,7 +154,7 @@ export default {
return { return {
answerResult: questionAnswer, answerResult: questionAnswer,
answeredQuestions: answeredQuestions, answeredQuestions: answeredQuestions,
glassPartIndex: this.glassPartIndex, glassIndex: this.glassIndex,
}; };
} }

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="(glassPart, i) in capabilityQuestionsData" :key="glassPart.key"> <div v-for="(glass, i) in capabilityQuestionsData" :key="glass.key">
<questionChain ref="questionChain" :keyString="glassPart.key" <questionChain ref="questionChain" :keyString="glass.key"
v-model="selectedAnswers[glassPart.glassLocation + '-' + glassPart.glassName]" v-model="selectedAnswers[glass.glassLocation + '-' + glass.glassName]"
:questionData="glassPart.capabilityQuestions" :glassPartIndex="i" :questionData="glass.capabilityQuestions" :glassIndex="i"
v-if="showThisQuestionChain(glassPart, i)" v-if="showThisQuestionChain(glass, i)"
validationRules="questions-required" /> validationRules="questions-required" />
</div> </div>
<funnel-footer ref="funnelFooter" cmsWidgetName="FunnelFooterWidget" <funnel-footer ref="funnelFooter" cmsWidgetName="FunnelFooterWidget"
@ -100,33 +100,33 @@ export default {
this.loadInitialCapabilityQuestionsData(); this.loadInitialCapabilityQuestionsData();
}, },
methods: { methods: {
showThisQuestionChain(glassPart, i) { showThisQuestionChain(glass, i) {
if (glassPart.capabilityQuestions?.length < 1 || glassPart.isSuppressedPart) { return false; } // return false if no capabilityQuestions or if suppressed if (!glass.capabilityQuestions || glass.capabilityQuestions?.length < 1 || glass.isSuppressedPart) { return false; } // return false if no capabilityQuestions or if suppressed
return this.currentQuestionChainIndex === i || glassPart.answerData?.answerResult?.length > 0; return this.currentQuestionChainIndex === i || glass.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((glassPart) => { const capabilityQuestionsAnswersArray = this.capabilityQuestionsData.map((glass) => {
const selectedAnswerResult1 = glassPart.answerData.answerResult; const selectedAnswerResult1 = glass.answerData.answerResult;
const selectedAnswerResult2 = glassPart.answerData.answerResult2; const selectedAnswerResult2 = glass.answerData.answerResult2;
return { return {
glassLocation: glassPart.glassLocation, glassLocation: glass.glassLocation,
glassName: glassPart.glassName, glassName: glass.glassName,
result: glassPart.answerData.answerResult, result: glass.answerData.answerResult,
result1: selectedAnswerResult1, result1: selectedAnswerResult1,
result2: selectedAnswerResult2, result2: selectedAnswerResult2,
answeredQuestions: glassPart.answerData.answeredQuestions, answeredQuestions: glass.answerData.answeredQuestions,
isSuppressedPart: glassPart.isSuppressedPart, isSuppressedPart: glass.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((glassPart) => { this.capabilityQuestionsData.forEach((glass) => {
glassPart.answerData = {}; glass.answerData = {};
}); });
// save to vuex store as order.damage.capabilityQuestionAnswers (array) // save to vuex store as order.damage.capabilityQuestionAnswers (array)
@ -160,7 +160,7 @@ export default {
"questionNum": 1, "questionNum": 1,
} }
], ],
"glassPartIndex": 0 "glassIndex": 0
} }
*/ */
@ -183,18 +183,18 @@ export default {
// HANDLE DUPLICATE QUESTIONS // HANDLE DUPLICATE QUESTIONS
// loop through all glass parts data // loop through all glass parts data
this.capabilityQuestionsData.forEach((glassPart, gpIndex) => { this.capabilityQuestionsData.forEach((glass, 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.glassPart) { if (gpIndex > answer.glass) {
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; glass.answerData = null;
glassPart.isSuppressedPart = null; glass.isSuppressedPart = null;
// loop through this glass part's part questions, looking for a questionText match // loop through this glass part's part questions, looking for a questionText match
glassPart.capabilityQuestions.forEach((pq, pqIndex) => { glass.capabilityQuestions.forEach((pq, pqIndex) => {
// clear out any previously set answers // clear out any previously set answers
pq.answerSelected = null; pq.answerSelected = null;
@ -214,7 +214,7 @@ 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 thisAnsweredCapabilityQuestion = glassPart.capabilityQuestions[pqIndex]; const thisAnsweredCapabilityQuestion = glass.capabilityQuestions[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...
@ -236,7 +236,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.capabilityQuestions[matchedAnswer.nextQuestionSequence - 1].suppressQuestion = null; glass.capabilityQuestions[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 }
@ -245,7 +245,7 @@ export default {
} }
// handle suppressing upstream in this question chain // handle suppressing upstream in this question chain
glassPart.capabilityQuestions.forEach((q) => { glass.capabilityQuestions.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) {
@ -279,7 +279,7 @@ export default {
// suppress current question // suppress current question
thisAnsweredCapabilityQuestion.suppressQuestion = true; thisAnsweredCapabilityQuestion.suppressQuestion = true;
const thisGlassPart = "glassPart" + gpIndex; const thisGlassPart = "glass" + gpIndex;
if (this.foundDuplicateQuestions[thisGlassPart]) { if (this.foundDuplicateQuestions[thisGlassPart]) {
if (!this.foundDuplicateQuestions[thisGlassPart].includes(thisAnsweredCapabilityQuestion.questionSequence)) { if (!this.foundDuplicateQuestions[thisGlassPart].includes(thisAnsweredCapabilityQuestion.questionSequence)) {
this.foundDuplicateQuestions[thisGlassPart].push(thisAnsweredCapabilityQuestion.questionSequence); this.foundDuplicateQuestions[thisGlassPart].push(thisAnsweredCapabilityQuestion.questionSequence);
@ -289,7 +289,7 @@ export default {
} }
// are there any questions left that are not suppressed? // are there any questions left that are not suppressed?
const remainingQuestions = glassPart.capabilityQuestions.filter((q) => { const remainingQuestions = glass.capabilityQuestions.filter((q) => {
return !q.suppressQuestion; return !q.suppressQuestion;
}); });
@ -304,14 +304,14 @@ export default {
suppressQuestion: pq.suppressQuestion, suppressQuestion: pq.suppressQuestion,
}; };
// set the answerData as 'already answered' // set the answerData as 'already answered'
glassPart.answerData = { glass.answerData = {
answerResult: matchedAnswer.nextQuestionSequence ? matchedAnswer.nextQuestionSequence : matchedAnswer.answerResult, answerResult: matchedAnswer.nextQuestionSequence ? matchedAnswer.nextQuestionSequence : matchedAnswer.answerResult,
answerResult1: matchedAnswer.nextQuestionSequence ? matchedAnswer.nextQuestionSequence : matchedAnswer.answerResult, answerResult1: matchedAnswer.nextQuestionSequence ? matchedAnswer.nextQuestionSequence : matchedAnswer.answerResult,
answeredQuestions: [answeredQuestionObj], answeredQuestions: [answeredQuestionObj],
}; };
// suppress this glassPart because it has an answer // suppress this glass because it has an answer
glassPart.isSuppressedPart = true; glass.isSuppressedPart = true;
} }
} }
@ -337,9 +337,9 @@ export default {
// "glassPart2": [7, 10] // "glassPart2": [7, 10]
// }; // };
const thisPartsDupes = this.foundDuplicateQuestions["glassPart" + answer.glassPartIndex]; const thisPartsDupes = this.foundDuplicateQuestions["glass" + answer.glassIndex];
const completeAnsweredQuestions = answer.answeredQuestions ? [...answer.answeredQuestions] : []; const completeAnsweredQuestions = answer.answeredQuestions ? [...answer.answeredQuestions] : [];
const glassPartAnswered = this.capabilityQuestionsData[answer.glassPartIndex]; const glassPartAnswered = this.capabilityQuestionsData[answer.glassIndex];
debugger; // eslint-disable-line no-debugger debugger; // eslint-disable-line no-debugger
thisPartsDupes?.forEach((dupe) => { thisPartsDupes?.forEach((dupe) => {
// dupe is a single integer // dupe is a single integer
@ -395,7 +395,7 @@ debugger; // eslint-disable-line no-debugger
} }
// 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.glassPartIndex + 1; i < this.capabilityQuestionsData.length; i++) { for (let i = answer.glassIndex + 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;
@ -416,11 +416,11 @@ debugger; // eslint-disable-line no-debugger
// 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((glassPart, i) => { this.capabilityQuestionsData = this.pageData.partsOrQuestions.filter(x => x.capabilityQuestions).map((glass, i) => {
glassPart.key = glassPart.glassLocation + "-" + glassPart.glassName; glass.key = glass.glassLocation + "-" + glass.glassName;
this.selectedAnswers[glassPart.key] = []; this.selectedAnswers[glass.key] = [];
if (!alreadyAnsweredQuestions) { if (!alreadyAnsweredQuestions) {
glassPart.answerData = null; glass.answerData = null;
} }
alreadyAnsweredQuestions?.forEach((savedPart) => { alreadyAnsweredQuestions?.forEach((savedPart) => {
@ -428,7 +428,7 @@ debugger; // eslint-disable-line no-debugger
if (!savedPart.glassLocation || !savedPart.glassName || !savedPart.answeredQuestions || !savedPart.result) { if (!savedPart.glassLocation || !savedPart.glassName || !savedPart.answeredQuestions || !savedPart.result) {
return; return;
} }
if (glassPart.glassLocation === savedPart.glassLocation && glassPart.glassName === savedPart.glassName) { if (glass.glassLocation === savedPart.glassLocation && glass.glassName === savedPart.glassName) {
let answerString = ""; let answerString = "";
// matches; loop through answeredQuestions for matches // matches; loop through answeredQuestions for matches
@ -437,7 +437,7 @@ debugger; // eslint-disable-line no-debugger
return; return;
} }
// determine which answer was previously chosen // determine which answer was previously chosen
const theAns = glassPart.capabilityQuestions[aq.questionNum - 1].answers.find((a) => { const theAns = glass.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) {
@ -447,18 +447,18 @@ debugger; // eslint-disable-line no-debugger
} }
// mark this partQuestion as answered (question-chain will read this) // mark this partQuestion as answered (question-chain will read this)
glassPart.capabilityQuestions[aq.questionNum - 1].answerSelected = answerString; glass.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) {
glassPart.capabilityQuestions[aq.questionNum - 1].suppressQuestion = true; glass.capabilityQuestions[aq.questionNum - 1].suppressQuestion = true;
} }
}); });
// advance the currentQuestionChainIndex // advance the currentQuestionChainIndex
this.currentQuestionChainIndex = i; this.currentQuestionChainIndex = i;
// add answerData to current glassPart // add answerData to current glass
glassPart.answerData = { glass.answerData = {
answerResult: savedPart.result, answerResult: savedPart.result,
answerResult1: savedPart.result, answerResult1: savedPart.result,
answerResult2: this.getCorrespondingAnswerResult2(savedPart.result), answerResult2: this.getCorrespondingAnswerResult2(savedPart.result),
@ -468,14 +468,14 @@ debugger; // eslint-disable-line no-debugger
}); });
// Set up watch for each set of glassPart questions, which gets updated when all questions for a glassPart have been answered // Set up watch for each set of glass questions, which gets updated when all questions for a glass have been answered
this.$watch("selectedAnswers." + glassPart.key, (newValue) => { this.$watch("selectedAnswers." + glass.key, (newValue) => {
if (newValue) { if (newValue) {
this.handleAnswerUpdates(newValue); this.handleAnswerUpdates(newValue);
} }
}, { deep: true }) }, { deep: true })
return glassPart; return glass;
}); });
}, },

View file

@ -20,14 +20,14 @@
:manualCopy="AlertFewMoreQuestionsCopy" :manualCopy="AlertFewMoreQuestionsCopy"
v-bind:isDismissible="false" v-bind:isDismissible="false"
/> />
<div v-for="(glassPart, i) in moldingQuestionsData" :key="glassPart.key"> <div v-for="(glass, i) in moldingQuestionsData" :key="glass.key">
<questionChain <questionChain
ref="questionChain" ref="questionChain"
:keyString="glassPart.key" :keyString="glass.key"
v-model="selectedAnswers[glassPart.glassLocation + '-' + glassPart.glassName]" v-model="selectedAnswers[glass.glassLocation + '-' + glass.glassName]"
:questionData="glassPart.questions" :questionData="glass.questions"
:glassPartIndex="i" :glassIndex="i"
v-if="showThisQuestionChain(glassPart, i)" v-if="showThisQuestionChain(glass, i)"
validationRules="questions-required" validationRules="questions-required"
/> />
</div> </div>
@ -117,24 +117,24 @@ export default {
const moldingQuestionsFromPageData = store.getters.pageData(fmgPageValues.MOLDING_QUESTIONS); const moldingQuestionsFromPageData = store.getters.pageData(fmgPageValues.MOLDING_QUESTIONS);
return moldingQuestionsFromPageData && Object.keys(moldingQuestionsFromPageData).length > 0; return moldingQuestionsFromPageData && Object.keys(moldingQuestionsFromPageData).length > 0;
}, },
showThisQuestionChain(glassPart, i) { showThisQuestionChain(glass, i) {
if (part.partQuestions?.length < 1 || part.isSuppressedPart) { return false; } // return false if no partQuestions or if suppressed if (glass.questions?.length < 1 || glass.isSuppressedPart) { return false; } // return false if no questions or if suppressed
return this.currentPartNum === i || glassPart.answerData?.answerResult?.length > 0; return this.currentPartNum === i || glass.answerData?.answerResult?.length > 0;
}, },
async forwardButtonAction() { async forwardButtonAction() {
const questionAnswersArray = this.moldingQuestionsData.map((glassPart) => { const questionAnswersArray = this.moldingQuestionsData.map((glass) => {
return { return {
glassLocation: glassPart.glassLocation, glassLocation: glass.glassLocation,
glassName: glassPart.glassName, glassName: glass.glassName,
partNum: glassPart.answerData.answerResult, partNum: glass.answerData.answerResult,
answeredQuestions: glassPart.answerData.answeredQuestions, answeredQuestions: glass.answerData.answeredQuestions,
isSuppressedPart: glassPart.isSuppressedPart, isSuppressedPart: glass.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.moldingQuestionsData.forEach((glassPart) => { this.moldingQuestionsData.forEach((glass) => {
glassPart.answerData = {}; glass.answerData = {};
}); });
// save to vuex store as order.damage.partQuestionAnswers (array) // save to vuex store as order.damage.partQuestionAnswers (array)
@ -171,7 +171,7 @@ export default {
"questionNum": 1, "questionNum": 1,
} }
], ],
"glassPartIndex": 0 "glassIndex": 0
} }
*/ */
@ -194,18 +194,18 @@ export default {
// HANDLE DUPLICATE QUESTIONS // HANDLE DUPLICATE QUESTIONS
// loop through all glass parts data // loop through all glass parts data
this.moldingQuestionsData.forEach((glassPart, gpIndex) => { this.moldingQuestionsData.forEach((glass, 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.glassPartIndex) { if (gpIndex > answer.glassIndex) {
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; glass.answerData = null;
glassPart.isSuppressedPart = null; glass.isSuppressedPart = null;
// loop through this glass part's part questions, looking for a questionText match // loop through this glass part's part questions, looking for a questionText match
glassPart.questions.forEach((pq, pqIndex) => { glass.questions.forEach((pq, pqIndex) => {
// clear out any previously set answers // clear out any previously set answers
pq.answerSelected = null; pq.answerSelected = null;
@ -225,11 +225,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 thisAnsweredPartQuestion = glass.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;
@ -247,7 +247,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; glass.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 }
@ -256,7 +256,7 @@ export default {
} }
// handle suppressing upstream in this question chain // handle suppressing upstream in this question chain
glassPart.partQuestions.forEach((q) => { glass.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) {
@ -288,7 +288,7 @@ export default {
// suppress current question // suppress current question
thisAnsweredPartQuestion.suppressQuestion = true; thisAnsweredPartQuestion.suppressQuestion = true;
const thisGlassPart = "glassPart" + gpIndex; const thisGlassPart = "glass" + gpIndex;
if (this.foundDuplicateQuestions[thisGlassPart]) { if (this.foundDuplicateQuestions[thisGlassPart]) {
if (!this.foundDuplicateQuestions[thisGlassPart].includes(thisAnsweredPartQuestion.questionSequence)) { if (!this.foundDuplicateQuestions[thisGlassPart].includes(thisAnsweredPartQuestion.questionSequence)) {
this.foundDuplicateQuestions[thisGlassPart].push(thisAnsweredPartQuestion.questionSequence); this.foundDuplicateQuestions[thisGlassPart].push(thisAnsweredPartQuestion.questionSequence);
@ -298,7 +298,7 @@ export default {
} }
// 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 = glass.questions.filter((q) => {
return !q.suppressQuestion; return !q.suppressQuestion;
}); });
@ -313,13 +313,13 @@ export default {
suppressQuestion: pq.suppressQuestion, suppressQuestion: pq.suppressQuestion,
}; };
// set the answerData as 'already answered' // set the answerData as 'already answered'
glassPart.answerData = { glass.answerData = {
answerResult: matchedAnswer.nextQuestionSequence ? matchedAnswer.nextQuestionSequence : matchedAnswer.answerResult, answerResult: matchedAnswer.nextQuestionSequence ? matchedAnswer.nextQuestionSequence : matchedAnswer.answerResult,
answeredQuestions: [answeredQuestionObj], answeredQuestions: [answeredQuestionObj],
}; };
// suppress this glassPart because it has an answer // suppress this glass because it has an answer
glassPart.isSuppressedPart = true; glass.isSuppressedPart = true;
} }
} }
@ -347,16 +347,16 @@ export default {
// "glassPart2": [7, 10] // "glassPart2": [7, 10]
// }; // };
const thisPartsDupes = this.foundDuplicateQuestions["glassPart" + answer.glassPartIndex]; const thisPartsDupes = this.foundDuplicateQuestions["glass" + answer.glassIndex];
const completeAnsweredQuestions = answer.answeredQuestions ? [...answer.answeredQuestions] : []; const completeAnsweredQuestions = answer.answeredQuestions ? [...answer.answeredQuestions] : [];
const glassPartAnswered = this.moldingQuestionsData[answer.glassPartIndex]; const glassPartAnswered = this.moldingQuestionsData[answer.glassIndex];
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?
@ -400,7 +400,7 @@ export default {
} }
// this part has been fully answered, so advance to next molding question chain // this part has been fully answered, so advance to next molding question chain
for (let i = answer.glassPartIndex + 1; i < this.moldingQuestionsData.length; i++) { for (let i = answer.glassIndex + 1; i < this.moldingQuestionsData.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.moldingQuestionsData[i].answerData?.answerResult) { if (!this.moldingQuestionsData[i].answerData?.answerResult) {
this.currentPartNum = i; this.currentPartNum = i;
@ -414,14 +414,14 @@ export default {
// are there alreadyAnsweredQuestions? // are there alreadyAnsweredQuestions?
const alreadyAnsweredQuestions = store.getters.damage.partQuestionAnswers; const alreadyAnsweredQuestions = store.getters.damage.partQuestionAnswers;
this.moldingQuestionsData = this.pageData.partsOrQuestions.filter(x => x.parts[0].childPartQuestions.length).map((glassPart, i) => { this.moldingQuestionsData = this.pageData.partsOrQuestions.filter(x => x.parts[0].childPartQuestions.length).map((glass, i) => {
glassPart.key = glassPart.glassLocation + "-" + glassPart.glassName; glass.key = glass.glassLocation + "-" + glass.glassName;
// NOTE: property "questions" can differ between layouts // NOTE: property "questions" can differ between layouts
glassPart.questions = glassPart.parts[0].childPartQuestions; glass.questions = glass.parts[0].childPartQuestions;
this.selectedAnswers[glassPart.key] = []; this.selectedAnswers[glass.key] = [];
if (!alreadyAnsweredQuestions) { if (!alreadyAnsweredQuestions) {
glassPart.answerData = null; glass.answerData = null;
} }
alreadyAnsweredQuestions?.forEach((savedPart) => { alreadyAnsweredQuestions?.forEach((savedPart) => {
@ -429,7 +429,7 @@ export default {
if (!savedPart.glassLocation || !savedPart.glassName || !savedPart.answeredQuestions || !savedPart.result) { if (!savedPart.glassLocation || !savedPart.glassName || !savedPart.answeredQuestions || !savedPart.result) {
return; return;
} }
if (glassPart.glassLocation === savedPart.glassLocation && glassPart.glassName === savedPart.glassName) { if (glass.glassLocation === savedPart.glassLocation && glass.glassName === savedPart.glassName) {
let answerString = ""; let answerString = "";
// matches; loop through answeredQuestions for matches // matches; loop through answeredQuestions for matches
@ -438,7 +438,7 @@ export default {
return; return;
} }
// determine which answer was previously chosen // determine which answer was previously chosen
const theAns = glassPart.partQuestions[aq.questionNum-1].answers.find((a) => { const theAns = glass.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,18 +448,18 @@ export default {
} }
// mark this partQuestion as answered (question-chain will read this) // mark this partQuestion as answered (question-chain will read this)
glassPart.partQuestions[aq.questionNum-1].answerSelected = answerString; glass.questions[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) {
glassPart.partQuestions[aq.questionNum-1].suppressQuestion = true; glass.questions[aq.questionNum-1].suppressQuestion = true;
} }
}); });
// advance the currentPartNum // advance the currentPartNum
this.currentPartNum = i; this.currentPartNum = i;
// add answerData to current glassPart // add answerData to current glass
glassPart.answerData = { glass.answerData = {
answerResult: savedPart.result, answerResult: savedPart.result,
answeredQuestions: savedPart.answeredQuestions answeredQuestions: savedPart.answeredQuestions
} }
@ -467,14 +467,14 @@ export default {
}); });
// Set up watch for each set of glassPart questions, which gets updated when all questions for a glassPart have been answered // Set up watch for each set of glass questions, which gets updated when all questions for a glass have been answered
this.$watch("selectedAnswers." + glassPart.key, (newValue) => { this.$watch("selectedAnswers." + glass.key, (newValue) => {
if (newValue) { if (newValue) {
this.handleAnswerUpdates(glassPart.key, newValue); this.handleAnswerUpdates(glass.key, newValue);
} }
}, {deep: true}) }, {deep: true})
return glassPart; return glass;
}); });
}, },

View file

@ -20,14 +20,14 @@
:manualCopy="AlertFewMoreQuestionsCopy" :manualCopy="AlertFewMoreQuestionsCopy"
v-bind:isDismissible="false" v-bind:isDismissible="false"
/> />
<div v-for="(glassPart, i) in partsQuestionsData" :key="glassPart.key"> <div v-for="(glass, i) in partsQuestionsData" :key="glass.key">
<questionChain <questionChain
ref="questionChain" ref="questionChain"
:keyString="glassPart.key" :keyString="glass.key"
v-model="selectedAnswers[glassPart.glassLocation + '-' + glassPart.glassName]" v-model="selectedAnswers[glass.glassLocation + '-' + glass.glassName]"
:questionData="glassPart.questions" :questionData="glass.questions"
:glassPartIndex="i" :glassIndex="i"
v-if="showThisQuestionChain(glassPart, i)" v-if="showThisQuestionChain(glass, i)"
validationRules="questions-required" validationRules="questions-required"
/> />
</div> </div>
@ -117,24 +117,24 @@ export default {
const partQuestionsFromPageData = store.getters.pageData(fmgPageValues.PART_QUESTIONS); const partQuestionsFromPageData = store.getters.pageData(fmgPageValues.PART_QUESTIONS);
return partQuestionsFromPageData && Object.keys(partQuestionsFromPageData).length > 0; return partQuestionsFromPageData && Object.keys(partQuestionsFromPageData).length > 0;
}, },
showThisQuestionChain(glassPart, i) { showThisQuestionChain(glass, i) {
if (glassPart.questions?.length < 1 || glassPart.isSuppressedPart) { return false; } // return false if no questions or if suppressed if (!glass.questions || glass.questions?.length < 1 || glass.isSuppressedPart) { return false; } // return false if no questions or if suppressed
return this.currentPartNum === i || glassPart.answerData?.answerResult?.length > 0; return this.currentPartNum === i || glass.answerData?.answerResult?.length > 0;
}, },
async forwardButtonAction() { async forwardButtonAction() {
const questionAnswersArray = this.partsQuestionsData.map((glassPart) => { const questionAnswersArray = this.partsQuestionsData.map((glass) => {
return { return {
glassLocation: glassPart.glassLocation, glassLocation: glass.glassLocation,
glassName: glassPart.glassName, glassName: glass.glassName,
result: glassPart.answerData.answerResult, result: glass.answerData.answerResult,
answeredQuestions: glassPart.answerData.answeredQuestions, answeredQuestions: glass.answerData.answeredQuestions,
isSuppressedPart: glassPart.isSuppressedPart, isSuppressedPart: glass.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((glassPart) => { this.partsQuestionsData.forEach((glass) => {
glassPart.answerData = {}; glass.answerData = {};
}); });
// save to vuex store as order.damage.partQuestionAnswers (array) // save to vuex store as order.damage.partQuestionAnswers (array)
@ -167,7 +167,7 @@ export default {
"questionNum": 1, "questionNum": 1,
} }
], ],
"glassPartIndex": 0 "glassIndex": 0
} }
*/ */
@ -190,18 +190,18 @@ export default {
// HANDLE DUPLICATE QUESTIONS // HANDLE DUPLICATE QUESTIONS
// loop through all glass parts data // loop through all glass parts data
this.partsQuestionsData.forEach((glassPart, gpIndex) => { this.partsQuestionsData.forEach((glass, 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.glassPartIndex) { if (gpIndex > answer.glassIndex) {
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; glass.answerData = null;
glassPart.isSuppressedPart = null; glass.isSuppressedPart = null;
// loop through this glass part's questions, looking for a questionText match // loop through this glass part's questions, looking for a questionText match
glassPart.questions.forEach((pq, pqIndex) => { glass.questions.forEach((pq, pqIndex) => {
// clear out any previously set answers // clear out any previously set answers
pq.answerSelected = null; pq.answerSelected = null;
@ -221,7 +221,7 @@ 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 thisAnsweredQuestion = glassPart.questions[pqIndex]; const thisAnsweredQuestion = glass.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...
@ -243,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.questions[matchedAnswer.nextQuestionSequence - 1].suppressQuestion = null; glass.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 }
@ -252,7 +252,7 @@ export default {
} }
// handle suppressing upstream in this question chain // handle suppressing upstream in this question chain
glassPart.questions.forEach((q) => { glass.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) {
@ -284,7 +284,7 @@ export default {
// suppress current question // suppress current question
thisAnsweredQuestion.suppressQuestion = true; thisAnsweredQuestion.suppressQuestion = true;
const thisGlassPart = "glassPart" + gpIndex; const thisGlassPart = "glass" + gpIndex;
if (this.foundDuplicateQuestions[thisGlassPart]) { if (this.foundDuplicateQuestions[thisGlassPart]) {
if (!this.foundDuplicateQuestions[thisGlassPart].includes(thisAnsweredQuestion.questionSequence)) { if (!this.foundDuplicateQuestions[thisGlassPart].includes(thisAnsweredQuestion.questionSequence)) {
this.foundDuplicateQuestions[thisGlassPart].push(thisAnsweredQuestion.questionSequence); this.foundDuplicateQuestions[thisGlassPart].push(thisAnsweredQuestion.questionSequence);
@ -294,7 +294,7 @@ export default {
} }
// are there any questions left that are not suppressed? // are there any questions left that are not suppressed?
const remainingQuestions = glassPart.questions.filter((q) => { const remainingQuestions = glass.questions.filter((q) => {
return !q.suppressQuestion; return !q.suppressQuestion;
}); });
@ -309,13 +309,13 @@ export default {
suppressQuestion: pq.suppressQuestion, suppressQuestion: pq.suppressQuestion,
}; };
// set the answerData as 'already answered' // set the answerData as 'already answered'
glassPart.answerData = { glass.answerData = {
answerResult: matchedAnswer.nextQuestionSequence ? matchedAnswer.nextQuestionSequence : matchedAnswer.answerResult, answerResult: matchedAnswer.nextQuestionSequence ? matchedAnswer.nextQuestionSequence : matchedAnswer.answerResult,
answeredQuestions: [answeredQuestionObj], answeredQuestions: [answeredQuestionObj],
}; };
// suppress this glassPart because it has an answer // suppress this glass because it has an answer
glassPart.isSuppressedPart = true; glass.isSuppressedPart = true;
} }
} }
@ -343,9 +343,9 @@ export default {
// "glassPart2": [7, 10] // "glassPart2": [7, 10]
// }; // };
const thisPartsDupes = this.foundDuplicateQuestions["glassPart" + answer.glassPartIndex]; const thisPartsDupes = this.foundDuplicateQuestions["glass" + answer.glassIndex];
const completeAnsweredQuestions = answer.answeredQuestions ? [...answer.answeredQuestions] : []; const completeAnsweredQuestions = answer.answeredQuestions ? [...answer.answeredQuestions] : [];
const glassPartAnswered = this.partsQuestionsData[answer.glassPartIndex]; const glassPartAnswered = this.partsQuestionsData[answer.glassIndex];
thisPartsDupes?.forEach((dupe) => { thisPartsDupes?.forEach((dupe) => {
// dupe is a single integer // dupe is a single integer
@ -396,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.glassPartIndex + 1; i < this.partsQuestionsData.length; i++) { for (let i = answer.glassIndex + 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;
@ -410,14 +410,14 @@ export default {
// are there alreadyAnsweredQuestions? // are there alreadyAnsweredQuestions?
const alreadyAnsweredQuestions = store.getters.damage.partQuestionAnswers; const alreadyAnsweredQuestions = store.getters.damage.partQuestionAnswers;
this.partsQuestionsData = this.pageData.partsOrQuestions.filter(x => x.partQuestions).map((glassPart, i) => { this.partsQuestionsData = this.pageData.partsOrQuestions.filter(x => x.partQuestions).map((glass, i) => {
glassPart.key = glassPart.glassLocation + "-" + glassPart.glassName; glass.key = glass.glassLocation + "-" + glass.glassName;
// NOTE: property "questions" can differ between layouts // NOTE: property "questions" can differ between layouts
glassPart.questions = glassPart.partQuestions; glass.questions = glass.partQuestions;
this.selectedAnswers[glassPart.key] = []; this.selectedAnswers[glass.key] = [];
if (!alreadyAnsweredQuestions) { if (!alreadyAnsweredQuestions) {
glassPart.answerData = null; glass.answerData = null;
} }
alreadyAnsweredQuestions?.forEach((savedPart) => { alreadyAnsweredQuestions?.forEach((savedPart) => {
@ -425,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 (glassPart.glassLocation === savedPart.glassLocation && glassPart.glassName === savedPart.glassName) { if (glass.glassLocation === savedPart.glassLocation && glass.glassName === savedPart.glassName) {
let answerString = ""; let answerString = "";
// matches; loop through answeredQuestions for matches // matches; loop through answeredQuestions for matches
@ -434,7 +434,7 @@ export default {
return; return;
} }
// determine which answer was previously chosen // determine which answer was previously chosen
const theAns = glassPart.questions[aq.questionNum-1].answers.find((a) => { const theAns = glass.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) {
@ -444,18 +444,18 @@ export default {
} }
// mark this question as answered (question-chain will read this) // mark this question as answered (question-chain will read this)
glassPart.questions[aq.questionNum-1].answerSelected = answerString; glass.questions[aq.questionNum-1].answerSelected = answerString;
// mark this question 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) {
glassPart.questions[aq.questionNum-1].suppressQuestion = true; glass.questions[aq.questionNum-1].suppressQuestion = true;
} }
}); });
// advance the currentPartNum // advance the currentPartNum
this.currentPartNum = i; this.currentPartNum = i;
// add answerData to current glassPart // add answerData to current glass
glassPart.answerData = { glass.answerData = {
answerResult: savedPart.result, answerResult: savedPart.result,
answeredQuestions: savedPart.answeredQuestions answeredQuestions: savedPart.answeredQuestions
} }
@ -463,14 +463,14 @@ export default {
}); });
// Set up watch for each set of glassPart questions, which gets updated when all questions for a glassPart have been answered // Set up watch for each set of glass questions, which gets updated when all questions for a glass have been answered
this.$watch("selectedAnswers." + glassPart.key, (newValue) => { this.$watch("selectedAnswers." + glass.key, (newValue) => {
if (newValue) { if (newValue) {
this.handleAnswerUpdates(glassPart.key, newValue); this.handleAnswerUpdates(glass.key, newValue);
} }
}, {deep: true}) }, {deep: true})
return glassPart; return glass;
}); });
}, },