finished skipping questions

This commit is contained in:
thilo 2020-03-22 22:08:45 +01:00
parent 96abb6559e
commit 41fa4e68a8
3 changed files with 29 additions and 21 deletions

View file

@ -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) {

View file

@ -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')
}
},

View file

@ -29,33 +29,40 @@
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) {
for(let i = 0; i < answersFiltered.length; i ++) {
if (answersFiltered[i] < 33) {
this.good.push({
title: this.$store.state.questions[i].cards.good,
description: this.$store.state.questions[i].cards.information
title: questionsFiltered[i].cards.good,
description: questionsFiltered[i].cards.information
})
} else if (this.$store.state.answers[i] < 66) {
} else if (answersFiltered[i] < 66) {
this.warning.push({
title: this.$store.state.questions[i].cards.okay,
description: this.$store.state.questions[i].cards.information
title: questionsFiltered[i].cards.okay,
description: questionsFiltered[i].cards.information
})
} else {
this.bad.push({
title: this.$store.state.questions[i].cards.bad,
description: this.$store.state.questions[i].cards.information
title: questionsFiltered[i].cards.bad,
description: questionsFiltered[i].cards.information
})
}
}