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>
18 --> input of type text (number, or vector, or matrix e.g. in R syntax)
19 --> parameter stored in question.param (TODO)
23 Vue
.component("statements", {
24 // 'inputs': object with key = question index and value = text or boolean array
25 // display: 'all', 'one', 'solution'
26 // iidx: current level-0 integer index (can match a group of questions / inputs)
27 props: ['questions','inputs','display','iidx'],
30 displayStyle: "compact", //or "all": all on same page
33 // Full questions tree is rendered, but some parts hidden depending on display settings
35 // Prepare questions groups, ordered
36 let questions
= this.questions
|| [ ]
37 let questionGroups
= _
.groupBy(questions
, q
=> {
38 const dotPos
= q
.index
.indexOf(".");
39 return dotPos
=== -1 ? q
.index : q
.index
.substring(0,dotPos
);
41 let domTree
= questionGroups
.map( (qg
,i
) => {
42 // Re-order questions 1.1.1 then 1.1.2 then...
43 const orderedQg
= qg
.sort( (a
,b
) => {
44 let aParts
= a
.split('.').map(Number
);
45 let bParts
= b
.split('.').map(Number
);
46 const La
= aParts
.length
, Lb
= bParts
.length
;
47 for (let i
=0; i
<Math
.min(La
,Lb
); i
++)
49 if (aParts
[i
] != bParts
[i
])
50 return aParts
[i
] - bParts
[i
];
52 return La
- Lb
; //the longer should appear after
54 let qgDom
= orderedQg
.map( q
=> {
55 let questionContent
= [ ];
61 "questionIndex": true,
83 let optionsOrder
= _
.range(q
.options
.length
);
85 optionsOrder
= _
.shuffle(optionsOrder
);
87 optionsOrder
.forEach( idx
=> {
94 checked: this.inputs
[q
.index
][idx
],
98 id: this.inputId(q
.index
,idx
),
102 change: e
=> { this.inputs
[q
.index
][idx
] = e
.target
.checked
; },
105 [ '' ] //to work in Firefox 45.9 ESR @ ENSTA...
113 innerHTML: q
.options
[idx
],
116 "for": this.inputId(q
.index
,idx
),
127 choiceCorrect: this.display
== "solution" && q
.answer
.includes(idx
),
128 choiceWrong: this.display
== "solution" && this.inputs
[q
.index
][idx
] && !q
.answer
.includes(idx
),
135 questionContent
.push(
147 const depth
= (q
.index
.match(/\./g) || []).length
;
153 "depth" + depth: true,
163 "questionGroup": true,
164 "hide": this.display
== "one" && this.iidx
!= i
,
174 "hide": this.displayStyle
== "all"
186 this.index
= Math
.max(0, this.index
- 1);
190 [ h("span", { "class": { "material-icon": true } }, "fast_rewind") ]
192 h("span",{ },(this.iidx
+1).toString()),
201 this.index
= Math
.min(this.index
+1, this.questions
.length
-1)
205 [ h("span", { "class": { "material-icon": true } }, "fast_forward") ]
209 domTree
.push(navigator
);
216 this.displayStyle
= displayStyle
== "compact" ? "all" : "compact";
220 this.displayStyle
== "compact" ? "Show all" : "Navigator"
233 mounted: function() {
234 statementsLibsRefresh();
236 updated: function() {
237 statementsLibsRefresh();
240 inputId: function(i
,j
) {
241 return "q" + i
+ "_" + "input" + j
;