From 25cb8d539e4f68586f2e5fa95e20f6de3c031b6f Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Tue, 13 Feb 2018 11:37:42 +0100
Subject: [PATCH] Draft logic to toggle students presence in exam + send
 answers only if everyone finished

---
 public/javascripts/monitor.js | 18 ++++++++++++++++++
 views/monitor.pug             |  4 ++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/public/javascripts/monitor.js b/public/javascripts/monitor.js
index 1b8d62f..b5a0fe4 100644
--- a/public/javascripts/monitor.js
+++ b/public/javascripts/monitor.js
@@ -42,6 +42,23 @@ new Vue({
 		groupId: function(group, prefix) {
 			return (prefix || "") + "group" + group;
 		},
+		togglePresence: function(s) {
+			s.present = !s.present;
+		},
+		allFinished: function() {
+			for (s of this.students)
+			{
+				if (!s.present)
+					continue;
+				const paperIdx = this.assessment.papers.findIndex( item => { return item.number == number; });
+				if (paperIdx === -1)
+					return false;
+				const paper = this.assessment.papers[paperIdx];
+				if (paper.inputs.length < this.assessment.questions.length)
+					return false;
+			}
+			return true;
+		},
 		getColor: function(number, qIdx) {
 			// For the moment, green if correct and red if wrong; grey if unanswered yet
 			// TODO: in-between color for partially right (especially for multi-questions)
@@ -82,6 +99,7 @@ new Vue({
 						return input;
 					});
 					this.students = s.students;
+					this.students.forEach( s => { s.present = true; }); //a priori...
 					this.stage = 1;
 					socket = io.connect("/", {
 						query: "aid=" + this.assessment._id + "&secret=" + s.secret
diff --git a/views/monitor.pug b/views/monitor.pug
index 7b257ec..00bf476 100644
--- a/views/monitor.pug
+++ b/views/monitor.pug
@@ -15,7 +15,7 @@ block content
 							input#password(type="password" v-model="password" @keyup.enter="startMonitoring()")
 						button.waves-effect.waves-light.btn(@click="startMonitoring()") Send
 				#stage1(v-show="stage==1")
-					button.waves-effect.waves-light.btn(@click="endMonitoring()") Send feedback
+					button.waves-effect.waves-light.btn(@click="endMonitoring()" :disabled="!allFinished()") Send feedback
 					h4.title(@click="toggleDisplay('answers')") Anwers
 					// TODO: aussi afficher stats, permettre tri par colonnes
 					.card(v-show="display=='answers'")
@@ -31,7 +31,7 @@ block content
 									th(v-for="(q,i) in assessment.questions") Q.{{ (i+1) }}
 							tbody
 								tr.assessment(v-for="s in studentList(group)")
-									td(:class="{blur:!!s.blur,resize:!!s.resize,disconnect:!!s.disco}") {{ s.name }}
+									td(:class="{blur:!!s.blur,resize:!!s.resize,disconnect:!!s.disco}" @click="togglePresence(s)") {{ s.name }}
 									td(v-for="(q,i) in assessment.questions" :style="{backgroundColor: getColor(s.number,i)}" @click="seeDetails(s.number,i)") &nbsp;
 					h4.title(@click="toggleDisplay('assessment')") Assessment
 					div(v-show="display=='assessment'")
-- 
2.44.0