Fix exam mode
authorBenjamin Auder <benjamin.auder@somewhere>
Sun, 28 Jan 2018 21:22:11 +0000 (22:22 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sun, 28 Jan 2018 21:22:11 +0000 (22:22 +0100)
entities/assessment.js
models/assessment.js
public/javascripts/assessment.js

index a8a781b..b4e3092 100644 (file)
@@ -127,7 +127,6 @@ const AssessmentEntity =
 
        startSession: function(aid, number, password, callback)
        {
-               // TODO: security, do not re-do tasks if already done
                db.assessments.update(
                        { _id: aid },
                        { $push: { papers: {
@@ -154,13 +153,11 @@ const AssessmentEntity =
                        (err,a) => {
                                if (!!err || !a)
                                        return cb(err,a);
-                               for (let p of a.papers)
+                               let papIdx = a.papers.findIndex( item => { return item.number == number; });
+                               for (let i of a.papers[papIdx].inputs)
                                {
-                                       for (let i of p.inputs)
-                                       {
-                                               if (i.index == idx)
-                                                       return cb(null,true);
-                                       }
+                                       if (i.index == idx)
+                                               return cb(null,true);
                                }
                                cb(null,false);
                        }
index a1a41e2..9269aee 100644 (file)
@@ -74,8 +74,8 @@ const AssessmentModel =
                                        return cb(err,null);
                                if (!!paper)
                                        return cb(null,{paper:paper,questions:questions});
-                               AssessmentEntity.startSession(aid, number, password, (err2,ret) => {
-                                       const pwd = TokenGen.generate(12); //arbitrary number, 12 seems enough...
+                               const pwd = TokenGen.generate(12); //arbitrary number, 12 seems enough...
+                               AssessmentEntity.startSession(aid, number, pwd, (err2,ret) => {
                                        cb(err2, {
                                                questions: questions,
                                                password: pwd,
@@ -87,7 +87,6 @@ const AssessmentModel =
 
        newAnswer: function(aid, number, password, input, cb)
        {
-               console.log(JSON.stringify(input));
                // Check that student hasn't already answered
                AssessmentEntity.hasInput(aid, number, password, input.index, (err,ret) => {
                        if (!!err)
@@ -95,7 +94,6 @@ const AssessmentModel =
                        if (!!ret)
                                return cb({errmsg:"Question already answered"},null);
                        AssessmentEntity.setInput(aid, number, password, input, (err2,ret2) => {
-                               console.log(JSON.stringify(ret2));
                                if (!!err2 || !ret2)
                                        return cb(err2,ret2);
                                return cb(null,ret2);
index 5fe24cd..1d62894 100644 (file)
@@ -193,14 +193,15 @@ new Vue({
                                },
                                // stage 2
                                sendAnswer: function(realIndex) {
-                                       console.log(realIndex);
-                                       if (assessment.index == assessment.questions.length - 1)
-                                               this.$emit("gameover");
-                                       else
-                                               assessment.index++;
-                                       this.$forceUpdate(); //TODO: shouldn't be required
+                                       let gotoNext = () => {
+                                               if (assessment.index == assessment.questions.length - 1)
+                                                       this.$emit("gameover");
+                                               else
+                                                       assessment.index++;
+                                               this.$forceUpdate(); //TODO: shouldn't be required
+                                       };
                                        if (assessment.mode == "open")
-                                               return; //only local
+                                               return gotoNext(); //only local
                                        let answerData = {
                                                aid: assessment._id,
                                                answer: JSON.stringify({
@@ -220,6 +221,8 @@ new Vue({
                                                success: ret => {
                                                        if (!!ret.errmsg)
                                                                return this.$emit("warning", ret.errmsg);
+                                                       else
+                                                               gotoNext();
                                                        //socket.emit(message.newAnswer, answer);
                                                },
                                        });