Added overall feedback to question set + bonus fixes [HFP-1174]

pull/15/head
Paal Joergensen 2017-07-03 15:09:49 +02:00
parent 8ca94b1079
commit 9401e5abe3
5 changed files with 116 additions and 45 deletions

View File

@ -225,30 +225,27 @@
font-size: 1.25em; font-size: 1.25em;
} }
.questionset-results .feedback-section .feedback-text {
font-weight: normal;
color: #777;
}
.questionset-results .buttons { .questionset-results .buttons {
margin-bottom: 1.5em; margin: 2em 0 1em 0;
} }
.questionset-results .result-header, .questionset-results .result-header,
.questionset-results .result-text { .questionset-results .result-text,
.questionset-results .feedback-section .feedback-text {
color: #1a73d9; color: #1a73d9;
font-weight: bold; font-weight: bold;
} }
.questionset-results .result-header { .questionset-results .result-header {
font-size: 2em; font-size: 2em;
margin-top: 1em; margin: 1em 0.5em 0.5em 0.5em;
} }
.questionset-results .result-text { .questionset-results .result-text,
.questionset-results .feedback-section .feedback-text {
font-size: 1.25em; font-size: 1.25em;
line-height: 1.25em; line-height: 1.25em;
margin: 1em 1em 2.25em; margin: 1em;
} }
/* No margin for questions when no frame */ /* No margin for questions when no frame */

View File

@ -112,11 +112,11 @@ H5P.QuestionSet = function (options, contentId, contentData) {
showResultPage: true, showResultPage: true,
noResultMessage: 'Finished', noResultMessage: 'Finished',
message: 'Your result:', message: 'Your result:',
successGreeting: 'Congratulations!', successGreeting: '',
successComment: 'You have enough correct answers to pass the test.', successComment: '',
failGreeting: 'Sorry!', failGreeting: '',
failComment: "You don't have enough correct answers to pass this test.", failComment: '',
scoreString: 'You got @score of @total points', overallFeedback: [],
finishButtonText: 'Finish', finishButtonText: 'Finish',
solutionButtonText: 'Show solution', solutionButtonText: 'Show solution',
retryButtonText: 'Retry', retryButtonText: 'Retry',
@ -420,13 +420,17 @@ H5P.QuestionSet = function (options, contentId, contentData) {
var hasAutoPlay = currentQuestion var hasAutoPlay = currentQuestion
&& currentQuestion.params.media && currentQuestion.params.media
&& currentQuestion.params.media.params
&& currentQuestion.params.media.params.playback
&& currentQuestion.params.media.params.playback.autoplay; && currentQuestion.params.media.params.playback.autoplay;
if (hasAutoPlay) { if (hasAutoPlay && typeof questionInstances[currentQuestionIndex].play === 'function') {
questionInstances[currentQuestionIndex].play(); questionInstances[currentQuestionIndex].play();
} }
}; };
/** /**
* Show solutions for subcontent, and hide subcontent buttons. * Show solutions for subcontent, and hide subcontent buttons.
* Used for contracts with integrated content. * Used for contracts with integrated content.
@ -703,12 +707,9 @@ H5P.QuestionSet = function (options, contentId, contentData) {
// Get total score. // Get total score.
var finals = self.getScore(); var finals = self.getScore();
var totals = self.getMaxScore(); var totals = self.getMaxScore();
var scoreString = params.endGame.scoreString.replace("@score", finals).replace("@total", totals);
var scoreString = H5P.Question.determineOverallFeedback(params.endGame.overallFeedback, finals / totals).replace('@score', finals).replace('@total', totals);
var success = ((100 * finals / totals) >= params.passPercentage); var success = ((100 * finals / totals) >= params.passPercentage);
var eventData = {
score: scoreString,
passed: success
};
/** /**
* Makes our buttons behave like other buttons. * Makes our buttons behave like other buttons.
@ -743,10 +744,6 @@ H5P.QuestionSet = function (options, contentId, contentData) {
$myDom.append(endTemplate.render(eparams)); $myDom.append(endTemplate.render(eparams));
if (params.endGame.showResultPage) { if (params.endGame.showResultPage) {
// Add event handlers to summary buttons
hookUpButton('.qs-finishbutton', function () {
self.trigger('h5pQuestionSetFinished', eventData);
});
hookUpButton('.qs-solutionbutton', function () { hookUpButton('.qs-solutionbutton', function () {
showSolutions(); showSolutions();
$myDom.children().hide().filter('.questionset').show(); $myDom.children().hide().filter('.questionset').show();

View File

@ -14,7 +14,7 @@
"author": "Joubel", "author": "Joubel",
"coreApi": { "coreApi": {
"majorVersion": 1, "majorVersion": 1,
"minorVersion": 6 "minorVersion": 14
}, },
"license": "MIT", "license": "MIT",
"preloadedJs": [ "preloadedJs": [
@ -50,6 +50,11 @@
} }
], ],
"editorDependencies": [ "editorDependencies": [
{
"machineName": "H5PEditor.RangeList",
"majorVersion": 1,
"minorVersion": 0
},
{ {
"machineName": "H5PEditor.VerticalTabs", "machineName": "H5PEditor.VerticalTabs",
"majorVersion": 1, "majorVersion": 1,
@ -61,4 +66,4 @@
"minorVersion": 2 "minorVersion": 2
} }
] ]
} }

View File

@ -122,7 +122,7 @@
"description": "Library for this question.", "description": "Library for this question.",
"options": [ "options": [
"H5P.MultiChoice 1.9", "H5P.MultiChoice 1.9",
"H5P.DragQuestion 1.10", "H5P.DragQuestion 1.11",
"H5P.Blanks 1.7", "H5P.Blanks 1.7",
"H5P.MarkTheWords 1.6", "H5P.MarkTheWords 1.6",
"H5P.DragText 1.5", "H5P.DragText 1.5",
@ -276,7 +276,6 @@
"label": "Feedback heading", "label": "Feedback heading",
"importance": "low", "importance": "low",
"default": "Your result:", "default": "Your result:",
"optional": true,
"description": "This heading will be displayed at the end of the quiz when the user has answered all questions.", "description": "This heading will be displayed at the end of the quiz when the user has answered all questions.",
"tags": [ "tags": [
"strong", "strong",
@ -284,27 +283,74 @@
] ]
}, },
{ {
"name": "scoreString", "name": "overallFeedback",
"type": "text", "type": "group",
"label": "Score display text", "label": "Overall Feedback",
"importance": "low", "importance": "low",
"description": "Text used to display Total user score. \"@score\" will be replaced by calculated score, \"@total\" will be replaced by maximum possible score. ", "fields": [
"default": "You got @score of @total points", {
"optional": true "name": "overallFeedback",
"type": "list",
"widgets": [
{
"name": "RangeList",
"label": "Default"
}
],
"importance": "high",
"label": "Define custom feedback for any score range",
"description": "Example: 0-20% Bad score, 21-91% Average Score, 91-100% Great Score!",
"entity": "range",
"min": 1,
"defaultNum": 1,
"optional": true,
"field": {
"name": "overallFeedback",
"type": "group",
"importance": "low",
"fields": [
{
"name": "from",
"type": "number",
"label": "Score Range",
"min": 0,
"max": 100,
"default": 0,
"unit": "%"
},
{
"name": "to",
"type": "number",
"min": 0,
"max": 100,
"default": 100,
"unit": "%"
},
{
"name": "feedback",
"type": "text",
"label": "Feedback for defined score range",
"importance": "low",
"placeholder": "Fill in the feedback",
"optional": true
}
]
}
}
]
}, },
{ {
"name": "successGreeting", "name": "successGreeting",
"type": "text", "type": "text",
"label": "Quiz passed greeting", "label": "Quiz passed greeting",
"importance": "low", "importance": "low",
"placeholder": "Congratulations!",
"default": "Congratulations!",
"optional": true, "optional": true,
"description": "This text will be displayed above the score if the user has successfully passed the quiz.", "description": "This text will be displayed above the score if the user has successfully passed the quiz.",
"tags": [ "tags": [
"strong", "strong",
"em" "em"
] ],
"deprecated": true
}, },
{ {
"name": "successComment", "name": "successComment",
@ -312,7 +358,6 @@
"widget": "html", "widget": "html",
"label": "Passed comment", "label": "Passed comment",
"importance": "low", "importance": "low",
"default": "You did very well!",
"optional": true, "optional": true,
"description": "This comment will be displayed after the score if the user has successfully passed the quiz.", "description": "This comment will be displayed after the score if the user has successfully passed the quiz.",
"tags": [ "tags": [
@ -322,20 +367,21 @@
"em", "em",
"a", "a",
"p" "p"
] ],
"deprecated": true
}, },
{ {
"name": "failGreeting", "name": "failGreeting",
"type": "text", "type": "text",
"label": "Quiz failed title", "label": "Quiz failed title",
"importance": "low", "importance": "low",
"default": "You did not pass this time.",
"optional": true, "optional": true,
"description": "This text will be displayed above the score if the user has failed the quiz.", "description": "This text will be displayed above the score if the user has failed the quiz.",
"tags": [ "tags": [
"strong", "strong",
"em" "em"
] ],
"deprecated": true
}, },
{ {
"name": "failComment", "name": "failComment",
@ -343,7 +389,6 @@
"widget": "html", "widget": "html",
"label": "Failed comment", "label": "Failed comment",
"importance": "low", "importance": "low",
"default": "Have another try!",
"optional": true, "optional": true,
"description": "This comment will be displayed after the score if the user has failed the quiz.", "description": "This comment will be displayed after the score if the user has failed the quiz.",
"tags": [ "tags": [
@ -353,7 +398,8 @@
"em", "em",
"a", "a",
"p" "p"
] ],
"deprecated": true
}, },
{ {
"name": "solutionButtonText", "name": "solutionButtonText",
@ -460,4 +506,4 @@
} }
] ]
} }
] ]

View File

@ -52,6 +52,32 @@ H5PUpgrades['H5P.QuestionSet'] = (function ($) {
// Remove old copyright dialog question label // Remove old copyright dialog question label
delete parameters.questionLabel; delete parameters.questionLabel;
finished(null, parameters);
},
/**
* Asynchronous content upgrade hook.
*
* Upgrade params to support overall feedback
*
* @param {Object} parameters
* @param {function} finished
*/
13: function (parameters, finished) {
parameters.endGame = parameters.endGame || {};
parameters.endGame.overallFeedback = [];
if (parameters.endGame.scoreString) {
parameters.endGame.overallFeedback.push({
from: 0,
to: 100,
feedback: parameters.endGame.scoreString
});
delete parameters.endGame.scoreString;
}
finished(null, parameters); finished(null, parameters);
} }
} }