Commit 395c4034 by E. Kolpakov

Preserving feedback messages and tips on page reload for standard mode

parent f13d337a
...@@ -435,6 +435,61 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC ...@@ -435,6 +435,61 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC
""" """
Gets detailed results in the case of extended feedback. Gets detailed results in the case of extended feedback.
Right now there are two ways to get results-- through the template upon loading up
the mentoring block, or after submission of an AJAX request like in
submit or get_results here.
"""
if self.mode == 'standard':
results, completed, show_message = self._get_standard_results()
mentoring_completed = completed
else:
if not self.show_extended_feedback():
return {
'results': [],
'error': 'Extended feedback results cannot be obtained.'
}
results, completed, show_message = self._get_assessment_results(queries)
mentoring_completed = True
result = {
'results': results,
'completed': completed,
'step': self.step,
'max_attempts': self.max_attempts,
'num_attempts': self.num_attempts,
}
if show_message:
result['message'] = self.get_message(mentoring_completed)
return result
def _get_standard_results(self):
"""
Gets previous submissions results as if submit was called with exactly the same values as last time.
"""
results = []
completed, show_message = True, False
choices = dict(self.student_results)
# In standard mode, all children is visible simultaneously, so need collecting responses from all of them
for child_id in self.steps:
child = self.runtime.get_block(child_id)
if child.name and child.name in choices:
show_message = True
child_result = child.get_results(choices[child.name])
results.append([child.name, child_result])
completed = completed and (child_result['status'] == 'correct')
else:
completed = False
return results, completed, show_message
def _get_assessment_results(self, queries):
"""
Gets detailed results in the case of extended feedback.
It may be a good idea to eventually have this function get results It may be a good idea to eventually have this function get results
in the general case instead of loading them in the template in the future, in the general case instead of loading them in the template in the future,
and only using it for extended feedback situations. and only using it for extended feedback situations.
...@@ -444,14 +499,8 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC ...@@ -444,14 +499,8 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC
submit or get_results here. submit or get_results here.
""" """
results = [] results = []
if not self.show_extended_feedback():
return {
'results': [],
'error': 'Extended feedback results cannot be obtained.'
}
completed = True completed = True
choices = dict(self.student_results) choices = dict(self.student_results)
step = self.step
# Only one child should ever be of concern with this method. # Only one child should ever be of concern with this method.
for child_id in self.steps: for child_id in self.steps:
child = self.runtime.get_block(child_id) child = self.runtime.get_block(child_id)
...@@ -464,17 +513,7 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC ...@@ -464,17 +513,7 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC
completed = choices[child.name]['status'] completed = choices[child.name]['status']
break break
# The 'completed' message should always be shown in this case, since no more attempts are available. return results, completed, True
message = self.get_message(True)
return {
'results': results,
'completed': completed,
'message': message,
'step': step,
'max_attempts': self.max_attempts,
'num_attempts': self.num_attempts,
}
@XBlock.json_handler @XBlock.json_handler
def submit(self, submissions, suffix=''): def submit(self, submissions, suffix=''):
......
...@@ -66,6 +66,10 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -66,6 +66,10 @@ function MentoringStandardView(runtime, element, mentoring) {
submitXHR = $.post(handlerUrl, JSON.stringify(data)).success(handleSubmitResults).error(handleSubmitError); submitXHR = $.post(handlerUrl, JSON.stringify(data)).success(handleSubmitResults).error(handleSubmitError);
} }
function get_results(){
calculate_results('get_results');
}
function submit() { function submit() {
calculate_results('submit'); calculate_results('submit');
} }
...@@ -97,6 +101,8 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -97,6 +101,8 @@ function MentoringStandardView(runtime, element, mentoring) {
mentoring.initChildren(options); mentoring.initChildren(options);
mentoring.renderDependency(); mentoring.renderDependency();
get_results();
var submitPossible = submitDOM.length > 0; var submitPossible = submitDOM.length > 0;
if (submitPossible) { if (submitPossible) {
mentoring.renderAttempts(); mentoring.renderAttempts();
......
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