From 31acbd4d29ad4903c58a33fa77d76ce119a380a8 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Thu, 28 Jul 2016 09:26:54 +0100 Subject: [PATCH 1/8] Add reset button --- js/summary.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++---- library.json | 6 ++--- todo.txt | 1 + 3 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 todo.txt diff --git a/js/summary.js b/js/summary.js index e5e6ddd..4d19659 100644 --- a/js/summary.js +++ b/js/summary.js @@ -1,4 +1,4 @@ -H5P.Summary = (function ($, Question) { +H5P.Summary = (function ($, Question, JoubelUI) { function Summary(options, contentId, contentData) { if (!(this instanceof H5P.Summary)) { @@ -19,7 +19,7 @@ H5P.Summary = (function ($, Question) { return element.summary !== undefined; }); } - + if (contentData && contentData.previousState !== undefined && contentData.previousState.progress !== undefined && contentData.previousState.answers) { @@ -113,6 +113,15 @@ H5P.Summary = (function ($, Question) { Summary.prototype.registerDomElements = function () { // Register task content area this.setContent(this.createQuestion()); + + // Register retry button to h5p question + var self = this; + this.addButton('try-again', 'retry', function () { + + // Remove button after is has been clicked + self.hideButton('try-again'); + self.resetTask(); + }, false); }; // Function for attaching the multichoice to a DOM element. @@ -189,6 +198,12 @@ H5P.Summary = (function ($, Question) { * Used when alt was selected with keyboard. */ var selectedAlt = function ($el, setFocus) { + + // Don't do anything if the option has already been clicked + if ($el.hasClass("summary-failed")){ + return; + } + that.triggerXAPI('interacted'); var node_id = Number($el.attr('data-bit')); var panel_id = Number($el.parent().data('panel')); @@ -217,7 +232,6 @@ H5P.Summary = (function ($, Question) { setTimeout(function () { $answer.css({backgroundColor: ''}); }, 1); - //$answer.animate({backgroundColor: '#eee'}, 'slow'); var panel = parseInt($el.parent().attr('data-panel')); var $curr_panel = $('.h5p-panel:eq(' + panel + ')', that.$myDom); @@ -273,7 +287,9 @@ H5P.Summary = (function ($, Question) { // Hide intermediate evaluation $evaluation_content.html(that.options.resultLabel); + // Show results and retry button that.do_final_evaluation($summary_container, $options, $summary_list, that.score); + that.showButton('try-again'); } that.trigger('resize'); }); @@ -283,7 +299,6 @@ H5P.Summary = (function ($, Question) { } else { // Remove event handler (prevent repeated clicks) and mouseover effect - $el.off('click'); $el.addClass('summary-failed'); $el.removeClass('summary-claim-unclicked'); @@ -436,7 +451,46 @@ H5P.Summary = (function ($, Question) { * Used for contracts. */ Summary.prototype.resetTask = function () { - // Summary is not yet able to Reset itself + + // Reset starting attributes + this.offset = 0; + this.score = 0; + this.progress = 0; + this.error_counts = []; + + // Reset the progress bar + this.$myDom.find(".summary-evaluation").find(".summary-progress").html(this.options.solvedLabel + ' 0/' + this.summaries.length); + + // Reset the summary container that holds the answers + this.$myDom.find(".summary-container").removeClass("has-results"); + this.$myDom.find(".summary-container ul").empty(); + this.$myDom.find(".summary-score").css("display", "none"); + + // Reset the data for each of the divs + this.$myDom.find('li[role="button"]').each(function() { + $(this).removeClass("summary-failed").addClass("summary-claim-unclicked"); + $(this).attr("tabindex", 0); + $(this).on('click'); + }); + + for (i = 0; i < this.options.summaries.length; i++) { + $('.h5p-panel:eq(' + (i) + ')', this.$myDom).removeClass("panel-disabled"); + } + + // Reset the html statement + this.$myDom.find(".summary-evaluation-content").html("Choose the correct statement."); + + //Set the tip for the first question + var first_tip = this.summaries[0].tip; + if (first_tip){ + this.$myDom.find(".summary-evaluation-content").append(H5P.JoubelUI.createTip(first_tip)); + } + + // Remove the feedback bar + this.setFeedback(); + + // Show the first question and its answers + $('.h5p-panel:eq(' + (0) + ')', this.$myDom).fadeIn(1000); }; /** diff --git a/library.json b/library.json index b039445..06555bd 100644 --- a/library.json +++ b/library.json @@ -1,9 +1,9 @@ { - "title": "Summary", + "title": "SummaryTest", "description": "Test your users with fill in the summary tasks.", "majorVersion": 1, "minorVersion": 5, - "patchVersion": 0, + "patchVersion": 1, "runnable": 1, "machineName": "H5P.Summary", "license": "MIT", @@ -46,4 +46,4 @@ "minorVersion": 0 } ] -} \ No newline at end of file +} diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..71bb1fa --- /dev/null +++ b/todo.txt @@ -0,0 +1 @@ +[ ] From 678f9d07ec075be243f9e34f0ece2ba8b81bdafe Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Thu, 28 Jul 2016 09:29:54 +0100 Subject: [PATCH 2/8] Clean up files --- todo.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 todo.txt diff --git a/todo.txt b/todo.txt deleted file mode 100644 index 71bb1fa..0000000 --- a/todo.txt +++ /dev/null @@ -1 +0,0 @@ -[ ] From 0d63b0d148b321888df63d157d8ed1bed1f53406 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Thu, 28 Jul 2016 12:11:30 +0100 Subject: [PATCH 3/8] Update library.json --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 06555bd..87ddb93 100644 --- a/library.json +++ b/library.json @@ -1,5 +1,5 @@ { - "title": "SummaryTest", + "title": "Summary", "description": "Test your users with fill in the summary tasks.", "majorVersion": 1, "minorVersion": 5, From ebae1643cf2916fadbeecea8b1cc3200b7446271 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Thu, 1 Sep 2016 08:17:39 +0100 Subject: [PATCH 4/8] Integrate resume functionality --- js/summary.js | 39 +++++++++++++++++++++++++++++---------- library.json | 2 +- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/js/summary.js b/js/summary.js index 4d19659..be347d2 100644 --- a/js/summary.js +++ b/js/summary.js @@ -72,14 +72,25 @@ H5P.Summary = (function ($, Question, JoubelUI) { intro: "Choose the correct statement.", solvedLabel: "Solved:", scoreLabel: "Wrong answers:", + behaviour: { + enableRetry: true, + }, postUserStatistics: (H5P.postUserStatistics === true) }, options); this.summaries = that.options.summaries; // Required questiontype contract function - this.showSolutions = function() { - // intentionally left blank, no solution view exists + this.getAnswerGiven = function () { + if (this.progress > 0){ + return true; + } + return false; + }; + + // Required questiontype contract function + this.getScore = function() { + return this.getMaxScore() - this.countErrors(); }; // Required questiontype contract function @@ -87,8 +98,9 @@ H5P.Summary = (function ($, Question, JoubelUI) { return this.summaries.length; }; - this.getScore = function() { - return this.getMaxScore() - this.countErrors(); + // Required questiontype contract function + this.showSolutions = function() { + // intentionally left blank, no solution view exists }; this.getTitle = function() { @@ -116,12 +128,18 @@ H5P.Summary = (function ($, Question, JoubelUI) { // Register retry button to h5p question var self = this; - this.addButton('try-again', 'retry', function () { - // Remove button after is has been clicked - self.hideButton('try-again'); - self.resetTask(); - }, false); + // Attach the retry buton if it is enabled in the semantics + if (this.options.behaviour.enableRetry) { + + // Add JoubelUI retry button using the h5p-question module + this.addButton('try-again', 'retry', function () { + + // Remove button after is has been clicked + self.hideButton('try-again'); + self.resetTask(); + }, self.progress == self.summaries.length); + } }; // Function for attaching the multichoice to a DOM element. @@ -457,6 +475,7 @@ H5P.Summary = (function ($, Question, JoubelUI) { this.score = 0; this.progress = 0; this.error_counts = []; + this.answers = []; // Reset the progress bar this.$myDom.find(".summary-evaluation").find(".summary-progress").html(this.options.solvedLabel + ' 0/' + this.summaries.length); @@ -473,7 +492,7 @@ H5P.Summary = (function ($, Question, JoubelUI) { $(this).on('click'); }); - for (i = 0; i < this.options.summaries.length; i++) { + for (var i = 0; i < this.options.summaries.length; i++) { $('.h5p-panel:eq(' + (i) + ')', this.$myDom).removeClass("panel-disabled"); } diff --git a/library.json b/library.json index 87ddb93..06555bd 100644 --- a/library.json +++ b/library.json @@ -1,5 +1,5 @@ { - "title": "Summary", + "title": "SummaryTest", "description": "Test your users with fill in the summary tasks.", "majorVersion": 1, "minorVersion": 5, From f6f1020f848dab8bbd4cd7160cb0459dca573f2e Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Thu, 1 Sep 2016 08:19:15 +0100 Subject: [PATCH 5/8] Update library.json --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 06555bd..87ddb93 100644 --- a/library.json +++ b/library.json @@ -1,5 +1,5 @@ { - "title": "SummaryTest", + "title": "Summary", "description": "Test your users with fill in the summary tasks.", "majorVersion": 1, "minorVersion": 5, From c0c0395c79f5b2ef727f3b9d8a91b3a8a4f86775 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Sat, 3 Sep 2016 14:29:09 +0100 Subject: [PATCH 6/8] Add semantics boolean to enable retry --- js/summary.js | 20 ++++++++++---------- semantics.json | 7 +++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/js/summary.js b/js/summary.js index be347d2..e1beeca 100644 --- a/js/summary.js +++ b/js/summary.js @@ -44,7 +44,7 @@ H5P.Summary = (function ($, Question, JoubelUI) { } } var that = this; - this.options = H5P.jQuery.extend({}, { + this.options = H5P.jQuery.extend(true, {}, { response: { scorePerfect: { @@ -72,9 +72,7 @@ H5P.Summary = (function ($, Question, JoubelUI) { intro: "Choose the correct statement.", solvedLabel: "Solved:", scoreLabel: "Wrong answers:", - behaviour: { - enableRetry: true, - }, + enableRetry: true, postUserStatistics: (H5P.postUserStatistics === true) }, options); @@ -82,10 +80,7 @@ H5P.Summary = (function ($, Question, JoubelUI) { // Required questiontype contract function this.getAnswerGiven = function () { - if (this.progress > 0){ - return true; - } - return false; + return this.progress > 0; }; // Required questiontype contract function @@ -129,8 +124,13 @@ H5P.Summary = (function ($, Question, JoubelUI) { // Register retry button to h5p question var self = this; + // Parameters are undefined when used wihtin another H5P content type + if (self.summaries === undefined){ + return; + } + // Attach the retry buton if it is enabled in the semantics - if (this.options.behaviour.enableRetry) { + if (this.options.enableRetry) { // Add JoubelUI retry button using the h5p-question module this.addButton('try-again', 'retry', function () { @@ -138,7 +138,7 @@ H5P.Summary = (function ($, Question, JoubelUI) { // Remove button after is has been clicked self.hideButton('try-again'); self.resetTask(); - }, self.progress == self.summaries.length); + }, self.progress === self.summaries.length); } }; diff --git a/semantics.json b/semantics.json index ab9be58..f7fb6b4 100644 --- a/semantics.json +++ b/semantics.json @@ -192,5 +192,12 @@ "default": "You got @score of @total statements (@percent %) correct on your first try.", "description": "Available variables: @score, @total, @percent. Example: You got @score of @total statements (@percent %) correct.", "common": true + }, + { + "label": "Enable \"Retry\"", + "name": "enableRetry", + "type": "boolean", + "default": false, + "optional": true } ] From da57a77cc24a7adeecec09cc6c28f4641ab91976 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Mon, 5 Sep 2016 12:08:38 +0100 Subject: [PATCH 7/8] (Re)Add behaviour group --- js/summary.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/summary.js b/js/summary.js index e1beeca..40e3c7b 100644 --- a/js/summary.js +++ b/js/summary.js @@ -72,7 +72,9 @@ H5P.Summary = (function ($, Question, JoubelUI) { intro: "Choose the correct statement.", solvedLabel: "Solved:", scoreLabel: "Wrong answers:", - enableRetry: true, + behavior: { + enableRetry: false + }, postUserStatistics: (H5P.postUserStatistics === true) }, options); @@ -130,7 +132,7 @@ H5P.Summary = (function ($, Question, JoubelUI) { } // Attach the retry buton if it is enabled in the semantics - if (this.options.enableRetry) { + if (this.options.behavior.enableRetry) { // Add JoubelUI retry button using the h5p-question module this.addButton('try-again', 'retry', function () { From be4f909c059b54ff643cc362b6160f3b7f0f5791 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Mon, 5 Sep 2016 13:52:16 +0100 Subject: [PATCH 8/8] Update semantics.json --- semantics.json | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/semantics.json b/semantics.json index f7fb6b4..e99ba27 100644 --- a/semantics.json +++ b/semantics.json @@ -194,10 +194,19 @@ "common": true }, { - "label": "Enable \"Retry\"", - "name": "enableRetry", - "type": "boolean", - "default": false, - "optional": true + "name": "behaviour", + "type": "group", + "label": "Behavioural settings.", + "description": "These options will let you control how the task behaves.", + "optional": true, + "fields": [ + { + "label": "Enable \"Retry\"", + "name": "enableRetry", + "type": "boolean", + "default": false, + "optional": true + } + ] } ]