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

Commit a99c632

Browse files
authored
Merge branch 'master' into num_fix
2 parents 70cab26 + 0042a6c commit a99c632

2 files changed

Lines changed: 36 additions & 31 deletions

File tree

runestone/lp/js/lp.js

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class LP extends RunestoneBase {
4545
// Store the DOM element (a span) where feedback will be displayed.
4646
this.feedbackElement = $(this.element).siblings("div");
4747
// Use a nice editor.
48-
var that = this;
48+
let that = this;
4949
this.textAreas = [];
5050
$(".code_snippet").each(function (index, element) {
51-
var editor = CodeMirror.fromTextArea(element, {
51+
let editor = CodeMirror.fromTextArea(element, {
5252
lineNumbers: true,
5353
mode: $(that.element).attr("data-lang"),
5454
indentUnit: 4,
@@ -68,41 +68,46 @@ class LP extends RunestoneBase {
6868
});
6969
this.checkServer("lp_build");
7070
// Handle clicks to the "Save and run" button.
71-
$(this.element).click(function (eventObject) {
72-
$(that.resultElement).val("Building...");
73-
$(that.feedbackElement).text("").attr("");
74-
// Since the Save and run button was clicked, we assume the code snippets have been changed; therefore, don't store ``correct`` or ``answer.resultString`` because they are out of date.
75-
let answer = { code_snippets: that.textareasToData() };
76-
that.setLocalStorage({
77-
answer: answer,
78-
timestamp: new Date(),
79-
});
80-
that.logBookEvent({
71+
$(this.element).click((eventObject) => that.onSaveAndRun(eventObject).then(null));
72+
}
73+
74+
async onSaveAndRun(_eventObject) {
75+
$(this.resultElement).val("Building...");
76+
$(this.feedbackElement).text("").attr("");
77+
// Since the Save and run button was clicked, we assume the code snippets have been changed; therefore, don't store ``correct`` or ``answer.resultString`` because they are out of date.
78+
let answer = { code_snippets: this.textareasToData() };
79+
this.setLocalStorage({
80+
answer: answer,
81+
timestamp: new Date(),
82+
});
83+
// Store the answer that the server returns, which includes additional data (correct/incorrect, feedback from the build, etc.).
84+
let serverAnswer;
85+
try {
86+
serverAnswer = await this.logBookEvent({
8187
event: "lp_build",
8288
// All values must be strings, or the resulting values on the server side come out confused.
8389
answer: JSON.stringify(answer),
8490
// Find the relative path to this web page. Slice off the leading ``/``.
8591
path: window.location.href
8692
.replace(eBookConfig.app, "")
8793
.slice(1),
88-
div_id: that.divid,
89-
})
90-
.done(function (data) {
91-
// The server doesn't return the ``code_snippets``, for efficiency. Include those. If an error was returned, note that there is no ``answer`` yet.
92-
if (!("answer" in data)) {
93-
data["answer"] = {};
94-
}
95-
data["answer"]["code_snippets"] = that.textareasToData();
96-
that.displayAnswer(data);
97-
that.setLocalStorage(data);
98-
})
99-
.fail(function () {
100-
$(that.feedbackElement)
101-
.val("Error contacting server.")
102-
.attr("class", "alert alert-danger");
103-
});
104-
});
94+
div_id: this.divid,
95+
});
96+
} catch (err) {
97+
$(this.feedbackElement)
98+
.val(`Error contacting server: {err}.`)
99+
.attr("class", "alert alert-danger");
100+
return;
101+
}
102+
// The server doesn't return the ``code_snippets``, for efficiency. Include those. If an error was returned, note that there is no ``answer`` yet.
103+
if (!("answer" in serverAnswer)) {
104+
serverAnswer["answer"] = {};
105+
}
106+
serverAnswer["answer"]["code_snippets"] = this.textareasToData();
107+
this.displayAnswer(serverAnswer);
108+
this.setLocalStorage(serverAnswer);
105109
}
110+
106111
// Given a single answer, display it.
107112
displayAnswer(data) {
108113
if ("errors" in data) {

runestone/server/componentdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from sphinx.util import logging
3434
from sqlalchemy import create_engine, Table, MetaData, select, and_, or_
3535
from sqlalchemy.orm.session import sessionmaker
36-
import pdb
3736

3837
from runestone.common.runestonedirective import RunestoneDirective, RunestoneIdNode
3938

@@ -723,7 +722,8 @@ def update_chapter_subchapter(
723722
else:
724723
currentRowId = res.id
725724

726-
for sub in subtitles[chap]:
725+
# If this chapter doesn't have subchapters, then skip them -- hence, use ``subtitles.get(chap, [])`` instead of ``subtitles[chap]``.
726+
for sub in subtitles.get(chap, []):
727727
if (chap, sub) in skips:
728728
skipreading = "T"
729729
else:

0 commit comments

Comments
 (0)