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 + fixed + question time (syntax ?)
20 --> input of type text (number, or vector, or matrix e.g. in R syntax)
21 --> parameter stored in question.param (TODO)
25 Vue
.component("statements", {
26 // 'inputs': object with key = question index and value = text or boolean array
27 // display: 'all', 'one', 'solution'
28 // iidx: current level-0 integer index (can match a group of questions / inputs)
29 props: ['questions','inputs','display','iidx'],
32 displayStyle: "compact", //or "all": all on same page
35 // Full questions tree is rendered, but some parts hidden depending on display settings
37 // Prepare questions groups, ordered
38 let questions
= this.questions
|| [ ]
39 let questionGroups
= _
.groupBy(questions
, q
=> {
40 const dotPos
= q
.index
.indexOf(".");
41 return dotPos
=== -1 ? q
.index : q
.index
.substring(0,dotPos
);
43 let domTree
= questionGroups
.map( (qg
,i
) => {
44 // Re-order questions 1.1.1 then 1.1.2 then...
45 const orderedQg
= qg
.sort( (a
,b
) => {
46 let aParts
= a
.split('.').map(Number
);
47 let bParts
= b
.split('.').map(Number
);
48 const La
= aParts
.length
, Lb
= bParts
.length
;
49 for (let i
=0; i
<Math
.min(La
,Lb
); i
++)
51 if (aParts
[i
] != bParts
[i
])
52 return aParts
[i
] - bParts
[i
];
54 return La
- Lb
; //the longer should appear after
56 let qgDom
= orderedQg
.map( q
=> {
57 let questionContent
= [ ];
63 "questionIndex": true,
85 let optionsOrder
= _
.range(q
.options
.length
);
87 optionsOrder
= _
.shuffle(optionsOrder
);
89 optionsOrder
.forEach( idx
=> {
96 checked: !!this.inputs
&& this.inputs
[q
.index
][idx
],
97 disabled: monitoring
|| this.display
== "solution",
100 id: this.inputId(q
.index
,idx
),
104 change: e
=> { this.inputs
[q
.index
][idx
] = e
.target
.checked
; },
107 [ '' ] //to work in Firefox 45.9 ESR @ ENSTA...
115 innerHTML: q
.options
[idx
],
118 "for": this.inputId(q
.index
,idx
),
129 choiceCorrect: this.display
== "solution" && q
.answer
.includes(idx
),
130 choiceWrong: this.display
== "solution" && !!this.inputs
&& this.inputs
[q
.index
][idx
] && !q
.answer
.includes(idx
),
137 questionContent
.push(
149 const depth
= (q
.index
.match(/\./g) || []).length
;
155 "depth" + depth: true,
165 "questionGroup": true,
166 "hide": this.display
== "one" && this.iidx
!= i
,
176 "hide": this.displayStyle
== "all"
188 this.index
= Math
.max(0, this.index
- 1);
192 [ h("span", { "class": { "material-icon": true } }, "fast_rewind") ]
194 h("span",{ },(this.iidx
+1).toString()),
203 this.index
= Math
.min(this.index
+1, this.questions
.length
-1)
207 [ h("span", { "class": { "material-icon": true } }, "fast_forward") ]
211 domTree
.push(navigator
);
218 this.displayStyle
= displayStyle
== "compact" ? "all" : "compact";
222 this.displayStyle
== "compact" ? "Show all" : "Navigator"
235 mounted: function() {
236 statementsLibsRefresh();
238 updated: function() {
239 statementsLibsRefresh();
242 inputId: function(i
,j
) {
243 return "q" + i
+ "_" + "input" + j
;