9b3964bb259593d040576eaf5d0cd40c970a357a
1 let socket
= null; //monitor answers in real time
6 password: "", //from password field
7 evaluation: { }, //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: "evaluation", //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 togglePresence: function(student
) {
46 const sIdx
= this.students
.findIndex( s
=> { return s
.number
== student
.number
; });
47 Vue
.set( this.students
, sIdx
, Object
.assign({},student
,{present:!student
.present
}) );
48 //s.present = !s.present;
50 allFinished: function() {
51 for (s
of this.students
)
55 const paperIdx
= this.evaluation
.papers
.findIndex( item
=> { return item
.number
== s
.number
; });
58 const paper
= this.evaluation
.papers
[paperIdx
];
59 if (paper
.inputs
.length
< this.evaluation
.questions
.length
)
64 getColor: function(number
, qIdx
) {
65 // For the moment, green if correct and red if wrong; grey if unanswered yet
66 // TODO: in-between color for partially right (especially for multi-questions)
67 const paperIdx
= this.evaluation
.papers
.findIndex( item
=> { return item
.number
== number
; });
69 return "grey"; //student didn't start yet
70 const inputIdx
= this.evaluation
.papers
[paperIdx
].inputs
.findIndex( item
=> {
71 const qNum
= parseInt(item
.index
.split(".")[0]); //indexes separated by dots
76 if (_
.isEqual(this.evaluation
.papers
[paperIdx
].inputs
[inputIdx
].input
, this.evaluation
.questions
[qIdx
].answer
))
80 seeDetails: function(number
, i
) {
81 // UNIMPLEMENTED: see question details, with current answer(s)
84 startMonitoring: function() {
85 $.ajax("/evaluations/monitor", {
88 password: Sha1
.Compute(this.password
),
96 return alert(s
.errmsg
);
97 this.evaluation
= s
.evaluation
;
98 this.answers
.inputs
= s
.evaluation
.questions
.map( q
=> {
99 let input
= _(q
.options
.length
).times( _
.constant(false) );
100 q
.answer
.forEach( idx
=> { input
[idx
] = true; });
103 this.students
= s
.students
;
104 this.students
.forEach( s
=> { s
.present
= true; }); //a priori...
106 socket
= io
.connect("/", {
107 query: "aid=" + this.evaluation
._id
+ "&secret=" + s
.secret
109 socket
.on(message
.studentBlur
, m
=> {
110 const sIdx
= this.students
.findIndex( item
=> { return item
.number
== m
.number
; });
111 Vue
.set(this.students
, sIdx
, Object
.assign({},this.students
[sIdx
],{blur: true}));
112 //this.students[sIdx].blur = true;
114 socket
.on(message
.studentFocus
, m
=> {
115 const sIdx
= this.students
.findIndex( item
=> { return item
.number
== m
.number
; });
116 this.students
[sIdx
].blur
= false;
118 socket
.on(message
.studentResize
, m
=> {
119 const sIdx
= this.students
.findIndex( item
=> { return item
.number
== m
.number
; });
120 Vue
.set(this.students
, sIdx
, Object
.assign({},this.students
[sIdx
],{resize: true}));
121 //this.students[sIdx].resize = true;
123 socket
.on(message
.studentFullscreen
, m
=> {
124 const sIdx
= this.students
.findIndex( item
=> { return item
.number
== m
.number
; });
125 this.students
[sIdx
].resize
= false;
127 socket
.on(message
.studentDisconnect
, m
=> {
128 const sIdx
= this.students
.findIndex( item
=> { return item
.number
== m
.number
; });
129 Vue
.set(this.students
, sIdx
, Object
.assign({},this.students
[sIdx
],{disco: true}));
130 //this.students[sIdx].disco = true;
132 socket
.on(message
.studentConnect
, m
=> {
133 const sIdx
= this.students
.findIndex( item
=> { return item
.number
== m
.number
; });
134 this.students
[sIdx
].disco
= false;
136 socket
.on(message
.newAnswer
, m
=> {
137 let paperIdx
= this.evaluation
.papers
.findIndex( item
=> {
138 return item
.number
== m
.number
;
143 paperIdx
= this.evaluation
.papers
.length
;
144 this.evaluation
.papers
.push({
146 inputs: [ ], //other fields irrelevant here
149 // TODO: notations not coherent (input / answer... when, which ?)
150 this.evaluation
.papers
[paperIdx
].inputs
.push(JSON
.parse(m
.answer
)); //input+index
155 endMonitoring: function() {
156 // In the end, send answers to students
157 // TODO: disable this button until everyone finished (need ability to mark absents)
160 { answers: JSON
.stringify(this.evaluation
.questions
.map( q
=> { return q
.answer
; })) }