86138c00a2d2c7e72a6b5aff591756a9c41ead77
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','answers','display','iidx'],
32 displayStyle: "compact", //or "all": all on same page
33 parameters: 0, //TODO: DO NOT re-draw parameters for already answered questions
36 // Full questions tree is rendered, but some parts hidden depending on display settings
38 // Prepare questions groups, ordered
39 let questions
= this.questions
|| [ ]
40 let questionGroups
= _
.groupBy(questions
, q
=> {
41 const dotPos
= q
.index
.indexOf(".");
42 return dotPos
=== -1 ? q
.index : q
.index
.substring(0,dotPos
);
44 let domTree
= questionGroups
.map( (qg
,i
) => {
45 // Re-order questions 1.1.1 then 1.1.2 then...
46 const orderedQg
= qg
.sort( (a
,b
) => {
47 let aParts
= a
.split('.').map(Number
);
48 let bParts
= b
.split('.').map(Number
);
49 const La
= aParts
.length
, Lb
= bParts
.length
;
50 for (let i
=0; i
<Math
.min(La
,Lb
); i
++)
52 if (aParts
[i
] != bParts
[i
])
53 return aParts
[i
] - bParts
[i
];
55 return La
- Lb
; //the longer should appear after
57 let qgDom
= orderedQg
.map( q
=> {
58 let questionContent
= [ ];
64 "questionIndex": true,
86 let optionsOrder
= _
.range(q
.options
.length
);
88 optionsOrder
= _
.shuffle(optionsOrder
);
90 optionsOrder
.forEach( idx
=> {
97 checked: !!this.inputs
&& this.inputs
[q
.index
][idx
],
98 disabled: monitoring
|| this.display
== "solution",
101 id: this.inputId(q
.index
,idx
),
105 change: e
=> { this.inputs
[q
.index
][idx
] = e
.target
.checked
; },
108 [ '' ] //to work in Firefox 45.9 ESR @ ENSTA...
116 innerHTML: q
.options
[idx
],
119 "for": this.inputId(q
.index
,idx
),
124 const aIdx
= (this.answers
|| [ ]).findIndex( item
=> { return item
.index
== q
.index
; });
131 choiceCorrect: this.display
== "solution" && this.answers
[aIdx
].includes(idx
),
132 choiceWrong: this.display
== "solution" && !!this.inputs
&& this.inputs
[q
.index
][idx
] && !this.answers
[aIdx
].includes(idx
),
139 questionContent
.push(
153 // Open question, or parameterized: TODO
155 const depth
= (q
.index
.match(/\./g) || []).length
;
161 "depth" + depth: true,
171 "questionGroup": true,
172 "hide": this.display
== "one" && this.iidx
!= i
,
182 "hide": this.displayStyle
== "all"
194 this.index
= Math
.max(0, this.index
- 1);
198 [ h("span", { "class": { "material-icon": true } }, "fast_rewind") ]
200 h("span",{ },(this.iidx
+1).toString()),
209 this.index
= Math
.min(this.index
+1, this.questions
.length
-1)
213 [ h("span", { "class": { "material-icon": true } }, "fast_forward") ]
217 domTree
.push(navigator
);
224 this.displayStyle
= displayStyle
== "compact" ? "all" : "compact";
228 this.displayStyle
== "compact" ? "Show all" : "Navigator"
241 mounted: function() {
242 statementsLibsRefresh();
244 updated: function() {
245 statementsLibsRefresh();
248 inputId: function(i
,j
) {
249 return "q" + i
+ "_" + "input" + j
;