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

Commit f1523dd

Browse files
committed
Fix: do not load history if not logged in
1 parent 9e9ac35 commit f1523dd

File tree

1 file changed

+49
-53
lines changed

1 file changed

+49
-53
lines changed

runestone/activecode/js/activecode.js

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ import embed from "vega-embed";
3636
window.vegaEmbed = embed;
3737

3838
var isMouseDown = false;
39-
document.onmousedown = function () {
39+
document.onmousedown = function() {
4040
isMouseDown = true;
4141
};
4242

43-
document.onmouseup = function () {
43+
document.onmouseup = function() {
4444
isMouseDown = false;
4545
};
4646
window.edList = {};
4747

4848
var socket, connection, doc;
4949
var chatcodesServer = "chat.codes";
5050

51-
CodeMirror.commands.autocomplete = function (cm) {
51+
CodeMirror.commands.autocomplete = function(cm) {
5252
cm.showHint({ hint: CodeMirror.hint.anyword });
5353
};
5454

@@ -135,7 +135,7 @@ export class ActiveCode extends RunestoneBase {
135135
}
136136
this.addCaption("runestone");
137137
setTimeout(
138-
function () {
138+
function() {
139139
this.editor.refresh();
140140
}.bind(this),
141141
1000
@@ -190,15 +190,15 @@ export class ActiveCode extends RunestoneBase {
190190
});
191191
// Make the editor resizable
192192
$(editor.getWrapperElement()).resizable({
193-
resize: function () {
193+
resize: function() {
194194
editor.setSize($(this).width(), $(this).height());
195195
editor.refresh();
196196
},
197197
});
198198
// give the user a visual cue that they have changed but not saved
199199
editor.on(
200200
"change",
201-
function (ev) {
201+
function(ev) {
202202
if (
203203
editor.acEditEvent == false ||
204204
editor.acEditEvent === undefined
@@ -208,7 +208,7 @@ export class ActiveCode extends RunestoneBase {
208208
// offsetParent === null means that the element is not on the screen and so can't change
209209
// this.controlDiv.offsetParent
210210
if (this.origText === editor.getValue() ||
211-
this.addingScrubber ) {
211+
this.addingScrubber) {
212212
console.log("Fake change event, skipping the log");
213213
return;
214214
}
@@ -232,16 +232,16 @@ export class ActiveCode extends RunestoneBase {
232232
}.bind(this)
233233
); // use bind to preserve *this* inside the on handler.
234234
//Solving Keyboard Trap of ActiveCode: If user use tab for navigation outside of ActiveCode, then change tab behavior in ActiveCode to enable tab user to tab out of the textarea
235-
$(window).keydown(function (e) {
235+
$(window).keydown(function(e) {
236236
var code = e.keyCode ? e.keyCode : e.which;
237237
if (code == 9 && $("textarea:focus").length === 0) {
238238
editor.setOption("extraKeys", {
239-
Tab: function (cm) {
239+
Tab: function(cm) {
240240
$(document.activeElement)
241241
.closest(".tab-content")
242242
.nextSibling.focus();
243243
},
244-
"Shift-Tab": function (cm) {
244+
"Shift-Tab": function(cm) {
245245
$(document.activeElement)
246246
.closest(".tab-content")
247247
.previousSibling.focus();
@@ -361,7 +361,7 @@ export class ActiveCode extends RunestoneBase {
361361
this.showHideButt = butt;
362362
ctrlDiv.appendChild(butt);
363363
$(butt).click(
364-
function () {
364+
function() {
365365
$(this.codeDiv).toggle();
366366
if (this.historyScrubber == null) {
367367
this.addHistoryScrubber(true);
@@ -407,7 +407,7 @@ export class ActiveCode extends RunestoneBase {
407407
this.atButton = butt;
408408
ctrlDiv.appendChild(butt);
409409
$(butt).click(
410-
function () {
410+
function() {
411411
new AudioTour(
412412
this.divid,
413413
this.code,
@@ -426,7 +426,7 @@ export class ActiveCode extends RunestoneBase {
426426
this.shareButt = butt;
427427
ctrlDiv.appendChild(butt);
428428
$(butt).click(
429-
async function () {
429+
async function() {
430430
if (
431431
!confirm(
432432
"You are about to share this code with ALL of your students. Are you sure you want to continue?"
@@ -440,8 +440,7 @@ export class ActiveCode extends RunestoneBase {
440440
lang: this.language,
441441
};
442442
let request = new Request(
443-
eBookConfig.ajaxURL + "broadcast_code.json",
444-
{
443+
eBookConfig.ajaxURL + "broadcast_code.json", {
445444
method: "POST",
446445
headers: this.jsonHeaders,
447446
body: JSON.stringify(data),
@@ -468,7 +467,7 @@ export class ActiveCode extends RunestoneBase {
468467
$(plabel).text("Pair?");
469468
ctrlDiv.appendChild(plabel);
470469
$(checkPartner).click(
471-
function () {
470+
function() {
472471
if (this.partner) {
473472
this.partner = false;
474473
$(partnerTextBox).hide();
@@ -480,8 +479,8 @@ export class ActiveCode extends RunestoneBase {
480479
if (!didAgree) {
481480
didAgree = confirm(
482481
"Pair Programming should only be used with the consent of your instructor." +
483-
"Your partner must be a registered member of the class and have agreed to pair with you." +
484-
"By clicking OK you certify that both of these conditions have been met."
482+
"Your partner must be a registered member of the class and have agreed to pair with you." +
483+
"By clicking OK you certify that both of these conditions have been met."
485484
);
486485
if (didAgree) {
487486
localStorage.setItem("partnerAgree", "true");
@@ -500,7 +499,7 @@ export class ActiveCode extends RunestoneBase {
500499
ctrlDiv.appendChild(partnerTextBox);
501500
$(partnerTextBox).hide();
502501
$(partnerTextBox).change(
503-
function () {
502+
function() {
504503
this.partner = partnerTextBox.value;
505504
}.bind(this)
506505
);
@@ -524,21 +523,21 @@ export class ActiveCode extends RunestoneBase {
524523
$(butt).attr(
525524
"href",
526525
"http://" +
527-
chatcodesServer +
528-
"/new?" +
529-
$.param({
530-
topic: window.location.host + "-" + this.divid,
531-
code: this.editor.getValue(),
532-
lang: "Python",
533-
})
526+
chatcodesServer +
527+
"/new?" +
528+
$.param({
529+
topic: window.location.host + "-" + this.divid,
530+
code: this.editor.getValue(),
531+
lang: "Python",
532+
})
534533
);
535534
this.chatButton = butt;
536535
chatBar.appendChild(butt);
537-
var updateChatCodesChannels = function () {
536+
var updateChatCodesChannels = function() {
538537
var data = doc.data;
539538
var i = 1;
540539
$(channels).html("");
541-
data["channels"].forEach(function (channel) {
540+
data["channels"].forEach(function(channel) {
542541
if (!channel.archived && topic === channel.topic) {
543542
var link = $("<a />");
544543
var href =
@@ -581,16 +580,14 @@ export class ActiveCode extends RunestoneBase {
581580
}
582581
console.log("before get hist");
583582
if (
584-
eBookConfig.practice_mode ||
583+
eBookConfig.practice_mode || !eBookConfig.isLoggedIn ||
585584
(this.isTimed && !this.assessmentTaken)
586585
) {
587586
// If this is timed and already taken we should restore history info
588587
this.renderScrubber();
589588
} else {
590-
// TODO: If the user is not logged in there is no point in getting history
591589
let request = new Request(
592-
`${eBookConfig.new_server_prefix}/assessment/gethist`,
593-
{
590+
`${eBookConfig.new_server_prefix}/assessment/gethist`, {
594591
method: "POST",
595592
headers: this.jsonHeaders,
596593
body: JSON.stringify(reqData),
@@ -634,7 +631,7 @@ export class ActiveCode extends RunestoneBase {
634631
});
635632
var scrubber = document.createElement("div");
636633
this.timestampP = document.createElement("span");
637-
this.slideit = function (ev, el) {
634+
this.slideit = function(ev, el) {
638635
this.editor.setValue(this.history[$(scrubber).slider("value")]);
639636
var curVal = this.timestamps[$(scrubber).slider("value")];
640637
let pos = $(scrubber).slider("value");
@@ -708,7 +705,7 @@ export class ActiveCode extends RunestoneBase {
708705
$(this.graphics).on(
709706
"DOMNodeInserted",
710707
"canvas",
711-
function () {
708+
function() {
712709
$(this.graphics).addClass("visible-ac-canvas");
713710
}.bind(this)
714711
);
@@ -748,10 +745,10 @@ export class ActiveCode extends RunestoneBase {
748745
fnb +
749746
"_" +
750747
d
751-
.toJSON()
752-
.substring(0, 10) // reverse date format
753-
.split("-")
754-
.join("") +
748+
.toJSON()
749+
.substring(0, 10) // reverse date format
750+
.split("-")
751+
.join("") +
755752
"." +
756753
languageExtensions[lang];
757754
var code = this.editor.getValue();
@@ -1028,10 +1025,10 @@ Yet another is that there is an internal error. The internal error message is:
10281025
$.ajax({
10291026
async: false,
10301027
url: `/runestone/ajax/get_datafile?course_id=${eBookConfig.course}&acid=${divid}`,
1031-
success: function (data) {
1028+
success: function(data) {
10321029
result = JSON.parse(data).data;
10331030
},
1034-
error: function (err) {
1031+
error: function(err) {
10351032
result = null;
10361033
},
10371034
});
@@ -1055,7 +1052,7 @@ Yet another is that there is an internal error. The internal error message is:
10551052
}
10561053
outputfun(text) {
10571054
// bnm python 3
1058-
var pyStr = function (x) {
1055+
var pyStr = function(x) {
10591056
if (x instanceof Array) {
10601057
return "[" + x.join(", ") + "]";
10611058
} else {
@@ -1081,9 +1078,9 @@ Yet another is that there is an internal error. The internal error message is:
10811078
.replace(/>/g, "&gt;")
10821079
.replace(/\n/g, "<br/>");
10831080
return Promise.resolve().then(
1084-
function () {
1081+
function() {
10851082
setTimeout(
1086-
function () {
1083+
function() {
10871084
$(this.output).append(text);
10881085
}.bind(this),
10891086
0
@@ -1127,8 +1124,7 @@ Yet another is that there is an internal error. The internal error message is:
11271124
return window.edList[divid].editor.getValue();
11281125
} else {
11291126
let request = new Request(
1130-
`/runestone/ajax/get_datafile?course_id=${eBookConfig.course}&acid=${divid}`,
1131-
{
1127+
`/runestone/ajax/get_datafile?course_id=${eBookConfig.course}&acid=${divid}`, {
11321128
method: "GET",
11331129
headers: this.jsonHeaders,
11341130
}
@@ -1175,7 +1171,7 @@ Yet another is that there is an internal error. The internal error message is:
11751171
if (
11761172
this.historyScrubber &&
11771173
this.history[$(this.historyScrubber).slider("value")] !=
1178-
this.editor.getValue()
1174+
this.editor.getValue()
11791175
) {
11801176
saveCode = "True";
11811177
this.history.push(this.editor.getValue());
@@ -1258,7 +1254,7 @@ Yet another is that there is an internal error. The internal error message is:
12581254
if (
12591255
$(this.outerDiv).find(`#${urDivid}`).length == 0 &&
12601256
$(this.outerDiv).find(`#${urDivid}_offscreen_unit_results`)
1261-
.length == 0
1257+
.length == 0
12621258
) {
12631259
let urResults = document.getElementById(urDivid);
12641260
this.outerDiv.appendChild(urResults);
@@ -1267,10 +1263,10 @@ Yet another is that there is an internal error. The internal error message is:
12671263
}
12681264
}
12691265

1270-
toggleAlert(){
1266+
toggleAlert() {
12711267
if (this.is_toggle && this.runCount == 3) {
1272-
if (this.errinfo != "success" || this.unit_results.substring(8,11)!=100.0){
1273-
setTimeout(function() {alert("Help is Available Using the Toggle Question Selector! You can try the Mixed-up Question first."); }, 500);
1268+
if (this.errinfo != "success" || this.unit_results.substring(8, 11) != 100.0) {
1269+
setTimeout(function() { alert("Help is Available Using the Toggle Question Selector! You can try the Mixed-up Question first."); }, 500);
12741270
this.logBookEvent({
12751271
event: "togglealert",
12761272
act: "Help is Available Using the Toggle Question Selector",
@@ -1345,7 +1341,7 @@ Yet another is that there is an internal error. The internal error message is:
13451341
});
13461342
}
13471343
try {
1348-
await Sk.misceval.asyncToPromise(function () {
1344+
await Sk.misceval.asyncToPromise(function() {
13491345
return Sk.importMainWithBody("<stdin>", false, prog, true);
13501346
});
13511347
if (!noUI) {
@@ -1372,7 +1368,7 @@ Yet another is that there is an internal error. The internal error message is:
13721368
} finally {
13731369
$(this.runButton).removeAttr("disabled");
13741370
if (typeof window.allVisualizers != "undefined") {
1375-
$.each(window.allVisualizers, function (i, e) {
1371+
$.each(window.allVisualizers, function(i, e) {
13761372
e.redrawConnectors();
13771373
});
13781374
}
@@ -1445,6 +1441,6 @@ errorText.KeyErrorFix = $.i18n("msg_activecode_key_error_fix");
14451441
errorText.AssertionError = $.i18n("msg_activecode_assertion_error");
14461442
errorText.AssertionErrorFix = $.i18n("msg_activecode_assertion_error_fix");
14471443

1448-
String.prototype.replaceAll = function (target, replacement) {
1444+
String.prototype.replaceAll = function(target, replacement) {
14491445
return this.split(target).join(replacement);
14501446
};

0 commit comments

Comments
 (0)