Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localstorage #23

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
41 changes: 36 additions & 5 deletions runestone/activecode/js/activecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class ActiveCode extends RunestoneBase {
this.runButton = null;
this.enabledownload = $(orig).data("enabledownload");
this.downloadButton = null;
this.resetButton = null;
this.saveButton = null;
this.loadButton = null;
this.outerDiv = null;
Expand Down Expand Up @@ -167,7 +168,11 @@ export class ActiveCode extends RunestoneBase {
} else if (edmode === "octave" || edmode === "MATLAB") {
edmode = "text/x-octave";
}
var editor = CodeMirror(codeDiv, {

if(localStorage.getItem(this.divid) !== null)
this.code = localStorage.getItem(this.divid);

var opts = {
value: this.code,
lineNumbers: true,
mode: edmode,
Expand All @@ -178,7 +183,9 @@ export class ActiveCode extends RunestoneBase {
Tab: "indentMore",
"Shift-Tab": "indentLess",
},
});
}
var editor = CodeMirror(codeDiv,opts );

// Make the editor resizable
$(editor.getWrapperElement()).resizable({
resize: function () {
Expand Down Expand Up @@ -242,7 +249,7 @@ export class ActiveCode extends RunestoneBase {
}

async runButtonHandler() {
// Disable the run button until the run is finished.
// Disable the run button until the run is finished.
this.runButton.disabled = true;
try {
await this.runProg();
Expand Down Expand Up @@ -272,6 +279,8 @@ export class ActiveCode extends RunestoneBase {
this.runButton.onclick = this.runButtonHandler.bind(this);
$(butt).attr("type", "button");

this.addResetButton(ctrlDiv);

if (this.enabledownload || eBookConfig.downloadsEnabled) {
this.addDownloadButton(ctrlDiv);
}
Expand Down Expand Up @@ -348,6 +357,16 @@ export class ActiveCode extends RunestoneBase {
$(butt).attr("type", "button");
}

addResetButton(ctrlDiv) {
let butt = document.createElement("button");
$(butt).text("Reset");
$(butt).addClass("btn btn-default");
$(butt).attr("type", "button");
ctrlDiv.appendChild(butt);
this.resetButton = butt;
$(butt).click(this.resetCode.bind(this));
}

enableHideShow(ctrlDiv) {
$(this.runButton).attr("disabled", "disabled");
let butt = document.createElement("button");
Expand Down Expand Up @@ -757,6 +776,11 @@ export class ActiveCode extends RunestoneBase {
}
}

resetCode() {
localStorage.removeItem(this.divid);
window.location.reload();
}

async createGradeSummary() {
// get grade and comments for this assignment
// get summary of all grades for this student
Expand Down Expand Up @@ -1190,7 +1214,7 @@ Yet another is that there is an internal error. The internal error message is:
}

logCurrentAnswer() {
this.logRunEvent({
let data = {
div_id: this.divid,
code: this.editor.getValue(),
lang: this.language,
Expand All @@ -1199,7 +1223,11 @@ Yet another is that there is an internal error. The internal error message is:
prefix: this.pretext,
suffix: this.suffix,
partner: this.partner,
}); // Log the run event
};

localStorage.setItem(this.divid, data['code']);

this.logRunEvent(data); // Log the run event
// If unit tests were run there will be a unit_results
if (this.unit_results) {
this.logBookEvent({
Expand Down Expand Up @@ -1285,6 +1313,9 @@ Yet another is that there is an internal error. The internal error message is:
});
Sk.divid = this.divid;
Sk.logResults = logResults;

localStorage.setItem(this.divid,this.code);

if (this.graderactive && this.outerDiv.closest(".loading")) {
Sk.gradeContainer = this.outerDiv.closest(".loading").id;
} else {
Expand Down

Large diffs are not rendered by default.

355 changes: 323 additions & 32 deletions runestone/dist/runestone.bundle.js

Large diffs are not rendered by default.

Loading