Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 30e8e91

Browse files
committed
Add show feedback button
1 parent 2d33eae commit 30e8e91

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

runestone/activecode/activecode.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def setup(app):
5454

5555

5656
TEMPLATE = """
57-
<pre data-component="activecode" id=%(divid)s data-lang="%(language)s" %(autorun)s %(hidecode)s %(include)s %(timelimit)s %(coach)s %(codelens)s data-audio='%(ctext)s' %(sourcefile)s %(datafile)s %(stdin)s>
57+
<pre data-component="activecode" id=%(divid)s data-lang="%(language)s" %(autorun)s %(hidecode)s %(include)s %(timelimit)s %(coach)s %(codelens)s data-audio='%(ctext)s' %(sourcefile)s %(datafile)s %(stdin)s %(gradebutton)s>
5858
%(initialcode)s
5959
</pre>
6060
"""
@@ -65,18 +65,6 @@ def setup(app):
6565
<p class="ac_caption"><span class="ac_caption_text">%(caption)s (%(divid)s)</span> </p>
6666
'''
6767

68-
69-
GRADES = '''
70-
<span class="ac_sep"></span>
71-
<input type="button" class='btn btn-default ' id="gradeb" name="Show Feedback" value="Show Feedback" onclick="createGradeSummary('%(divid)s')"/>
72-
'''
73-
74-
75-
76-
# <iframe id="%(divid)s_codelens" width="800" height="500" style="display:block"src="#">
77-
# </iframe>
78-
79-
8068
AUTO = '''
8169
<script type="text/javascript">
8270
$(document).ready(function() {
@@ -252,6 +240,9 @@ def run(self):
252240
else:
253241
self.options['sourcefile'] = "data-sourcefile='%s'" % self.options['sourcefile']
254242

243+
if 'gradebutton' not in self.options:
244+
self.options['gradebutton'] = ''
245+
255246
return [ActivcodeNode(self.options)]
256247

257248

@@ -261,9 +252,9 @@ class ActiveExercise(ActiveCode):
261252
has_content = True
262253

263254
def run(self):
264-
self.options['hidecode'] = True
265-
self.options['gradebutton'] = True
266-
self.options['coach'] = True
255+
self.options['hidecode'] = "data-hidecode=true"
256+
self.options['gradebutton'] = "data-gradebutton=true"
257+
self.options['coach'] = "data-coach=true"
267258
return super(ActiveExercise, self).run()
268259

269260

runestone/activecode/js/activecode.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ ActiveCode.prototype.createControls = function () {
134134
$(butt).css("display","none")
135135
}
136136

137+
if ($(this.origElem).data('gradebutton')) {
138+
butt = document.createElement("button");
139+
$(butt).addClass("ac_opt btn btn-default");
140+
$(butt).text("Show Feedback");
141+
$(butt).css("margin-left","10px");
142+
this.gradeButton = butt;
143+
ctrlDiv.appendChild(butt);
144+
$(butt).click(this.createGradeSummary.bind(this))
145+
}
137146
// Show/Hide Code
138147
if (this.hidecode) {
139148
butt = document.createElement("button");
@@ -220,6 +229,43 @@ ActiveCode.prototype.loadEditor = function () {
220229

221230
};
222231

232+
ActiveCode.prototype.createGradeSummary = function () {
233+
// get grade and comments for this assignment
234+
// get summary of all grades for this student
235+
// display grades in modal window
236+
var showGradeSummary = function (data, status, whatever) {
237+
var report = eval(data)[0];
238+
// check for report['message']
239+
if (report['grade']) {
240+
body = "<h4>Grade Report</h4>" +
241+
"<p>This assignment: " + report['grade'] + "</p>" +
242+
"<p>" + report['comment'] + "</p>" +
243+
"<p>Number of graded assignments: " + report['count'] + "</p>" +
244+
"<p>Average score: " + report['avg'] + "</p>"
245+
246+
} else {
247+
body = "<h4>You must be Logged in to see your grade</h4>";
248+
}
249+
var html = '<div class="modal fade">' +
250+
' <div class="modal-dialog compare-modal">' +
251+
' <div class="modal-content">' +
252+
' <div class="modal-header">' +
253+
' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>' +
254+
' <h4 class="modal-title">Assignment Feedback</h4>' +
255+
' </div>' +
256+
' <div class="modal-body">' +
257+
body +
258+
' </div>' +
259+
' </div>' +
260+
' </div>' +
261+
'</div>';
262+
263+
el = $(html);
264+
el.modal();
265+
}
266+
var data = {'div_id': this.divid}
267+
jQuery.get(eBookConfig.ajaxURL + 'getassignmentgrade', data, showGradeSummary);
268+
}
223269

224270
ActiveCode.prototype.hideCodelens = function (button, div_id) {
225271
this.codelens.style.display = 'none'

0 commit comments

Comments
 (0)