el: "#assessment",
data: {
assessment: assessment,
- inputs: [ ], //student's answers
- student: { }, //filled later
+ answers: { }, //filled later with answering parameters
+ student: { }, //filled later (name, password)
// Stage 0: unauthenticated (number),
// 1: authenticated (got a name, unvalidated)
// 2: locked: password set, exam started
let minutes = Math.floor(this.remainingTime / 60);
return this.padWithZero(minutes) + ":" + this.padWithZero(seconds);
},
+ showAnswers: function() {
+ return this.stage == 4;
+ },
},
mounted: function() {
$(".modal").modal();
this.trySendCurrentAnswer();
document.location.href= "/fullscreen";
}, false);
- },
- trySendCurrentAnswer: function() {
- if (this.stage == 2)
- this.sendAnswer(assessment.indices[assessment.index]);
- },
},
methods: {
// In case of AJAX errors
return "0" + x;
return x;
},
+ trySendCurrentAnswer: function() {
+ if (this.stage == 2)
+ this.sendAnswer(assessment.indices[assessment.index]);
+ },
// stage 0 --> 1
getStudent: function(cb) {
$.ajax("/get/student", {
// Initialize structured answer(s) based on questions type and nesting (TODO: more general)
if (!!questions)
assessment.questions = questions;
+ this.answers.inputs = [ ];
for (let q of assessment.questions)
this.inputs.push( _(q.options.length).times( _.constant(false) ) );
if (!paper)
{
- assessment.indices = assessment.fixed
+ this.answers.indices = assessment.fixed
? _.range(assessment.questions.length)
: _.shuffle( _.range(assessment.questions.length) );
}
// Resuming
let indices = paper.inputs.map( input => { return input.index; });
let remainingIndices = _.difference( _.range(assessment.questions.length).map(String), indices );
- assessment.indices = indices.concat( _.shuffle(remainingIndices) );
+ this.answers.indices = indices.concat( _.shuffle(remainingIndices) );
}
- assessment.index = !!paper ? paper.inputs.length : 0;
+ this.answers.index = !!paper ? paper.inputs.length : 0;
Vue.nextTick(libsRefresh);
this.stage = 2;
};
{
// Resuming: receive stored answers + startTime
this.student.password = s.paper.password;
- this.inputs = s.paper.inputs.map( inp => { return inp.input; });
+ this.answers.inputs = s.paper.inputs.map( inp => { return inp.input; });
}
else
{
sendAnswer: function(realIndex) {
let gotoNext = () => {
if (assessment.index == assessment.questions.length - 1)
- this.$emit("gameover");
+ this.endAssessment();
else
assessment.index++;
this.$forceUpdate(); //TODO: shouldn't be required
Vue.component("statements", {
- props: ['questions','inputs','showAnswers','index'], // index=-1 : show all, otherwise show current question
+ // 'answers' is an object containing
+ // 'inputs'(array),
+ // 'displayAll'(bool),
+ // 'showSolution'(bool),
+ // 'indices': order of appearance
+ // 'index': current integer index (focused question)
+ props: ['questions','answers'],
// TODO: general render function for nested exercises
// There should be a questions navigator below, or next (visible if display=='all')
// Full questions tree is rendered, but some parts hidden depending on display settings
render(h) {
+ // TODO: render nothing if answers is empty
let domTree = this.questions.map( (q,i) => {
let questionContent = [ ];
questionContent.push(
"input",
{
domProps: {
- checked: this.inputs.length > 0 && this.inputs[i][idx],
+ checked: this.answers.inputs.length > 0 && this.answers.inputs[i][idx],
disabled: monitoring,
},
attrs: {
type: "checkbox",
},
on: {
- change: e => { this.inputs[i][idx] = e.target.checked; },
+ change: e => { this.answers.inputs[i][idx] = e.target.checked; },
},
},
)
{
"class": {
option: true,
- choiceCorrect: showAnswers && this.questions[i].answer.includes(idx),
- choiceWrong: showAnswers && this.inputs[i][idx] && !questions[i].answer.includes(idx),
+ choiceCorrect: this.answers.showSolution && this.questions[i].answer.includes(idx),
+ choiceWrong: this.answers.showSolution && this.inputs[i][idx] && !q.answer.includes(idx),
},
},
option
{
"class": {
"question": true,
- "hide": index >= 0 && index != i,
+ "hide": !this.answers.displayAll && this.answers.index != i,
},
},
questionContent