d93a97f239c5f1e5aad79db28c16f24a7b805d4d
1 Vue
.component("statements", {
2 props: ['questions','inputs','showAnswers','index'], // index=-1 : show all, otherwise show current question
3 // TODO: general render function for nested exercises
4 // There should be a questions navigator below, or next (visible if display=='all')
5 // Full questions tree is rendered, but some parts hidden depending on display settings
7 let domTree
= this.questions
.map( (q
,i
) => {
8 let questionContent
= [ ];
22 let optionsOrder
= _
.range(q
.options
.length
);
24 optionsOrder
= _
.shuffle(optionsOrder
);
26 optionsOrder
.forEach( idx
=> {
33 checked: this.inputs
.length
> 0 && this.inputs
[i
][idx
],
37 id: this.inputId(i
,idx
),
41 change: e
=> { this.inputs
[i
][idx
] = e
.target
.checked
; },
51 innerHTML: q
.options
[idx
],
54 "for": this.inputId(i
,idx
),
65 choiceCorrect: showAnswers
&& this.questions
[i
].answer
.includes(idx
),
66 choiceWrong: showAnswers
&& this.inputs
[i
][idx
] && !questions
[i
].answer
.includes(idx
),
89 "hide": index
>= 0 && index
!= i
,
105 updated: function() {
106 // TODO: next line shouldn't be required: questions wordings + answer + options
107 // are processed earlier; their content should be updated at this time.
108 statementsLibsRefresh();
111 inputId: function(i
,j
) {
112 return "q" + i
+ "_" + "input" + j
;