Skip to content

Commit

Permalink
Fix initQuestionSet
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jan 9, 2025
1 parent ccd3cd8 commit fbe188a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions rdmo/projects/assets/js/interview/utils/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,36 @@ const initQuestionSet = (questionset) => {
// aggregate questionsets from descendants
questionset.questionsets = questionset.elements.reduce((questionsets, element) => {
if (element.model == 'questions.questionset') {
return questionsets.concat(element.questionsets)
return [...questionsets, element, ...element.questionsets] // add this questionset and all it's questionsets
} else {
return questionsets
return questionsets // do nothing
}
}, [])

// aggregate optionsets from descendants
// aggregate questions from descendants
questionset.questions = questionset.elements.reduce((questions, element) => {
if (element.model == 'questions.questionset') {
return questions.concat(element.questions)
return questions.concat(element.questions) // add the questions of this questionset
} else {
return [...questions, element]
return [...questions, element] // add this question
}
}, [])

// aggregate optionsets from descendants
questionset.optionsets = questionset.elements.reduce((optionsets, element) => {
if (element.model == 'questions.questionset') {
return optionsets.concat(element.optionsets)
return optionsets.concat(element.optionsets) // add all optionsets of the questions of this questionset
} else {
return [...optionsets, ...element.optionsets]
return [...optionsets, ...element.optionsets] // add all optionsets of this question
}
}, [])

// aggregate attributes from descendants
questionset.attributes = questionset.elements.reduce((attributes, element) => {
if (element.model == 'questions.questionset') {
return attributes.concat(element.attributes)
return attributes.concat(element.attributes) // add all attributes of this questionset and its questions
} else {
return [...attributes, element.attribute]
return [...attributes, element.attribute] // add the attribute of this question
}
}, [questionset.attribute]).filter((a) => !isNil(a))
}
Expand Down

0 comments on commit fbe188a

Please sign in to comment.