Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard/soft reset implementation #493

Merged
merged 2 commits into from Mar 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/core/js/models/adaptModel.js
Expand Up @@ -13,7 +13,9 @@ define(function (require) {

defaults: {
_canShowFeedback: true,
_canReset: false,
_isComplete: false,
_isInteractionComplete: false,
_isEnabled: true,
_isResetOnRevisit: false,
_isAvailable: true,
Expand Down Expand Up @@ -55,14 +57,37 @@ define(function (require) {
if (this._children) {
Adapt[this._children].on({
"change:_isReady": this.checkReadyStatus,
"change:_isComplete": this.checkCompletionStatus
"change:_isComplete": this.checkCompletionStatus,
"change:_isInteractionComplete": this.checkInteractionCompletionStatus
}, this);
}
this.init();
},

init: function() {},

reset: function(type, force) {
if (!this.get("_canReset") && !force) return;

type = type || true;

switch (type) {
case "hard": case true:
this.set({
_isEnabled: true,
_isComplete: false,
_isInteractionComplete: false,
});
break;
case "soft":
this.set({
_isEnabled: true,
_isInteractionComplete: false
});
break;
}
},

checkReadyStatus: function () {
// Filter children based upon whether they are available
var availableChildren = new Backbone.Collection(this.getChildren().where({_isAvailable: true}));
Expand All @@ -77,10 +102,27 @@ define(function (require) {
var availableChildren = new Backbone.Collection(this.getChildren().where({_isAvailable: true}));
// Check if any return _isComplete:false
// If not - set this model to _isComplete: true
if (availableChildren.findWhere({_isComplete: false})) return;
if (availableChildren.findWhere({_isComplete: false})) {
//cascade reset to menu
this.set({_isComplete:false});
return;
}
this.set({_isComplete: true});
},

checkInteractionCompletionStatus: function () {
// Filter children based upon whether they are available
var availableChildren = new Backbone.Collection(this.getChildren().where({_isAvailable: true}));
// Check if any return _isInteractionComplete:false
// If not - set this model to _isInteractionComplete: true
if (availableChildren.findWhere({_isInteractionComplete: false})) {
//cascade reset to menu
this.set({_isInteractionComplete:false});
return;
}
this.set({_isInteractionComplete: true});
},

findAncestor: function (ancestors) {

var parent = this.getParent();
Expand Down
21 changes: 20 additions & 1 deletion src/core/js/models/componentModel.js
Expand Up @@ -19,10 +19,29 @@ define(function(require) {
}
}
},

reset: function(type, force) {
if (!this.get("_canReset") && !force) return;

type = type || true;

AdaptModel.prototype.reset.call(this, type, force);

if (this.get("_isQuestionType")) {
var attempts = this.get('_attempts');
this.set({
_attemptsLeft: attempts,
_isCorrect: false,
_isSubmitted: false,
_buttonState: 'submit'
});
}
},

_parent:'blocks',
_siblings:'components'
});

return ComponentModel;

});
});
3 changes: 2 additions & 1 deletion src/core/js/models/courseModel.js
Expand Up @@ -26,7 +26,8 @@ define(function(require) {
setupListeners: function() {
Adapt[this._children].on({
"change:_isReady": this.checkReadyStatus,
"change:_isComplete": this.checkCompletionStatus
"change:_isComplete": this.checkCompletionStatus,
"change:_isInteractionComplete": this.checkInteractionCompletionStatus
}, this);
},

Expand Down
14 changes: 14 additions & 0 deletions src/core/js/views/adaptView.js
Expand Up @@ -60,6 +60,20 @@ define(function(require) {
setCompletionStatus: function() {
if (this.model.get('_isVisible')) {
this.model.set('_isComplete', true);
this.model.set('_isInteractionComplete', true);
}
},

resetCompletionStatus: function(type) {
if (!this.model.get("_canReset")) return;

var descendantComponents = this.model.findDescendants('components');
if (descendantComponents.length === 0) {
this.model.reset(type);
} else {
descendantComponents.each(function(model) {
model.reset(type);
});
}
},

Expand Down
4 changes: 2 additions & 2 deletions src/core/js/views/buttonsView.js
Expand Up @@ -64,12 +64,12 @@ define(function() {
},

updateAttemptsCount: function(model, changedAttribute) {
var isComplete = this.model.get('_isComplete');
var isInteractionComplete = this.model.get('_isInteractionComplete');
var attemptsLeft = (this.model.get('_attemptsLeft')) ? this.model.get('_attemptsLeft') : this.model.get('_attempts')
var isCorrect = this.model.get('_isCorrect');
var shouldDisplayAttempts = this.model.get('_shouldDisplayAttempts');
var attemptsString;
if (!isComplete && attemptsLeft != 0) {
if (!isInteractionComplete && attemptsLeft != 0) {
attemptsString = attemptsLeft + " ";
if (attemptsLeft > 1) {
attemptsString += this.model.get('_buttons').remainingAttemptsText;
Expand Down
26 changes: 10 additions & 16 deletions src/core/js/views/questionView.js
Expand Up @@ -69,27 +69,21 @@ define(function(require) {
// If reset is enabled set defaults
// Call blank method for question to handle
if (isResetOnRevisit) {
var attempts = this.model.get('_attempts');
this.model.set({
_isEnabled: true,
_attemptsLeft: attempts,
_isCorrect: false,
_isComplete: false,
_isSubmitted: false,
_buttonState: 'submit'
});
// Defer is added to allow the component to render

this.model.reset(isResetOnRevisit, true);

// Defer is added to allow the component to render
_.defer(_.bind(function() {
this.resetQuestionOnRevisit();
this.resetQuestionOnRevisit(isResetOnRevisit);
}, this));

} else {

// If complete - display users answer
// or reset the question if not complete
var isComplete = this.model.get('_isComplete');
var isInteractionComplete = this.model.get('_isInteractionComplete');

if (isComplete) {
if (isInteractionComplete) {
this.model.set('_buttonState', 'hideCorrectAnswer');
// Defer is added to allow the component to render
_.defer(_.bind(function() {
Expand All @@ -109,7 +103,7 @@ define(function(require) {
},

// Used by the question to reset the question when revisiting the component
resetQuestionOnRevisit: function() {},
resetQuestionOnRevisit: function(type) {},

// Calls default methods to setup on questions
setupDefaultSettings: function() {
Expand Down Expand Up @@ -309,12 +303,12 @@ define(function(require) {
// _buttonState on the model which buttonsView listens to
updateButtons: function() {

var isComplete = this.model.get('_isComplete');
var isInteractionComplete = this.model.get('_isInteractionComplete');
var isCorrect = this.model.get('_isCorrect');
var isEnabled = this.model.get('_isEnabled');
var buttonState = this.model.get('_buttonState');

if (isComplete) {
if (isInteractionComplete) {
if (isCorrect || !this.model.get('_canShowModelAnswer')) {
this.model.set('_buttonState', 'complete');
} else {
Expand Down