X-Git-Url: https://git.auder.net/pieces/Cwda/c_white_knight.svg?a=blobdiff_plain;f=public%2Fjavascripts%2Fassessment.js;h=2a451e4a19ad8df24be8ae4dcad59d93d0778533;hb=87d1063bdac629eca89c7ec0192fbc17e069a197;hp=93200cc8d52e35555e6d4b7583bec70ad8a442e4;hpb=20c96143f3ef4e652b4968bb994b0f70e008a861;p=qomet.git diff --git a/public/javascripts/assessment.js b/public/javascripts/assessment.js index 93200cc..2a451e4 100644 --- a/public/javascripts/assessment.js +++ b/public/javascripts/assessment.js @@ -23,19 +23,19 @@ new Vue({ // 2: locked: password set, exam started // 3: completed // 4: show answers + remainingTime: assessment.time, //integer or array stage: assessment.mode != "open" ? 0 : 1, - remainingTime: 0, //global, in seconds warnMsg: "", }, computed: { countdown: function() { - let seconds = this.remainingTime % 60; - let minutes = Math.floor(this.remainingTime / 60); + const remainingTime = assessment.display == "one" && _.isArray(assessment.time) + ? this.remainingTime[this.answers.index] + : this.remainingTime; + let seconds = remainingTime % 60; + let minutes = Math.floor(remainingTime / 60); return this.padWithZero(minutes) + ":" + this.padWithZero(seconds); }, - showAnswers: function() { - return this.stage == 4; - }, }, mounted: function() { $(".modal").modal(); @@ -46,7 +46,7 @@ new Vue({ return; if (assessment.mode == "secure") { - this.trySendCurrentAnswer(); + this.sendAnswer(); document.location.href= "/noblur"; } else //"watch" mode @@ -65,7 +65,7 @@ new Vue({ return; if (assessment.mode == "secure") { - this.trySendCurrentAnswer(); + this.sendAnswer(); document.location.href = "/fullscreen"; } else //"watch" mode @@ -78,7 +78,7 @@ new Vue({ }, false); }, methods: { - // In case of AJAX errors + // In case of AJAX errors (not blur-ing) showWarning: function(message) { this.warnMsg = message; $("#warning").modal("open"); @@ -88,13 +88,9 @@ new Vue({ return "0" + x; return x; }, - trySendCurrentAnswer: function() { - if (this.stage == 2) - this.sendAnswer(); - }, // stage 0 --> 1 - getStudent: function(cb) { - $.ajax("/get/student", { + getStudent: function() { + $.ajax("/courses/student", { method: "GET", data: { number: this.student.number, @@ -107,8 +103,6 @@ new Vue({ this.stage = 1; this.student = s.student; Vue.nextTick( () => { Materialize.updateTextFields(); }); - if (!!cb) - cb(); }, }); }, @@ -118,18 +112,14 @@ new Vue({ }, // stage 1 --> 2 (get all questions, set password) startAssessment: function() { - let initializeStage2 = (questions,paper) => { + let initializeStage2 = paper => { $("#leftButton, #rightButton").hide(); - if (assessment.time > 0) - { - -// TODO: distinguish total exam time AND question time - - const deltaTime = !!paper ? Date.now() - paper.startTime : 0; - this.remainingTime = assessment.time * 60 - Math.round(deltaTime / 1000); - this.runTimer(); - } // Initialize structured answer(s) based on questions type and nesting (TODO: more general) + + // if display == "all" getQuestionS + // otherwise get first question + + if (!!questions) assessment.questions = questions; this.answers.inputs = [ ]; @@ -148,6 +138,24 @@ new Vue({ let remainingIndices = _.difference( _.range(assessment.questions.length).map(String), indices ); this.answers.indices = indices.concat( _.shuffle(remainingIndices) ); } + + + + + + + + if (assessment.time > 0) + { + +// TODO: distinguish total exam time AND question time + + const deltaTime = !!paper ? Date.now() - paper.startTime : 0; + this.remainingTime = assessment.time * 60 - Math.round(deltaTime / 1000); + this.runTimer(); + } + + this.answers.index = !!paper ? paper.inputs.length : 0; this.answers.displayAll = assessment.display == "all"; this.answers.showSolution = false; @@ -155,8 +163,8 @@ new Vue({ }; if (assessment.mode == "open") return initializeStage2(); - $.ajax("/start/assessment", { - method: "GET", + $.ajax("/assessments/start", { + method: "PUT", data: { number: this.student.number, aid: assessment._id @@ -243,8 +251,8 @@ new Vue({ number: this.student.number, password: this.student.password, }; - $.ajax("/send/answer", { - method: "GET", + $.ajax("/assessments/answer", { + method: "PUT", data: answerData, dataType: "json", success: ret => { @@ -274,8 +282,8 @@ new Vue({ this.answers.displayAll = true; return; } - $.ajax("/end/assessment", { - method: "GET", + $.ajax("/assessments/end", { + method: "PUT", data: { aid: assessment._id, number: this.student.number,