startSession: function(aid, number, password, callback)
{
- // TODO: security, do not re-do tasks if already done
db.assessments.update(
{ _id: aid },
{ $push: { papers: {
(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);
}
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,
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)
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);
},
// 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({
success: ret => {
if (!!ret.errmsg)
return this.$emit("warning", ret.errmsg);
+ else
+ gotoNext();
//socket.emit(message.newAnswer, answer);
},
});