1 let socket
= null; //monitor answers in real time
6 password: "", //from password field
7 assessment: { }, //obtained after authentication
8 // Stage 0: unauthenticated (password),
9 // 1: authenticated (password hash validated), start monitoring
13 showSolution: true, //TODO: allow to hide, to let teachers search too
17 students: [ ], //to know their names
18 display: "assessment", //or student's answers
21 // TODO: redundant code, next 4 funcs already exist in course.js
22 toggleDisplay: function(area
) {
23 if (this.display
== area
)
28 studentList: function(group
) {
30 .filter( s
=> { return group
==0 || s
.group
== group
; })
31 .map( s
=> { return Object
.assign({}, s
); }) //not altering initial array
32 .sort( (a
,b
) => { return a
.name
.localeCompare(b
.name
); });
34 groupList: function() {
36 this.students
.forEach( s
=> {
40 return _
.range(1,maxGrp
+1);
42 groupId: function(group
, prefix
) {
43 return (prefix
|| "") + "group" + group
;
45 getColor: function(number
, qIdx
) {
46 // For the moment, green if correct and red if wrong; grey if unanswered yet
47 // TODO: in-between color for partially right (especially for multi-questions)
48 const paperIdx
= this.assessment
.papers
.findIndex( item
=> { return item
.number
== number
; });
50 return "grey"; //student didn't start yet
51 const inputIdx
= this.assessment
.papers
[paperIdx
].inputs
.findIndex( item
=> {
52 const qNum
= parseInt(item
.index
.split(".")[0]); //indexes separated by dots
57 if (_
.isEqual(this.assessment
.papers
[paperIdx
].inputs
[inputIdx
].input
, this.assessment
.questions
[qIdx
].answer
))
61 seeDetails: function(number
, i
) {
62 // UNIMPLEMENTED: see question details, with current answer(s)
65 startMonitoring: function() {
66 $.ajax("/start/monitoring", {
69 password: Sha1
.Compute(this.password
),
77 return alert(s
.errmsg
);
78 this.assessment
= s
.assessment
;
79 this.answers
.inputs
= s
.assessment
.questions
.map( q
=> {
80 let input
= _(q
.options
.length
).times( _
.constant(false) );
81 q
.answer
.forEach( idx
=> { input
[idx
] = true; });
84 this.students
= s
.students
;
86 socket
= io
.connect("/", {
87 query: "aid=" + this.assessment
._id
+ "&secret=" + s
.secret
89 socket
.on(message
.newAnswer
, m
=> {
90 let paperIdx
= this.assessment
.papers
.findIndex( item
=> {
91 return item
.number
== m
.number
;
96 paperIdx
= this.assessment
.papers
.length
;
97 this.assessment
.papers
.push({
99 inputs: [ ], //other fields irrelevant here
102 // TODO: notations not coherent (input / answer... when, which ?)
103 this.assessment
.papers
[paperIdx
].inputs
.push(JSON
.parse(m
.answer
)); //input+index
108 endMonitoring: function() {
109 // In the end, send answers to students
112 { answers: JSON
.stringify(this.assessment
.questions
.map( q
=> { return q
.answer
; })) }