From 41fa4e68a8417fbbcc645c2bdba47edfad1e4fba Mon Sep 17 00:00:00 2001 From: thilo Date: Sun, 22 Mar 2020 22:08:45 +0100 Subject: [PATCH] finished skipping questions --- src/store/index.js | 1 + src/views/HelpPage.vue | 2 +- src/views/Results.vue | 47 ++++++++++++++++++++++++------------------ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index c38de7f..584d70f 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -16,6 +16,7 @@ export default new Vuex.Store({ this.state.currentQuestion = 0 }, answerQuestion(state, pl) { + this.state.skipped[pl.id] = false this.state.answers[pl.id] = pl.answer }, setSkipped(state, n) { diff --git a/src/views/HelpPage.vue b/src/views/HelpPage.vue index 254e796..4e5a527 100644 --- a/src/views/HelpPage.vue +++ b/src/views/HelpPage.vue @@ -38,13 +38,13 @@ }, methods: { nextQuestion() { + this.$store.commit("setSkipped", this.$route.params.id) if (this.$route.params.id < this.$store.state.questions.length - 1) { const nextQuestion = parseInt(this.$route.params.id) + 1 this.$router.push("/questionnaire/" + nextQuestion) } else { this.$store.commit("setSurveyCompleted") - this.$store.commit("setSkipped", this.$route.params.id) router.push('/results') } }, diff --git a/src/views/Results.vue b/src/views/Results.vue index 44e3147..4094c5b 100644 --- a/src/views/Results.vue +++ b/src/views/Results.vue @@ -29,35 +29,42 @@ export default { name: "Results", mounted() { - const summed = this.$store.state.answers.map((x, i) => { - return x * this.$store.state.questions[i].multiplicator + const answersFiltered = this.$store.state.answers.filter((value, index) => { + return !this.$store.state.skipped[index] + }) + const questionsFiltered = this.$store.state.questions.filter((value, index) => { + return !this.$store.state.skipped[index] + }) + + const summed = answersFiltered.map((x, i) => { + return x * questionsFiltered[i].multiplicator }).reduce(function(acc, current) { return acc + current }) - const sumMult = this.$store.state.questions.reduce(function(acc, current) { + const sumMult = questionsFiltered.reduce(function(acc, current) { return acc + current.multiplicator }, 0) this.risk = Math.round(summed / sumMult) - for(let i = 0; i < this.$store.state.answers.length; i ++) { - if (this.$store.state.answers[i] < 33) { - this.good.push({ - title: this.$store.state.questions[i].cards.good, - description: this.$store.state.questions[i].cards.information - }) - } else if (this.$store.state.answers[i] < 66) { - this.warning.push({ - title: this.$store.state.questions[i].cards.okay, - description: this.$store.state.questions[i].cards.information - }) - } else { - this.bad.push({ - title: this.$store.state.questions[i].cards.bad, - description: this.$store.state.questions[i].cards.information - }) - } + for(let i = 0; i < answersFiltered.length; i ++) { + if (answersFiltered[i] < 33) { + this.good.push({ + title: questionsFiltered[i].cards.good, + description: questionsFiltered[i].cards.information + }) + } else if (answersFiltered[i] < 66) { + this.warning.push({ + title: questionsFiltered[i].cards.okay, + description: questionsFiltered[i].cards.information + }) + } else { + this.bad.push({ + title: questionsFiltered[i].cards.bad, + description: questionsFiltered[i].cards.information + }) + } } }, data() {