Commit d02539cb by Tim Krones

Persist step info.

parent 9cf2ee45
...@@ -834,6 +834,14 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes ...@@ -834,6 +834,14 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes
scope=Scope.settings scope=Scope.settings
) )
# User state
step = Integer(
# Keep track of the student progress.
default=0,
scope=Scope.user_state,
enforce_type=True
)
editable_fields = ('display_name',) editable_fields = ('display_name',)
@lazy @lazy
...@@ -900,6 +908,14 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes ...@@ -900,6 +908,14 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes
NestedXBlockSpec(OnAssessmentReviewMentoringMessageShim, boilerplate='on-assessment-review'), NestedXBlockSpec(OnAssessmentReviewMentoringMessageShim, boilerplate='on-assessment-review'),
] ]
@XBlock.json_handler
def update_step(self, step, suffix=''):
if step < len(self.steps):
self.step = step
return {
'step': self.step
}
def author_edit_view(self, context): def author_edit_view(self, context):
""" """
Add some HTML to the author view that allows authors to add child blocks. Add some HTML to the author view that allows authors to add child blocks.
......
...@@ -3,14 +3,27 @@ function MentoringWithStepsBlock(runtime, element) { ...@@ -3,14 +3,27 @@ function MentoringWithStepsBlock(runtime, element) {
var steps = runtime.children(element).filter( var steps = runtime.children(element).filter(
function(c) { return c.element.className.indexOf('pb-mentoring-step') > -1; } function(c) { return c.element.className.indexOf('pb-mentoring-step') > -1; }
); );
var active_child = -1; var step = $('.mentoring', element).data('step');
var checkmark, submitDOM, nextDOM; var active_child, checkmark, submitDOM, nextDOM;
function isLastChild() { function isLastChild() {
return (active_child === steps.length-1); return (active_child === steps.length-1);
} }
function updateStep() {
var handlerUrl = runtime.handlerUrl(element, 'update_step');
$.post(handlerUrl, JSON.stringify(step+1))
.success(function(response) {
step = response.step;
console.log('Step: ' + step);
});
}
function handleResults(response) { function handleResults(response) {
// Update step so next step is shown on page reload (even if user does not click "Next Step")
updateStep();
// Update UI
if (response.completed === 'correct') { if (response.completed === 'correct') {
checkmark.addClass('checkmark-correct icon-ok fa-check'); checkmark.addClass('checkmark-correct icon-ok fa-check');
} else if (response.completed === 'partial') { } else if (response.completed === 'partial') {
...@@ -106,6 +119,8 @@ function MentoringWithStepsBlock(runtime, element) { ...@@ -106,6 +119,8 @@ function MentoringWithStepsBlock(runtime, element) {
}; };
initSteps(options); initSteps(options);
active_child = step;
active_child -= 1;
displayNextChild(); displayNextChild();
} }
......
...@@ -75,13 +75,15 @@ class MentoringStepBlock( ...@@ -75,13 +75,15 @@ class MentoringStepBlock(
STUDIO_LABEL = _(u"Mentoring Step") STUDIO_LABEL = _(u"Mentoring Step")
CATEGORY = 'pb-mentoring-step' CATEGORY = 'pb-mentoring-step'
# Fields: # Settings
display_name = String( display_name = String(
display_name=_("Step Title"), display_name=_("Step Title"),
help=_('Leave blank to use sequential numbering'), help=_('Leave blank to use sequential numbering'),
default="", default="",
scope=Scope.content scope=Scope.content
) )
# User state
student_results = List( student_results = List(
# Store results of student choices. # Store results of student choices.
default=[], default=[],
......
Markdown is supported
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