Commit 0d627346 by Tim Krones

Display step- and answer-level feedback when reviewing step.

parent 67a9c25f
......@@ -111,6 +111,29 @@ function MentoringWithStepsBlock(runtime, element) {
step.submit(handleResults);
}
function getResults() {
var step = steps[activeStep];
step.getResults(handleReviewResults);
}
function handleReviewResults(response) {
// Show step-level feedback
if (response.completed === 'correct') {
checkmark.addClass('checkmark-correct icon-ok fa-check');
} else if (response.completed === 'partial') {
checkmark.addClass('checkmark-partially-correct icon-ok fa-check');
} else {
checkmark.addClass('checkmark-incorrect icon-exclamation fa-exclamation');
}
// Forward to active step to show answer level feedback
var step = steps[activeStep];
var results = response.results;
var options = {
checkmark: checkmark
};
step.handleReview(results, options);
}
function hideAllSteps() {
for (var i=0; i < steps.length; i++) {
$(steps[i].element).hide();
......@@ -216,6 +239,8 @@ function MentoringWithStepsBlock(runtime, element) {
submitDOM.attr('disabled', 'disabled');
reviewLinkDOM.show();
// ...
getResults();
}
function showAttempts() {
......@@ -258,10 +283,23 @@ function MentoringWithStepsBlock(runtime, element) {
function initSteps(options) {
for (var i=0; i < steps.length; i++) {
var step = steps[i];
var mentoring = {
setContent: setContent
};
options.mentoring = mentoring;
step.initChildren(options);
}
}
function setContent(dom, content) {
dom.html('');
dom.append(content);
var template = $('#light-child-template', dom).html();
if (template) {
dom.append(template);
}
}
function showGrade() {
cleanAll();
showAssessmentMessage();
......
function MentoringStepBlock(runtime, element) {
var children = runtime.children(element);
var submitXHR;
var submitXHR, resultsXHR;
function callIfExists(obj, fn) {
if (typeof obj !== 'undefined' && typeof obj[fn] == 'function') {
......@@ -51,6 +51,36 @@ function MentoringStepBlock(runtime, element) {
.success(function(response) {
result_handler(response);
});
},
getResults: function(result_handler) {
var handler_name = 'get_results';
var data = [];
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child && child.name !== undefined) { // Check if we are dealing with a question
data[i] = child.name;
}
}
var handlerUrl = runtime.handlerUrl(element, handler_name);
if (resultsXHR) {
resultsXHR.abort();
}
resultsXHR = $.post(handlerUrl, JSON.stringify(data))
.success(function(response) {
result_handler(response);
});
},
handleReview: function(results, options) {
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child && child.name !== undefined) { // Check if we are dealing with a question
var result = results[child.name];
callIfExists(child, 'handleSubmit', result, options);
callIfExists(child, 'handleReview', result);
}
}
}
};
......
......@@ -157,6 +157,29 @@ class MentoringStepBlock(
'attempt_complete': self.is_last_step
}
@XBlock.json_handler
def get_results(self, queries, suffix=''):
results = {}
answers = dict(self.student_results)
for question in self.get_steps():
previous_results = answers[question.name]
result = question.get_results(previous_results)
results[question.name] = result
# Compute "answer status" for this step
if all(result[1]['status'] == 'correct' for result in self.student_results):
completed = Correctness.CORRECT
elif all(result[1]['status'] == 'incorrect' for result in self.student_results):
completed = Correctness.INCORRECT
else:
completed = Correctness.PARTIAL
# Add 'message' to results? Looks like it's not used on the client ...
return {
'results': results,
'completed': completed,
}
def reset(self):
while self.student_results:
self.student_results.pop()
......
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