2 * questions group by index prefix 1.2.3 1.1 ...etc --> '1'
4 NOTE: questions can contain parameterized exercises (how ?
5 --> describe variables (syntax ?)
6 --> write javascript script (OK, users trusted ? ==> safe mode possible if public website)
7 Imaginary example: (using math.js)
11 M: math.matrix([[7, x], [y, -3]]);
14 <div>Calculer le déterminant de
15 $$\begin{matrix}7 & x\\y & -3\end{matrix}$$</div>
19 Vue
.component("statements", {
20 // 'answers' is an object containing
22 // 'displayAll'(bool), //TODO: should be in questions!
23 // 'showSolution'(bool),
24 // 'indices': order of appearance
25 // 'index': current integer index (focused question)
26 props: ['questions','answers'],
27 // TODO: general render function for nested exercises
28 // There should be a questions navigator below, or next (visible if display=='all')
29 // Full questions tree is rendered, but some parts hidden depending on display settings
31 // TODO: render nothing if answers is empty
32 let domTree
= (this.questions
|| [ ]).map( (q
,i
) => {
33 let questionContent
= [ ];
47 let optionsOrder
= _
.range(q
.options
.length
);
49 optionsOrder
= _
.shuffle(optionsOrder
);
51 optionsOrder
.forEach( idx
=> {
58 checked: this.answers
.inputs
.length
> 0 && this.answers
.inputs
[i
][idx
],
62 id: this.inputId(i
,idx
),
66 change: e
=> { this.answers
.inputs
[i
][idx
] = e
.target
.checked
; },
69 [ '' ] //to work in Firefox 45.9 ESR @ ENSTA...
77 innerHTML: q
.options
[idx
],
80 "for": this.inputId(i
,idx
),
91 choiceCorrect: this.answers
.showSolution
&& this.questions
[i
].answer
.includes(idx
),
92 choiceWrong: this.answers
.showSolution
&& this.answers
.inputs
[i
][idx
] && !q
.answer
.includes(idx
),
110 if (this.answers
.displayAll
&& i
< this.questions
.length
-1)
111 questionContent
.push( h("hr") );
117 "hide": !this.answers
.displayAll
&& this.answers
.indices
[this.answers
.index
] != i
,
133 mounted: function() {
134 statementsLibsRefresh();
136 updated: function() {
137 // TODO: next line shouldn't be required: questions wordings + answer + options
138 // are processed earlier; their content should be updated at this time.
139 statementsLibsRefresh();
142 inputId: function(i
,j
) {
143 return "q" + i
+ "_" + "input" + j
;