finished skipping questions
This commit is contained in:
parent
96abb6559e
commit
41fa4e68a8
3 changed files with 29 additions and 21 deletions
|
@ -16,6 +16,7 @@ export default new Vuex.Store({
|
||||||
this.state.currentQuestion = 0
|
this.state.currentQuestion = 0
|
||||||
},
|
},
|
||||||
answerQuestion(state, pl) {
|
answerQuestion(state, pl) {
|
||||||
|
this.state.skipped[pl.id] = false
|
||||||
this.state.answers[pl.id] = pl.answer
|
this.state.answers[pl.id] = pl.answer
|
||||||
},
|
},
|
||||||
setSkipped(state, n) {
|
setSkipped(state, n) {
|
||||||
|
|
|
@ -38,13 +38,13 @@
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
nextQuestion() {
|
nextQuestion() {
|
||||||
|
this.$store.commit("setSkipped", this.$route.params.id)
|
||||||
if (this.$route.params.id < this.$store.state.questions.length - 1) {
|
if (this.$route.params.id < this.$store.state.questions.length - 1) {
|
||||||
const nextQuestion = parseInt(this.$route.params.id) + 1
|
const nextQuestion = parseInt(this.$route.params.id) + 1
|
||||||
this.$router.push("/questionnaire/" + nextQuestion)
|
this.$router.push("/questionnaire/" + nextQuestion)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.$store.commit("setSurveyCompleted")
|
this.$store.commit("setSurveyCompleted")
|
||||||
this.$store.commit("setSkipped", this.$route.params.id)
|
|
||||||
router.push('/results')
|
router.push('/results')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -29,33 +29,40 @@
|
||||||
export default {
|
export default {
|
||||||
name: "Results",
|
name: "Results",
|
||||||
mounted() {
|
mounted() {
|
||||||
const summed = this.$store.state.answers.map((x, i) => {
|
const answersFiltered = this.$store.state.answers.filter((value, index) => {
|
||||||
return x * this.$store.state.questions[i].multiplicator
|
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) {
|
}).reduce(function(acc, current) {
|
||||||
return 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
|
return acc + current.multiplicator
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
this.risk = Math.round(summed / sumMult)
|
this.risk = Math.round(summed / sumMult)
|
||||||
|
|
||||||
for(let i = 0; i < this.$store.state.answers.length; i ++) {
|
for(let i = 0; i < answersFiltered.length; i ++) {
|
||||||
if (this.$store.state.answers[i] < 33) {
|
if (answersFiltered[i] < 33) {
|
||||||
this.good.push({
|
this.good.push({
|
||||||
title: this.$store.state.questions[i].cards.good,
|
title: questionsFiltered[i].cards.good,
|
||||||
description: this.$store.state.questions[i].cards.information
|
description: questionsFiltered[i].cards.information
|
||||||
})
|
})
|
||||||
} else if (this.$store.state.answers[i] < 66) {
|
} else if (answersFiltered[i] < 66) {
|
||||||
this.warning.push({
|
this.warning.push({
|
||||||
title: this.$store.state.questions[i].cards.okay,
|
title: questionsFiltered[i].cards.okay,
|
||||||
description: this.$store.state.questions[i].cards.information
|
description: questionsFiltered[i].cards.information
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.bad.push({
|
this.bad.push({
|
||||||
title: this.$store.state.questions[i].cards.bad,
|
title: questionsFiltered[i].cards.bad,
|
||||||
description: this.$store.state.questions[i].cards.information
|
description: questionsFiltered[i].cards.information
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue