diff --git a/src/app/euromat/components/theses.vue b/src/app/euromat/components/theses.vue index c86a415..66be845 100644 --- a/src/app/euromat/components/theses.vue +++ b/src/app/euromat/components/theses.vue @@ -6,7 +6,7 @@ /{{ thesesCount }} 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() } }, diff --git a/src/app/euromat/graphqlQueries.js b/src/app/euromat/graphqlQueries.js index c083d82..65d3f51 100644 --- a/src/app/euromat/graphqlQueries.js +++ b/src/app/euromat/graphqlQueries.js @@ -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 + }) : [] + } +} diff --git a/src/app/euromat/scoring.js b/src/app/euromat/scoring.js index ba8f620..67ff859 100644 --- a/src/app/euromat/scoring.js +++ b/src/app/euromat/scoring.js @@ -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') || diff --git a/src/app/euromat/scoring.test.js b/src/app/euromat/scoring.test.js index aca6025..99c4078 100644 --- a/src/app/euromat/scoring.test.js +++ b/src/app/euromat/scoring.test.js @@ -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 }) => { diff --git a/src/app/party/components/index.vue b/src/app/party/components/index.vue index e86e773..1b446a5 100644 --- a/src/app/party/components/index.vue +++ b/src/app/party/components/index.vue @@ -47,18 +47,18 @@ - + - {{ thesis.category }} + {{ thesis.category[$i18n.locale] }} - {{ thesis.thesis }} + {{ thesis.thesis[$i18n.locale] }} - + @@ -68,7 +68,7 @@ {{ $t('party.partyAnswer') }}: - {{ thesis.statement }} + {{ getPartyStatement(thesis) }} @@ -87,7 +87,11 @@
{{ $t('party.partyAnswer') }}:
- {{ thesis.statement }} + {{ getPartyStatement(thesis) }}