1 /*Draft format (compiled to json)
2 * TODO: separate questions and answers in Evaluation object
4 <some html question (or/+ exercise intro)>
6 <some html subQuestion>
7 * some answer [trigger input/index in answers]
17 <another sub sub> with params interpolation £ (tout simplement)
18 / params: javascript parameter generator (another function, body only)
23 <Some second question>
26 dans le cas de parametetrized, answer est une fonction javascript !! qui prend en arg le(s) param(s)
27 coté serveur on stock parameterized question + body func
28 une fois côté client, extra work first to 1) execute each func 2) replace (and store!!!) all params
29 https://stackoverflow.com/questions/7650071/is-there-a-way-to-create-a-function-from-a-string-with-javascript
36 display: "evaluations", //or "students" (in admin mode)
39 newEvaluation: { name: "" },
40 evaluationArray: evaluationArray
,
41 mode: "view", //or "edit" (some evaluation)
42 evaluationIndex: 0, //current edited evaluation index
43 evaluation: { }, //copy of evaluation at editing index in array
44 questionsText: "", //questions in an evaluation, in text format
48 Materialize
.updateTextFields(); //textareas, time field...
52 toggleDisplay: function(area
) {
53 if (this.display
== area
)
58 studentList: function(group
) {
59 return this.course
.students
60 .filter( s
=> { return group
==0 || s
.group
== group
; })
61 .map( s
=> { return Object
.assign({}, s
); }) //not altering initial array
62 .sort( (a
,b
) => { return a
.name
.localeCompare(b
.name
); })
65 uploadTrigger: function() {
69 let file
= (e
.target
.files
|| e
.dataTransfer
.files
)[0];
73 complete: (results
,file
) => {
75 // Post-process: add group/number if missing
77 results
.data
.forEach( d
=> {
82 if (typeof d
.number
!== "string")
83 d
.number
= d
.number
.toString();
86 $.ajax("/courses/student-list", {
90 students: JSON
.stringify(students
),
95 this.course
.students
= students
;
104 addEvaluation: function() {
107 // modal, fill code and description
108 let error
= Validator
.checkObject(this.newEvaluation
, "Evaluation");
112 $('#newEvaluation').modal('close');
113 $.ajax("/evaluations",
117 name: this.newEvaluation
.name
,
124 this.newEvaluation
["name"] = "";
125 this.evaluationArray
.push(res
);
133 updateEvaluation: function() {
134 $.ajax("/evaluations", {
136 data: {evaluation: JSON
.stringify(this.evaluation
)},
141 this.evaluationArray
[this.evaluationIndex
] = this.evaluation
;
149 deleteEvaluation: function(evaluation
) {
152 if (confirm("Delete evaluation '" + evaluation
.name
+ "' ?"))
154 $.ajax("/evaluations",
157 data: { qid: this.evaluation
._id
},
161 this.evaluationArray
.splice( this.evaluationArray
.findIndex( item
=> {
162 return item
._id
== evaluation
._id
;
171 toggleState: function(questionIndex
) {
172 // add or remove from activeSet of current evaluation
173 let activeIndex
= this.evaluation
.activeSet
.findIndex( item
=> { return item
== questionIndex
; });
174 if (activeIndex
>= 0)
175 this.evaluation
.activeSet
.splice(activeIndex
, 1);
177 this.evaluation
.activeSet
.push(questionIndex
);
179 setEvaluationText: function() {
181 this.evaluation
.questions
.forEach( q
=> {
182 txt
+= q
.wording
; //already ended by \n
183 q
.options
.forEach( (o
,i
) => {
184 let symbol
= q
.answer
.includes(i
) ? "+" : "-";
185 txt
+= symbol
+ " " + o
+ "\n";
187 txt
+= "\n"; //separate questions by new line
189 this.questionsText
= txt
;
191 parseEvaluation: function() {
193 let lines
= this.questionsText
.split("\n").map( L
=> { return L
.trim(); })
194 lines
.push(""); //easier parsing
195 let emptyQuestion
= () => {
200 active: true, //default
203 let q
= emptyQuestion();
204 lines
.forEach( L
=> {
207 if (['+','-'].includes(L
.charAt(0)))
209 if (L
.charAt(0) == '+')
210 q
.answer
.push(q
.options
.length
);
211 q
.options
.push(L
.slice(1).trim());
213 else if (L
.charAt(0) == '*')
215 // TODO: read current + next lines into q.answer (HTML, 1-elem array)
218 q
.wording
+= L
+ "\n";
222 // Flush current question (if any)
223 if (q
.wording
.length
> 0)
230 this.evaluation
.questions
= questions
;
232 actionEvaluation: function(index
) {
236 this.evaluationIndex
= index
;
237 this.evaluation
= $.extend(true, {}, this.evaluationArray
[index
]);
238 this.setEvaluationText();
240 Vue
.nextTick(statementsLibsRefresh
);
242 else //external user: show evaluation
243 this.redirect(this.evaluationArray
[index
].name
);
245 redirect: function(evaluationName
) {
246 document
.location
.href
= "/" + initials
+ "/" + course
.code
+ "/" + evaluationName
;
248 setPassword: function() {
249 let hashPwd
= Sha1
.Compute(this.monitorPwd
);
250 let error
= Validator
.checkObject({password:hashPwd
}, "Course");
251 if (error
.length
> 0)
253 $.ajax("/courses/password",
257 cid: this.course
._id
,
263 alert("Password saved!");
270 // NOTE: artifact required for Vue v-model to behave well
271 checkboxFixedId: function(i
) {
272 return "questionFixed" + i
;
274 checkboxActiveId: function(i
) {
275 return "questionActive" + i
;