63205385fdd7e722e81d63c1bf0005949be638b0
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
50 $('.modal').each( (i
,elem
) => {
51 if (elem
.id
!= "evaluationEdit")
54 $('ul.tabs').tabs(); //--> migrate to grade.js
58 $('#evaluationEdit').modal({
60 this.parseEvaluation();
61 Vue
.nextTick(statementsLibsRefresh
);
67 toggleDisplay: function(area
) {
68 if (this.display
== area
)
73 studentList: function(group
) {
74 return this.course
.students
75 .filter( s
=> { return group
==0 || s
.group
== group
; })
76 .map( s
=> { return Object
.assign({}, s
); }) //not altering initial array
77 .sort( (a
,b
) => { return a
.name
.localeCompare(b
.name
); })
80 uploadTrigger: function() {
84 let file
= (e
.target
.files
|| e
.dataTransfer
.files
)[0];
88 complete: (results
,file
) => {
90 // Post-process: add group/number if missing
92 results
.data
.forEach( d
=> {
97 if (typeof d
.number
!== "string")
98 d
.number
= d
.number
.toString();
101 $.ajax("/courses/student-list", {
104 cid: this.course
._id
,
105 students: JSON
.stringify(students
),
110 this.course
.students
= students
;
119 addEvaluation: function() {
122 // modal, fill code and description
123 let error
= Validator
.checkObject(this.newEvaluation
, "Evaluation");
127 $('#newEvaluation').modal('close');
128 $.ajax("/evaluations",
132 name: this.newEvaluation
.name
,
139 this.newEvaluation
["name"] = "";
140 this.evaluationArray
.push(res
);
148 materialOpenModal: function(id
) {
149 $("#" + id
).modal("open");
150 Materialize
.updateTextFields(); //textareas, time field...
152 updateEvaluation: function() {
153 $.ajax("/evaluations", {
155 data: {evaluation: JSON
.stringify(this.evaluation
)},
160 this.evaluationArray
[this.evaluationIndex
] = this.evaluation
;
168 deleteEvaluation: function(evaluation
) {
171 if (confirm("Delete evaluation '" + evaluation
.name
+ "' ?"))
173 $.ajax("/evaluations",
176 data: { qid: this.evaluation
._id
},
180 this.evaluationArray
.splice( this.evaluationArray
.findIndex( item
=> {
181 return item
._id
== evaluation
._id
;
190 toggleState: function(questionIndex
) {
191 // add or remove from activeSet of current evaluation
192 let activeIndex
= this.evaluation
.activeSet
.findIndex( item
=> { return item
== questionIndex
; });
193 if (activeIndex
>= 0)
194 this.evaluation
.activeSet
.splice(activeIndex
, 1);
196 this.evaluation
.activeSet
.push(questionIndex
);
198 setEvaluationText: function() {
200 this.evaluation
.questions
.forEach( q
=> {
201 txt
+= q
.wording
; //already ended by \n
202 q
.options
.forEach( (o
,i
) => {
203 let symbol
= q
.answer
.includes(i
) ? "+" : "-";
204 txt
+= symbol
+ " " + o
+ "\n";
206 txt
+= "\n"; //separate questions by new line
208 this.questionsText
= txt
;
210 parseEvaluation: function() {
212 let lines
= this.questionsText
.split("\n").map( L
=> { return L
.trim(); })
213 lines
.push(""); //easier parsing
214 let emptyQuestion
= () => {
219 active: true, //default
222 let q
= emptyQuestion();
223 lines
.forEach( L
=> {
226 if (['+','-'].includes(L
.charAt(0)))
228 if (L
.charAt(0) == '+')
229 q
.answer
.push(q
.options
.length
);
230 q
.options
.push(L
.slice(1).trim());
232 else if (L
.charAt(0) == '*')
234 // TODO: read current + next lines into q.answer (HTML, 1-elem array)
237 q
.wording
+= L
+ "\n";
241 // Flush current question (if any)
242 if (q
.wording
.length
> 0)
249 this.evaluation
.questions
= questions
;
251 actionEvaluation: function(index
) {
255 this.evaluationIndex
= index
;
256 this.evaluation
= $.extend(true, {}, this.evaluationArray
[index
]);
257 this.setEvaluationText();
259 Vue
.nextTick(statementsLibsRefresh
);
261 else //external user: show evaluation
262 this.redirect(this.evaluationArray
[index
].name
);
264 redirect: function(evaluationName
) {
265 document
.location
.href
= "/" + initials
+ "/" + course
.code
+ "/" + evaluationName
;
267 setPassword: function() {
268 let hashPwd
= Sha1
.Compute(this.monitorPwd
);
269 let error
= Validator
.checkObject({password:hashPwd
}, "Course");
270 if (error
.length
> 0)
272 $.ajax("/courses/password",
276 cid: this.course
._id
,
282 alert("Password saved!");
289 // NOTE: artifact required for Vue v-model to behave well
290 checkboxFixedId: function(i
) {
291 return "questionFixed" + i
;
293 checkboxActiveId: function(i
) {
294 return "questionActive" + i
;