Commit e54c5fc8 authored by Curtis Adam's avatar Curtis Adam
Browse files

Merge branch...

Merge branch '596-play-a-sound-for-answered-correctly-or-incorrectly-when-in-the-learning-phase-of-a-multiple' into 'staging'

Resolve "Play a sound for answered correctly or incorrectly when in the learning phase of a multiple choice quiz"

Closes #596

See merge request arsnova/cards!1138
parents a8c65cd6 46776896
......@@ -72,12 +72,7 @@ Meteor.methods({
if (leitnerTask !== undefined && card !== undefined && cardset !== undefined) {
userAnswers = userAnswers.sort();
let isAnswerWrong = false;
if (_.difference(userAnswers, card.answers.rightAnswers).length > 0 || userAnswers.length !== card.answers.rightAnswers.length) {
isAnswerWrong = true;
}
let isAnswerWrong = AnswerUtilities.isAnswerWrong(card.answers.rightAnswers, userAnswers);
let result = LeitnerUtilities.setNextBoxData(isAnswerWrong, activeLeitner, cardset);
Leitner.update({
......@@ -97,7 +92,7 @@ Meteor.methods({
}, {$set: {
timestamps: timestamps,
answer: isAnswerWrong ? 1 : 0,
"mcAnswers.user": userAnswers,
"mcAnswers.user": userAnswers.sort(),
"mcAnswers.card": card.answers.rightAnswers
}});
......
let randomizeByDefault = true;
let success;
let fail;
if (!Meteor.isServer) {
success = new Audio('/audio/correct-bell.mp3');
fail = new Audio('/audio/bad-bell.mp3');
}
module.exports = {
randomizeByDefault
randomizeByDefault,
success,
fail
};
......@@ -199,20 +199,26 @@ Template.learnAnswerOptions.helpers({
return Session.get('selectedAnswers').length > 0;
}
});
Template.learnAnswerOptions.events({
"click #learnSendAnswer": function () {
Session.set('isQuestionSide', false);
let timestamps = Session.get('leitnerHistoryTimestamps');
timestamps.answer = new Date();
Session.set('leitnerHistoryTimestamps', timestamps);
Meteor.call('setMCAnswers', CardIndex.getCardIndexFilter(), Session.get('activeCard'), FlowRouter.getParam('_id'), Session.get('selectedAnswers'), Session.get('leitnerHistoryTimestamps'), function (error, result) {
if (!error) {
Session.set('activeCardAnswers', result);
CardNavigation.resetNavigation(false);
$('html, body').animate({scrollTop: '0px'}, 300);
}
});
Meteor.call('setMCAnswers',
CardIndex.getCardIndexFilter(),
Session.get('activeCard'),
FlowRouter.getParam('_id'),
Session.get('selectedAnswers'),
Session.get('leitnerHistoryTimestamps'),
function (error, result) {
if (!error) {
Session.set('activeCardAnswers', result);
AnswerUtilities.playSound(result, Session.get('selectedAnswers'));
CardNavigation.resetNavigation(false);
$('html, body').animate({scrollTop: '0px'}, 300);
}
});
},
"click #nextMCCard": function () {
CardNavigation.switchCardMc(Session.get('activeCard'));
......
......@@ -8,9 +8,13 @@ import {CardVisuals} from "./cardVisuals";
import {CardType} from "./cardTypes";
import {Route} from "./route";
import shuffle from "knuth-shuffle-seeded";
import "/imports/api/meteorMethods/answers";
import {cubeTransitionTime, flipTransitionTime} from "../config/cardVisuals";
import * as answerConfig from "../config/answers";
let randomizedNumber = Math.random();
export let AnswerUtilities = class AnswerUtilities {
static setNewRandomizedNumber () {
randomizedNumber = Math.random();
......@@ -20,6 +24,14 @@ export let AnswerUtilities = class AnswerUtilities {
return shuffle(answers, cardId + randomizedNumber);
}
static isAnswerWrong (correctAnswers, selectedAnswers) {
let isAnswerWrong = true;
if (_.difference(selectedAnswers.sort(), correctAnswers.sort()).length > 0 || selectedAnswers.length !== correctAnswers.length) {
return isAnswerWrong;
}
}
/**
* Returns the answers of the requested cards
* @param cardIds Ids of the cards
......@@ -108,4 +120,31 @@ export let AnswerUtilities = class AnswerUtilities {
return gotMcQuestion;
}
}
static playSound (correctAnswers, selectedAnswers) {
let cardAnswers = [];
let transition;
if (Session.get('is3DActive')) {
transition = cubeTransitionTime * 1000;
} else if ((CardType.hasCardTwoSides(true, Session.get('cardType')))) {
transition = flipTransitionTime * 1000;
} else {
transition = 0;
}
correctAnswers.forEach(function (answers) {
if (answers._id === Session.get('activeCard')) {
cardAnswers = answers.answers.rightAnswers;
}
});
if (AnswerUtilities.isAnswerWrong(cardAnswers, selectedAnswers)) {
setTimeout(function () {
answerConfig.fail.play();
}, transition);
} else {
setTimeout(function () {
answerConfig.success.play();
}, transition);
}
}
};
......@@ -911,8 +911,7 @@
},
"minimist": {
"version": "1.2.0",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"resolved": "",
"dev": true
},
"repeating": {
......@@ -1577,8 +1576,7 @@
},
"kind-of": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
"resolved": ""
}
}
},
......@@ -4133,8 +4131,7 @@
},
"kind-of": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
"resolved": "",
"dev": true
},
"micromatch": {
......@@ -5908,8 +5905,7 @@
},
"kind-of": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
"resolved": "",
"dev": true
},
"micromatch": {
......@@ -9699,8 +9695,7 @@
},
"kind-of": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
"resolved": ""
}
}
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment