From 39ff04c4ea1597e805ce0fed009bea72667cf695 Mon Sep 17 00:00:00 2001 From: Kristi Nakaj Date: Fri, 22 Jul 2022 11:51:55 -0400 Subject: [PATCH] issue#1034 fixed, added a Reset button on active code component --- runestone/accessibility/css/accessibility.css | 14 ++++++++ runestone/activecode/js/activecode.js | 33 +++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/runestone/accessibility/css/accessibility.css b/runestone/accessibility/css/accessibility.css index 3e39702c8..a6de32c09 100644 --- a/runestone/accessibility/css/accessibility.css +++ b/runestone/accessibility/css/accessibility.css @@ -152,4 +152,18 @@ button.btn.btn-link:focus { button.btn.btn-link { color:#1a6a83 !important; background-color:#FFFFFF !important; +} + +/*Reset Button*/ +button.btn.btn-reset:active { + color:#d78080!important; + background-color:#FFFFFF !important; +} +button.btn.btn-reset:focus { + color:#d78080 !important; + background-color:#FFFFFF !important; +} +button.btn.btn-reset{ + color:#FFFFFF !important; + background-color:#d78080 !important; } \ No newline at end of file diff --git a/runestone/activecode/js/activecode.js b/runestone/activecode/js/activecode.js index 395bd7941..be0d53368 100755 --- a/runestone/activecode/js/activecode.js +++ b/runestone/activecode/js/activecode.js @@ -81,6 +81,7 @@ export class ActiveCode extends RunestoneBase { this.saveButton = null; this.loadButton = null; this.outerDiv = null; + this.resetButt = null; this.partner = ""; this.runCount = 0; this.logResults = true; @@ -281,7 +282,7 @@ export class ActiveCode extends RunestoneBase { $(butt).addClass("btn btn-success run-button"); ctrlDiv.appendChild(butt); this.runButton = butt; - console.log("adding click function for run"); + console.log("adding click function for run"); this.runButton.onclick = this.runButtonHandler.bind(this); $(butt).attr("type", "button"); @@ -309,13 +310,16 @@ export class ActiveCode extends RunestoneBase { if (eBookConfig.isInstructor) { this.enableInstructorSharing(ctrlDiv); } + + this.addReset(ctrlDiv); + if (this.enablePartner) { this.setupPartner(ctrlDiv); } if (this.chatcodes && eBookConfig.enable_chatcodes) { this.enableChatCodes(ctrlDiv); } - + $(this.outerDiv).prepend(ctrlDiv); if (this.question) { if ($(this.question).html().match(/^\s+$/)) { @@ -468,6 +472,26 @@ export class ActiveCode extends RunestoneBase { ); } + addReset(ctrlDiv){ + let butt = document.createElement("button"); + $(butt).text("Reset"); + ctrlDiv.appendChild(butt); + $(butt).addClass("btn btn-reset"); + $(butt).css("margin-right", "10px"); + $(butt).attr("type", "button"); + $(butt).attr("target", "_blank"); + this.resetButt = butt + $(butt).click( + function(){ + this.history = [this.history[0]]; + this.editor.setValue(this.history[0]); + $(this.historyScrubber).slider("value", 0) + $(this.timestampP).text(`${this.timestamps[0]} - 1 of 1`); + $(this.historyScrubber).slider("disable"); + }.bind(this) + ) + } + setupPartner(ctrlDiv) { var checkPartner = document.createElement("input"); checkPartner.type = "checkbox"; @@ -640,7 +664,7 @@ export class ActiveCode extends RunestoneBase { "max-width": "300px", }); var scrubber = document.createElement("div"); - this.timestampP = document.createElement("span"); + this.timestampP = document.createElement("span"); this.slideit = function () { this.editor.setValue(this.history[$(scrubber).slider("value")]); var curVal = this.timestamps[$(scrubber).slider("value")]; @@ -1177,6 +1201,9 @@ Yet another is that there is an internal error. The internal error message is: if (this.historyScrubber === null && !this.autorun) { await this.addHistoryScrubber(); } + if (this.history.length > 0){ + $(this.historyScrubber).slider("enable"); + } if ( this.historyScrubber && this.history[$(this.historyScrubber).slider("value")] !=