Skip to content

Commit

Permalink
Show solution on submit
Browse files Browse the repository at this point in the history
  • Loading branch information
dri94 committed Aug 7, 2023
1 parent bd3b3d1 commit 863168b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions swiftplugin/swiftplugin/static/js/src/swiftplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function SwiftPluginXBlock(runtime, element) {
myCodeMirror = CodeMirror.fromTextArea(myTextArea, codemirror_config);
myCodeMirror.setSize('100%');
if (response.user_code) {
myCodeMirror.setValue(response.user_code)
myCodeMirror.setValue(response.user_code)
} else if (response.starter_code) {
myCodeMirror.setValue(response.starter_code)
}
Expand All @@ -114,7 +114,6 @@ function SwiftPluginXBlock(runtime, element) {
solutionCodeMirror = CodeMirror.fromTextArea(solutionTextArea, solutionmirror_config);
solutionCodeMirror.setSize('100%');
if (response.has_solution_defined) {
solution_btn.hidden = false
updateProblemSolution(response)
} else {
solution_btn.hidden = true
Expand Down Expand Up @@ -147,6 +146,9 @@ function SwiftPluginXBlock(runtime, element) {
} else {
setOutput(response)
}
if (response.problem_solution) {
updateProblemSolution(response)
}
}

function setError(error) {
Expand Down Expand Up @@ -228,6 +230,7 @@ function SwiftPluginXBlock(runtime, element) {
console.log('No problem solution')
return
}
solution_btn.hidden = false
solutionCodeMirror.setValue(response.problem_solution)
}

Expand Down
4 changes: 3 additions & 1 deletion swiftplugin/swiftplugin/swiftplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def student_view(self, context=None):
frag.initialize_js('SwiftPluginXBlock')
return frag


@XBlock.json_handler
def get_button_handler(self, data, suffix=''):
"""
Expand Down Expand Up @@ -124,6 +123,9 @@ def get_button_handler(self, data, suffix=''):
response['response'] = assignment_response
is_final_attempt = assignment_response['finalAttempt']
success = assignment_response['success']
grade_points = assignment_response['gradePoints']
if 'solutionCode' in assignment_response:
response['problem_solution'] = assignment_response['solutionCode']
if success:
self.runtime.publish(self, "grade",
{'value': grade_points,
Expand Down

0 comments on commit 863168b

Please sign in to comment.