Fix several smaller problems
* adapt for structure change in gql backend (e.g. id -> rowId) * display questions not rowId dependent anymore * fixed calculation error if both, party and user, selected "skipped" * fixed problems occuring when a candidate hasn't answered all questions (yet)
This commit is contained in:
parent
f239bec4ff
commit
d414b95c1c
|
@ -6,7 +6,7 @@
|
|||
<span>/{{ thesesCount }}</span>
|
||||
</div>
|
||||
<button
|
||||
:disabled="currentThesis === 1"
|
||||
:disabled="currentThesisStep === 1"
|
||||
class="btn-dark btn-small"
|
||||
type="button"
|
||||
@click="goBack"
|
||||
|
@ -73,7 +73,7 @@
|
|||
|
||||
data () {
|
||||
return {
|
||||
currentThesis: 1,
|
||||
currentThesisStep: 1,
|
||||
theses: [],
|
||||
thesesCount: 0,
|
||||
answers: []
|
||||
|
@ -98,20 +98,17 @@
|
|||
this.$route.query.embedded === 'iframe'
|
||||
)
|
||||
},
|
||||
currentThesisStep () {
|
||||
return this.currentThesis
|
||||
},
|
||||
thesisTitle () {
|
||||
if (this.currentThesis > this.thesesCount) {
|
||||
if (this.currentThesisStep > this.thesesCount) {
|
||||
return
|
||||
}
|
||||
return this.getThesis(this.currentThesis).thesis[this.$i18n.locale]
|
||||
return this.theses[this.currentThesisStep - 1].thesis[this.$i18n.locale]
|
||||
},
|
||||
thesisCategory () {
|
||||
if (this.currentThesis > this.thesesCount) {
|
||||
if (this.currentThesisStep > this.thesesCount) {
|
||||
return
|
||||
}
|
||||
return this.getThesis(this.currentThesis).category[this.$i18n.locale]
|
||||
return this.theses[this.currentThesisStep - 1].category[this.$i18n.locale]
|
||||
},
|
||||
possiblePositions () {
|
||||
return possiblePositions.map(option =>
|
||||
|
@ -139,14 +136,11 @@
|
|||
default:
|
||||
}
|
||||
},
|
||||
getThesis (id) {
|
||||
return this.theses.find(t => t.id === id)
|
||||
},
|
||||
goBack () {
|
||||
const thesis = this.getThesis(this.currentThesis)
|
||||
const thesis = this.theses[this.currentThesisStep - 1]
|
||||
const index = this.answers.findIndex(a => a.thesis === thesis.id)
|
||||
this.answers.splice(index, 1)
|
||||
this.currentThesis -= 1
|
||||
this.currentThesisStep -= 1
|
||||
},
|
||||
submitAnswer (option, event) {
|
||||
if (!option) {
|
||||
|
@ -154,13 +148,13 @@
|
|||
return console.warn('Invalid answer')
|
||||
}
|
||||
|
||||
const thesis = this.getThesis(this.currentThesis)
|
||||
const thesis = this.theses[this.currentThesisStep - 1]
|
||||
this.answers.push({ thesis: thesis.id, position: option.position })
|
||||
this.currentThesis += 1
|
||||
this.currentThesisStep += 1
|
||||
event && event.target.blur()
|
||||
window.scrollTo(0, 0)
|
||||
|
||||
if (this.currentThesis > this.thesesCount) {
|
||||
if (this.currentThesisStep > this.thesesCount) {
|
||||
this.forwardToResults()
|
||||
}
|
||||
},
|
||||
|
|
|
@ -6,26 +6,26 @@ export function getPositionById (id) {
|
|||
}
|
||||
|
||||
export const apolloThesesQuery = gql`{
|
||||
allQuestions(orderBy: ID_ASC) {
|
||||
allQuestions(orderBy: ROW_ID_ASC) {
|
||||
nodes {
|
||||
category: categoryByCategoryId {
|
||||
nodeId
|
||||
category: categoryByCategoryRowId {
|
||||
id
|
||||
title
|
||||
}
|
||||
text
|
||||
title
|
||||
rowId
|
||||
id
|
||||
nodeId
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
export const apolloThesesUpdate = data => data.allQuestions.nodes.map(node => ({
|
||||
id: node.id,
|
||||
id: node.rowId,
|
||||
thesis: {
|
||||
de: node.text
|
||||
de: node.title
|
||||
},
|
||||
category: {
|
||||
de: node.category.title
|
||||
de: node.category ? node.category.title : ''
|
||||
}
|
||||
}))
|
||||
|
||||
|
@ -40,15 +40,15 @@ export const apolloThesesCountUpdate = data => data.allQuestions.totalCount
|
|||
export const apolloPersonsForResultsQuery = gql`{
|
||||
allPeople(condition: {role: CANDYMAT_CANDIDATE}) {
|
||||
nodes {
|
||||
nodeId
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
id
|
||||
answersByPersonId {
|
||||
rowId
|
||||
answers: answersByPersonRowId {
|
||||
nodes {
|
||||
nodeId
|
||||
id
|
||||
position
|
||||
questionId
|
||||
questionRowId
|
||||
text
|
||||
}
|
||||
}
|
||||
|
@ -57,11 +57,11 @@ export const apolloPersonsForResultsQuery = gql`{
|
|||
}`
|
||||
|
||||
export const apolloPersonsForResultsUpdate = data => data.allPeople.nodes.map(person => ({
|
||||
id: person.id,
|
||||
id: person.rowId,
|
||||
name: `${person.firstName} ${person.lastName}`,
|
||||
token: person.firstName.charAt(0) + person.lastName.charAt(0),
|
||||
positions: person.answersByPersonId.nodes.map(answer => ({
|
||||
thesis: answer.questionId,
|
||||
positions: person.answers.nodes.map(answer => ({
|
||||
thesis: answer.questionRowId,
|
||||
position: getPositionById(answer.position),
|
||||
statement: {
|
||||
de: answer.text
|
||||
|
@ -71,45 +71,39 @@ export const apolloPersonsForResultsUpdate = data => data.allPeople.nodes.map(pe
|
|||
|
||||
export const apolloPersonPositionsQuery = gql`
|
||||
query Person($partyId: Int!) {
|
||||
personById(id: $partyId) {
|
||||
nodeId
|
||||
personByRowId(rowId: $partyId) {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
answersByPersonId {
|
||||
answers: answersByPersonRowId {
|
||||
nodes {
|
||||
nodeId
|
||||
id
|
||||
position
|
||||
personId
|
||||
personRowId
|
||||
text
|
||||
questionByQuestionId {
|
||||
nodeId
|
||||
categoryByCategoryId {
|
||||
nodeId
|
||||
title
|
||||
}
|
||||
text
|
||||
question: questionByQuestionRowId {
|
||||
id
|
||||
description
|
||||
rowId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
export const apolloPersonPositionsUpdate = data => ({
|
||||
id: data.personById.id,
|
||||
name: `${data.personById.firstName} ${data.personById.lastName}`,
|
||||
token: data.personById.firstName.charAt(0) + data.personById.lastName.charAt(0),
|
||||
theses: data.personById.answersByPersonId.nodes.map(answer => {
|
||||
const question = answer.questionByQuestionId
|
||||
return {
|
||||
id: question.id,
|
||||
thesis: question.text,
|
||||
category: question.categoryByCategoryId.title,
|
||||
position: getPositionById(answer.position),
|
||||
statement: answer.text,
|
||||
showStatement: false
|
||||
}
|
||||
})
|
||||
})
|
||||
export const apolloPersonPositionsUpdate = data => {
|
||||
const person = data.personByRowId
|
||||
return {
|
||||
id: person.rowId,
|
||||
name: `${person.firstName} ${person.lastName}`,
|
||||
token: person.firstName.charAt(0) + person.lastName.charAt(0),
|
||||
theses: person.answers ? person.answers.nodes.map(answer => {
|
||||
const question = answer.question
|
||||
return question ? {
|
||||
id: question.rowId,
|
||||
position: getPositionById(answer.position),
|
||||
statement: answer.text,
|
||||
showStatement: false
|
||||
} : null
|
||||
}) : []
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ function getUserPosition (row) {
|
|||
// ...
|
||||
// ]
|
||||
function getScoringGrid (userAnswers, emphasizedTheses, parties) {
|
||||
return userAnswers.map(answer => (
|
||||
const grid = userAnswers.map(answer => (
|
||||
{
|
||||
thesis: answer.thesis,
|
||||
emphasis: emphasizedTheses.filter(e => e.thesis === answer.thesis).length >= 1,
|
||||
|
@ -83,6 +83,7 @@ function getScoringGrid (userAnswers, emphasizedTheses, parties) {
|
|||
]
|
||||
}
|
||||
))
|
||||
return grid
|
||||
}
|
||||
|
||||
function getPartyPositions (thesis, parties) {
|
||||
|
@ -91,15 +92,16 @@ function getPartyPositions (thesis, parties) {
|
|||
return {
|
||||
type: 'party',
|
||||
party: party.id,
|
||||
position: (position && position.position) || {}
|
||||
position: (position && position.position) || 'skipped'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function evalPointsPerThesisPerParty (partyPosition, userPosition, emphasis) {
|
||||
let score = 0
|
||||
|
||||
if (userPosition === partyPosition) {
|
||||
if (partyPosition === 'skipped' || userPosition === 'skipped') {
|
||||
score = MIN_POINTS
|
||||
} else if (userPosition === partyPosition) {
|
||||
score = MAX_POINTS
|
||||
} else if (
|
||||
(userPosition === 'positive' && partyPosition === 'neutral') ||
|
||||
|
|
|
@ -90,13 +90,19 @@ describe('The evalPointsPerThesisPerParty fucntion', () => {
|
|||
${'negative'} | ${'negative'} | ${2} | ${4}
|
||||
${'negative'} | ${'neutral'} | ${1} | ${2}
|
||||
${'negative'} | ${'positive'} | ${0} | ${0}
|
||||
${'negative'} | ${'skipped'} | ${0} | ${0}
|
||||
${'neutral'} | ${'negative'} | ${1} | ${2}
|
||||
${'neutral'} | ${'neutral'} | ${2} | ${4}
|
||||
${'neutral'} | ${'positive'} | ${1} | ${2}
|
||||
${'neutral'} | ${'skipped'} | ${0} | ${0}
|
||||
${'positive'} | ${'negative'} | ${0} | ${0}
|
||||
${'positive'} | ${'neutral'} | ${1} | ${2}
|
||||
${'positive'} | ${'positive'} | ${2} | ${4}
|
||||
${'positive'} | ${'skipped'} | ${0} | ${0}
|
||||
${'skipped'} | ${'negative'} | ${0} | ${0}
|
||||
${'skipped'} | ${'neutral'} | ${0} | ${0}
|
||||
${'skipped'} | ${'positive'} | ${0} | ${0}
|
||||
${'skipped'} | ${'skipped'} | ${0} | ${0}
|
||||
`('returns the correct score (according to the Rechenmodell of the bpb' +
|
||||
' if the party position is $partyPosition and the user\'s position is $userPosition',
|
||||
({ partyPosition, userPosition, expectedScore, expectedScoreWithEmphasis }) => {
|
||||
|
|
|
@ -47,18 +47,18 @@
|
|||
</h2>
|
||||
</li>
|
||||
|
||||
<li v-for="thesis in party.theses" :key="thesis.id">
|
||||
<li v-for="thesis in theses" :key="thesis.id">
|
||||
<div class="thesis-facts">
|
||||
<div class="list-thesis" @click="toggleStatement(thesis)">
|
||||
<div class="thesis-subline">
|
||||
<component :is="'feather-' + chevronIcon(thesis.showStatement)" />
|
||||
<span>{{ thesis.category }}</span>
|
||||
<span>{{ thesis.category[$i18n.locale] }}</span>
|
||||
</div>
|
||||
<h3>{{ thesis.thesis }}</h3>
|
||||
<h3>{{ thesis.thesis[$i18n.locale] }}</h3>
|
||||
</div>
|
||||
|
||||
<div class="statements-party">
|
||||
<component :is="'feather-' + positionToIconName(thesis.position)" />
|
||||
<component :is="'feather-' + positionToIconName(getPartyPosition(thesis))" />
|
||||
</div>
|
||||
<div v-if="!!answers" class="statements-user">
|
||||
<component :is="'feather-' + getUserPosition(thesis.id)" />
|
||||
|
@ -68,7 +68,7 @@
|
|||
<div v-show="thesis.showStatement" class="thesis-statement">
|
||||
<p><strong>{{ $t('party.partyAnswer') }}:</strong></p>
|
||||
<blockquote>
|
||||
{{ thesis.statement }}
|
||||
{{ getPartyStatement(thesis) }}
|
||||
</blockquote>
|
||||
</div>
|
||||
</li>
|
||||
|
@ -87,7 +87,11 @@
|
|||
<script>
|
||||
import possiblePositions from '@/app/euromat/possiblePositions'
|
||||
import { getTranslatedUrl } from '@/i18n/helper'
|
||||
import { apolloPersonPositionsQuery, apolloPersonPositionsUpdate } from '@/app/euromat/graphqlQueries'
|
||||
import {
|
||||
apolloPersonPositionsQuery,
|
||||
apolloPersonPositionsUpdate,
|
||||
apolloThesesQuery, apolloThesesUpdate
|
||||
} from '@/app/euromat/graphqlQueries'
|
||||
|
||||
export default {
|
||||
name: 'Party',
|
||||
|
@ -129,6 +133,7 @@
|
|||
name: 'Loading ...',
|
||||
theses: []
|
||||
},
|
||||
theses: [],
|
||||
answers,
|
||||
possiblePositions
|
||||
}
|
||||
|
@ -143,9 +148,15 @@
|
|||
}
|
||||
},
|
||||
update: apolloPersonPositionsUpdate
|
||||
},
|
||||
theses: {
|
||||
query: apolloThesesQuery,
|
||||
update: data => {
|
||||
const allTheses = apolloThesesUpdate(data)
|
||||
return allTheses.map(thesis => ({ ...thesis, showStatement: false }))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
resultsPath () {
|
||||
return getTranslatedUrl('results', getTranslatedUrl('theses', null, true))
|
||||
|
@ -156,6 +167,17 @@
|
|||
},
|
||||
|
||||
methods: {
|
||||
getPartyAnswerForThesis (thesis) {
|
||||
return this.party.theses.find(partyThesis => partyThesis.id === thesis.id)
|
||||
},
|
||||
getPartyPosition (thesis) {
|
||||
const partyAnswerForThesis = this.getPartyAnswerForThesis(thesis)
|
||||
return partyAnswerForThesis ? partyAnswerForThesis.position : 'skipped'
|
||||
},
|
||||
getPartyStatement (thesis) {
|
||||
const partyAnswerForThesis = this.getPartyAnswerForThesis(thesis)
|
||||
return partyAnswerForThesis ? partyAnswerForThesis.statement : ''
|
||||
},
|
||||
chevronIcon (showStatement) {
|
||||
return showStatement
|
||||
? 'chevron-up'
|
||||
|
|
Loading…
Reference in a new issue