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

Commit fa6d7d2

Browse files
committed
🔥 Removing code that is not useful for horizontal parsons + sql
1 parent 8353958 commit fa6d7d2

3 files changed

Lines changed: 7 additions & 262 deletions

File tree

runestone/hparsons/hparsons.py

Lines changed: 5 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,16 @@ def setup(app):
4747

4848

4949
TEMPLATE_START = """
50-
<div class="%(divclass)s">
50+
<div>
5151
<div data-component="activecode" id=%(divid)s data-question_label="%(question_label)s">
5252
<div id=%(divid)s_question class="ac_question col-md-12">
5353
"""
5454

5555
TEMPLATE_END = """
5656
</div>
57-
<textarea data-lang="%(language)s" id="%(divid)s_editor" %(autorun)s
58-
%(hidecode)s %(include)s %(timelimit)s %(coach)s %(codelens)s %(enabledownload)s %(chatcodes)s %(optional)s
59-
data-audio='%(ctext)s' %(sourcefile)s %(datafile)s %(stdin)s %(tie)s %(dburl)s %(nopair)s
60-
%(cargs)s %(largs)s %(rargs)s %(iargs)s %(gradebutton)s %(caption)s %(hidehistory)s %(wasmuri)s
57+
<textarea data-lang="%(language)s" id="%(divid)s_editor"
58+
%(optional)s
59+
%(dburl)s
6160
%(showlastsql)s style="visibility: hidden;">
6261
%(initialcode)s
6362
</textarea>
@@ -79,8 +78,6 @@ def visit_ac_node(self, node):
7978
# print self.settings.env.activecodecounter
8079

8180
# todo: handle above in node.runestone_options
82-
# todo handle 'hidecode' not in node.runestone_options:
83-
# todo: handle if 'gradebutton' in node.runestone_options: res += GRADES
8481

8582
node.delimiter = "_start__{}_".format(node.runestone_options["divid"])
8683

@@ -116,31 +113,11 @@ def purge_activecodes(app, env, docname):
116113

117114

118115
class HParsonsDirective(RunestoneIdDirective):
116+
# only keep: language, autograde, dburl
119117
"""
120118
.. activecode:: uniqueid
121-
:nocanvas: -- do not create a canvas
122119
:autograde: unittest
123-
:nopre: -- do not create an output component
124-
:above: -- put the canvas above the code
125-
:autorun: -- run this activecode as soon as the page is loaded
126-
:caption: this is the caption
127-
:include: div1,div2 -- invisibly include code from another activecode
128-
:hidecode: -- Don't show the editor initially
129-
:nocodelens: -- Do not show the codelens button
130-
:timelimit: -- set the time limit for this program in seconds
131120
:language: python, html, javascript, java, python2, python3
132-
:chatcodes: -- Enable users to talk about this code snippet with others
133-
:tour_1: audio tour track
134-
:tour_2: audio tour track
135-
:tour_3: audio tour track
136-
:tour_4: audio tour track
137-
:tour_5: audio tour track
138-
:stdin: : A file to simulate stdin (java, python2, python3)
139-
:datafile: : A datafile for the program to read (java, python2, python3)
140-
:sourcefile: : source files (java, python2, python3)
141-
:available_files: : other additional files (java, python2, python3)
142-
:enabledownload: -- allow textfield contents to be downloaded as *.py file
143-
:nopair: -- disable pair programming features
144121
:dburl: url to load database for sql mode
145122
:showlastsql: -- Only show the last sql result in output
146123
@@ -158,7 +135,6 @@ class HParsonsDirective(RunestoneIdDirective):
158135
159136
- activecode_div_class - custom CSS class of the component's outermost div
160137
- activecode_hide_load_history - if True, hide the load history button
161-
- wasm_uri - Path or Full URL to folder containing WASM files for SQL. /_static is default
162138
"""
163139

164140
required_arguments = 1
@@ -167,35 +143,7 @@ class HParsonsDirective(RunestoneIdDirective):
167143
option_spec = RunestoneIdDirective.option_spec.copy()
168144
option_spec.update(
169145
{
170-
"nocanvas": directives.flag,
171-
"nopre": directives.flag,
172-
"above": directives.flag, # put the canvas above the code
173-
"autorun": directives.flag,
174-
"caption": directives.unchanged,
175-
"include": directives.unchanged,
176-
"hidecode": directives.flag,
177146
"language": directives.unchanged,
178-
"chatcodes": directives.flag,
179-
"tour_1": directives.unchanged,
180-
"tour_2": directives.unchanged,
181-
"tour_3": directives.unchanged,
182-
"tour_4": directives.unchanged,
183-
"tour_5": directives.unchanged,
184-
"nocodelens": directives.flag,
185-
"coach": directives.flag,
186-
"gradebutton": directives.flag,
187-
"timelimit": directives.unchanged,
188-
"stdin": directives.unchanged,
189-
"datafile": directives.unchanged,
190-
"sourcefile": directives.unchanged,
191-
"available_files": directives.unchanged,
192-
"enabledownload": directives.flag,
193-
"compileargs": directives.unchanged,
194-
"linkargs": directives.unchanged,
195-
"interpreterargs": directives.unchanged,
196-
"runargs": directives.unchanged,
197-
"tie": directives.unchanged,
198-
"nopair": directives.flag,
199147
"dburl": directives.unchanged,
200148
"showlastsql": directives.flag,
201149
}
@@ -233,118 +181,9 @@ def run(self):
233181
str3 = str2.replace("'", "*singleq*")
234182
self.options["argu"] = str3
235183

236-
# TODO: This is BAD -- using '_' as a key for audio tour stuff is wrong.
237-
complete = ""
238-
no_of_buttons = 0
239-
okeys = list(self.options.keys())
240-
for k in okeys:
241-
if "tour_" in k:
242-
x, label = k.split("_")
243-
no_of_buttons = no_of_buttons + 1
244-
complete = complete + self.options[k] + "*atype*"
245-
246-
newcomplete = complete.replace('"', "*doubleq*")
247-
self.options["ctext"] = newcomplete
248-
self.options["no_of_buttons"] = no_of_buttons
249-
250-
if "caption" not in self.options:
251-
self.options["caption"] = ""
252-
else:
253-
self.options["caption"] = "data-caption='%s'" % self.options["caption"]
254-
255-
if "include" not in self.options:
256-
self.options["include"] = ""
257-
else:
258-
lst = self.options["include"].split(",")
259-
lst = [x.strip() for x in lst]
260-
self.options["include"] = 'data-include="' + " ".join(lst) + '"'
261-
262-
if "hidecode" in self.options:
263-
self.options["hidecode"] = 'data-hidecode="true"'
264-
else:
265-
self.options["hidecode"] = ""
266-
267-
if "enabledownload" in self.options:
268-
self.options["enabledownload"] = 'data-enabledownload="true"'
269-
else:
270-
self.options["enabledownload"] = ""
271-
272-
if "chatcodes" in self.options:
273-
self.options["chatcodes"] = 'data-chatcodes="true"'
274-
else:
275-
self.options["chatcodes"] = ""
276-
277184
if "language" not in self.options:
278185
self.options["language"] = "python"
279186

280-
if self.options["language"] == "html":
281-
self.options["language"] = "htmlmixed"
282-
self.options["initialcode"] = escape(self.options["initialcode"])
283-
284-
if "nocodelens" in self.options or self.options["language"] not in [
285-
"python",
286-
"java",
287-
"c",
288-
"cpp",
289-
]:
290-
self.options["codelens"] = ""
291-
else:
292-
self.options["codelens"] = 'data-codelens="true"'
293-
294-
if "nopair" in self.options:
295-
self.options["nopair"] = 'data-nopair="true"'
296-
else:
297-
self.options["nopair"] = ""
298-
299-
if "timelimit" not in self.options:
300-
self.options["timelimit"] = "data-timelimit=25000"
301-
else:
302-
self.options["timelimit"] = "data-timelimit=%s" % self.options["timelimit"]
303-
304-
if "autorun" not in self.options:
305-
self.options["autorun"] = ""
306-
else:
307-
self.options["autorun"] = 'data-autorun="true"'
308-
309-
if "coach" in self.options:
310-
self.options["coach"] = 'data-coach="true"'
311-
else:
312-
self.options["coach"] = ""
313-
314-
# livecode options
315-
if "stdin" in self.options:
316-
self.options["stdin"] = "data-stdin='%s'" % self.options["stdin"]
317-
else:
318-
self.options["stdin"] = ""
319-
320-
if "datafile" not in self.options:
321-
self.options["datafile"] = ""
322-
else:
323-
self.options["datafile"] = "data-datafile='%s'" % self.options["datafile"]
324-
325-
if "sourcefile" not in self.options:
326-
self.options["sourcefile"] = ""
327-
else:
328-
self.options["sourcefile"] = (
329-
"data-sourcefile='%s'" % self.options["sourcefile"]
330-
)
331-
332-
if "tie" in self.options:
333-
self.options["tie"] = "data-tie='{}'".format(self.options["tie"])
334-
else:
335-
self.options["tie"] = ""
336-
337-
for opt, tp in [
338-
("compileargs", "cargs"),
339-
("linkargs", "largs"),
340-
("runargs", "rargs"),
341-
("interpreterargs", "iargs"),
342-
]:
343-
if opt in self.options:
344-
self.options[tp] = 'data-{}="{}"'.format(opt, escape(self.options[opt]))
345-
else:
346-
self.options[tp] = ""
347-
348187
# SQL Options
349188
if "dburl" in self.options:
350189
self.options["dburl"] = "data-dburl='{}'".format(self.options["dburl"])
@@ -356,39 +195,6 @@ def run(self):
356195
else:
357196
self.options["showlastsql"] = ""
358197

359-
# other options
360-
361-
if "gradebutton" not in self.options:
362-
self.options["gradebutton"] = ""
363-
else:
364-
self.options["gradebutton"] = "data-gradebutton=true"
365-
366-
self.options["divclass"] = env.config.activecode_div_class
367-
if env.config.activecode_hide_load_history:
368-
self.options["hidehistory"] = "data-hidehistory=true"
369-
else:
370-
self.options["hidehistory"] = ""
371-
372-
if env.config.wasm_uri:
373-
self.options["wasmuri"] = f"data-wasm={env.config.wasm_uri}"
374-
else:
375-
self.options["wasmuri"] = ""
376-
377-
if self.content:
378-
if "^^^^" in self.content:
379-
idx = self.content.index("^^^^")
380-
prefix = "\n".join(self.content[:idx])
381-
if "====" in self.content:
382-
idx = self.content.index("====")
383-
source = "\n".join(self.content[:idx])
384-
suffix = "\n".join(self.content[idx + 1 :])
385-
else:
386-
source = "\n".join(self.content)
387-
suffix = "\n"
388-
else:
389-
source = "\n"
390-
suffix = "\n"
391-
392198
course_name = env.config.html_context["course_id"]
393199
divid = self.options["divid"]
394200

@@ -409,8 +215,6 @@ def run(self):
409215
course_id=course_name,
410216
main_code=source,
411217
suffix_code=suffix,
412-
includes=self.options["include"],
413-
available_files=self.options.get("available_files", ""),
414218
)
415219
)
416220
else:

runestone/hparsons/js/hparsons-sql.js

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -39,49 +39,22 @@ export default class SQLHParons extends RunestoneBase {
3939
this.divid = opts.orig.id;
4040
this.code = $(orig).text() || "\n\n\n\n\n";
4141
this.language = $(orig).data("lang");
42-
this.timelimit = $(orig).data("timelimit");
4342
this.includes = $(orig).data("include");
44-
this.hidecode = $(orig).data("hidecode");
45-
this.chatcodes = $(orig).data("chatcodes");
4643
this.hidehistory = $(orig).data("hidehistory");
4744
this.question = $(opts.orig).find(`#${this.divid}_question`)[0];
4845
this.tie = $(orig).data("tie");
4946
this.dburl = $(orig).data("dburl");
5047
this.runButton = null;
51-
this.enabledownload = $(orig).data("enabledownload");
52-
this.downloadButton = null;
5348
this.saveButton = null;
5449
this.loadButton = null;
5550
this.outerDiv = null;
5651
this.partner = "";
5752
this.logResults = true;
58-
if (!eBookConfig.allow_pairs || $(orig).data("nopair")) {
59-
this.enablePartner = false;
60-
} else {
61-
this.enablePartner = true;
62-
}
6353
this.output = null; // create pre for output
64-
this.graphics = null; // create div for turtle graphics
65-
this.codecoach = null;
66-
this.codelens = null;
6754
this.controlDiv = null;
6855
this.historyScrubber = null;
6956
this.timestamps = ["Original"];
7057
this.autorun = $(orig).data("autorun");
71-
if (this.chatcodes && eBookConfig.enable_chatcodes) {
72-
if (!socket) {
73-
socket = new WebSocket("wss://" + chatcodesServer);
74-
}
75-
if (!connection) {
76-
connection = new window.sharedb.Connection(socket);
77-
}
78-
if (!doc) {
79-
doc = connection.get("chatcodes", "channels");
80-
}
81-
}
82-
if (this.graderactive || this.isTimed) {
83-
this.hidecode = false;
84-
}
8558
if (this.includes) {
8659
this.includes = this.includes.split(/\s+/);
8760
}
@@ -281,52 +254,23 @@ export default class SQLHParons extends RunestoneBase {
281254
}
282255
});
283256
this.editor = editor;
284-
if (this.hidecode) {
285-
$(this.codeDiv).css("display", "none");
286-
}
287257
}
288258

289259
// copied from activecode
290260
createOutput() {
291261
// Create a parent div with two elements: pre for standard output and a div
292262
// to hold turtle graphics output. We use a div in case the turtle changes from
293-
// using a canvas to using some other element like svg in the future.
294263
var outDiv = document.createElement("div");
295264
$(outDiv).addClass("ac_output col-md-12");
296265
this.outDiv = outDiv;
297266
this.output = document.createElement("pre");
298267
this.output.id = this.divid + "_stdout";
299268
$(this.output).css("visibility", "hidden");
300-
this.graphics = document.createElement("div");
301-
this.graphics.id = this.divid + "_graphics";
302-
$(this.graphics).addClass("ac-canvas");
303-
// This bit of magic adds an event which waits for a canvas child to be created on our
304-
// newly created div. When a canvas child is added we add a new class so that the visible
305-
// canvas can be styled in CSS. Which a the moment means just adding a border.
306-
$(this.graphics).on(
307-
"DOMNodeInserted",
308-
"canvas",
309-
function () {
310-
$(this.graphics).addClass("visible-ac-canvas");
311-
}.bind(this)
312-
);
313269
var clearDiv = document.createElement("div");
314270
$(clearDiv).css("clear", "both"); // needed to make parent div resize properly
315271
this.outerDiv.appendChild(clearDiv);
316272
outDiv.appendChild(this.output);
317-
outDiv.appendChild(this.graphics);
318273
this.outerDiv.appendChild(outDiv);
319-
var lensDiv = document.createElement("div");
320-
lensDiv.id = `${this.divid}_codelens`;
321-
$(lensDiv).addClass("col-md-12");
322-
$(lensDiv).css("display", "none");
323-
this.codelens = lensDiv;
324-
this.outerDiv.appendChild(lensDiv);
325-
var coachDiv = document.createElement("div");
326-
$(coachDiv).addClass("col-md-12");
327-
$(coachDiv).css("display", "none");
328-
this.codecoach = coachDiv;
329-
this.outerDiv.appendChild(coachDiv);
330274
clearDiv = document.createElement("div");
331275
$(clearDiv).css("clear", "both"); // needed to make parent div resize properly
332276
this.outerDiv.appendChild(clearDiv);
@@ -348,12 +292,9 @@ export default class SQLHParons extends RunestoneBase {
348292
this.runButton.onclick = this.runButtonHandler.bind(this);
349293
$(butt).attr("type", "button");
350294

351-
if (!this.hidecode && !this.hidehistory) {
295+
if (!this.hidehistory) {
352296
this.addHistoryButton(ctrlDiv);
353297
}
354-
if ($(this.origElem).data("gradebutton") && !this.graderactive) {
355-
this.addFeedbackButton(ctrlDiv);
356-
}
357298

358299
$(this.outerDiv).prepend(ctrlDiv);
359300
if (this.question) {

0 commit comments

Comments
 (0)