1 /*Draft format (compiled to json)
3 <some html question (or/+ exercise intro)>
5 <some html subQuestion>
6 * some answer [trigger input/index in answers]
21 <Some second question>
28 display: "evaluations", //or "students", or "grades" (admin mode)
31 newEvaluation: { name: "" },
32 evaluationArray: evaluationArray
,
33 mode: "view", //or "edit" (some evaluation)
34 evaluationIndex: 0, //current edited evaluation index
35 evaluation: { }, //copy of evaluation at editing index in array
36 questionsText: "", //questions in an evaluation, in text format
42 $('.modal').each( (i
,elem
) => {
43 if (elem
.id
!= "evaluationEdit")
46 $('ul.tabs').tabs(); //--> migrate to grade.js
50 $('#evaluationEdit').modal({
52 this.parseEvaluation();
53 Vue
.nextTick(statementsLibsRefresh
);
59 toggleDisplay: function(area
) {
60 if (this.display
== area
)
65 studentList: function(group
) {
66 return this.course
.students
67 .filter( s
=> { return group
==0 || s
.group
== group
; })
68 .map( s
=> { return Object
.assign({}, s
); }) //not altering initial array
69 .sort( (a
,b
) => { return a
.name
.localeCompare(b
.name
); })
72 uploadTrigger: function() {
76 let file
= (e
.target
.files
|| e
.dataTransfer
.files
)[0];
80 complete: (results
,file
) => {
82 // Post-process: add group/number if missing
84 results
.data
.forEach( d
=> {
89 if (typeof d
.number
!== "string")
90 d
.number
= d
.number
.toString();
93 $.ajax("/courses/student-list", {
97 students: JSON
.stringify(students
),
102 this.course
.students
= students
;
111 addEvaluation: function() {
114 // modal, fill code and description
115 let error
= Validator
.checkObject(this.newEvaluation
, "Evaluation");
119 $('#newEvaluation').modal('close');
120 $.ajax("/evaluations",
124 name: this.newEvaluation
.name
,
131 this.newEvaluation
["name"] = "";
132 this.evaluationArray
.push(res
);
140 materialOpenModal: function(id
) {
141 $("#" + id
).modal("open");
142 Materialize
.updateTextFields(); //textareas, time field...
144 updateEvaluation: function() {
145 $.ajax("/evaluations", {
147 data: {evaluation: JSON
.stringify(this.evaluation
)},
152 this.evaluationArray
[this.evaluationIndex
] = this.evaluation
;
160 deleteEvaluation: function(evaluation
) {
163 if (confirm("Delete evaluation '" + evaluation
.name
+ "' ?"))
165 $.ajax("/evaluations",
168 data: { qid: this.evaluation
._id
},
172 this.evaluationArray
.splice( this.evaluationArray
.findIndex( item
=> {
173 return item
._id
== evaluation
._id
;
182 toggleState: function(questionIndex
) {
183 // add or remove from activeSet of current evaluation
184 let activeIndex
= this.evaluation
.activeSet
.findIndex( item
=> { return item
== questionIndex
; });
185 if (activeIndex
>= 0)
186 this.evaluation
.activeSet
.splice(activeIndex
, 1);
188 this.evaluation
.activeSet
.push(questionIndex
);
190 setEvaluationText: function() {
192 this.evaluation
.questions
.forEach( q
=> {
193 txt
+= q
.wording
; //already ended by \n
194 q
.options
.forEach( (o
,i
) => {
195 let symbol
= q
.answer
.includes(i
) ? "+" : "-";
196 txt
+= symbol
+ " " + o
+ "\n";
198 txt
+= "\n"; //separate questions by new line
200 this.questionsText
= txt
;
202 parseEvaluation: function() {
204 let lines
= this.questionsText
.split("\n").map( L
=> { return L
.trim(); })
205 lines
.push(""); //easier parsing
206 let emptyQuestion
= () => {
211 active: true, //default
214 let q
= emptyQuestion();
215 lines
.forEach( L
=> {
218 if (['+','-'].includes(L
.charAt(0)))
220 if (L
.charAt(0) == '+')
221 q
.answer
.push(q
.options
.length
);
222 q
.options
.push(L
.slice(1).trim());
224 else if (L
.charAt(0) == '*')
226 // TODO: read current + next lines into q.answer (HTML, 1-elem array)
229 q
.wording
+= L
+ "\n";
233 // Flush current question (if any)
234 if (q
.wording
.length
> 0)
241 this.evaluation
.questions
= questions
;
243 actionEvaluation: function(index
) {
247 this.evaluationIndex
= index
;
248 this.evaluation
= $.extend(true, {}, this.evaluationArray
[index
]);
249 this.setEvaluationText();
251 Vue
.nextTick(statementsLibsRefresh
);
253 else //external user: show evaluation
254 this.redirect(this.evaluationArray
[index
].name
);
256 redirect: function(evaluationName
) {
257 document
.location
.href
= "/" + initials
+ "/" + course
.code
+ "/" + evaluationName
;
259 setPassword: function() {
260 let hashPwd
= Sha1
.Compute(this.monitorPwd
);
261 let error
= Validator
.checkObject({password:hashPwd
}, "Course");
262 if (error
.length
> 0)
264 $.ajax("/courses/password",
268 cid: this.course
._id
,
274 alert("Password saved!");
281 // NOTE: artifact required for Vue v-model to behave well
282 checkboxFixedId: function(i
) {
283 return "questionFixed" + i
;
285 checkboxActiveId: function(i
) {
286 return "questionActive" + i
;