Skip to content

Commit 61a9cf6

Browse files
committed
more rejiggling
1 parent 4a9dc74 commit 61a9cf6

2 files changed

Lines changed: 74 additions & 80 deletions

File tree

‎v5-unity/js/opt-frontend-common.ts‎

Lines changed: 23 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ export abstract class AbstractBaseFrontend {
117117

118118
num414Tries = 0;
119119

120+
abstract executeCode(forceStartingInstr?: number, forceRawInputLst?: string[]) : any;
121+
abstract handleUncaughtExceptionFunc(trace: any[]) : any;
122+
120123
constructor(params: any = {}) {
121124
// optional params -- TODO: handle later
122125
/*
@@ -227,12 +230,6 @@ export abstract class AbstractBaseFrontend {
227230
// override this with a version in codeopticon-learner.js if needed
228231
logEventCodeopticon(obj) { } // NOP
229232

230-
231-
abstract executeCode(forceStartingInstr?: number, forceRawInputLst?: string[]) : any;
232-
abstract handleUncaughtExceptionFunc(trace: any[]) : any;
233-
appStateAugmenter: (appState) => {} // NOP
234-
loadTestCases: (testCasesLst) => {} // NOP
235-
236233
setFronendError(lines) {
237234
$("#frontendErrorOutput").html(lines.map(pytutor.htmlspecialchars).join('<br/>'));
238235
}
@@ -241,6 +238,26 @@ export abstract class AbstractBaseFrontend {
241238
$("#frontendErrorOutput").html('');
242239
}
243240

241+
// parsing the URL query string hash
242+
getQueryStringOptions() {
243+
var ril = $.bbq.getState('rawInputLstJSON');
244+
var testCasesLstJSON = $.bbq.getState('testCasesJSON');
245+
// note that any of these can be 'undefined'
246+
return {preseededCode: $.bbq.getState('code'),
247+
preseededCurInstr: Number($.bbq.getState('curInstr')),
248+
verticalStack: $.bbq.getState('verticalStack'),
249+
appMode: $.bbq.getState('mode'),
250+
py: $.bbq.getState('py'),
251+
cumulative: $.bbq.getState('cumulative'),
252+
heapPrimitives: $.bbq.getState('heapPrimitives'),
253+
textReferences: $.bbq.getState('textReferences'),
254+
rawInputLst: ril ? $.parseJSON(ril) : undefined,
255+
codeopticonSession: $.bbq.getState('cosession'),
256+
codeopticonUsername: $.bbq.getState('couser'),
257+
testCasesLst: testCasesLstJSON ? $.parseJSON(testCasesLstJSON) : undefined
258+
};
259+
}
260+
244261
redrawConnectors() {
245262
if (this.myVisualizer &&
246263
(this.appMode == 'display' ||
@@ -538,78 +555,6 @@ export abstract class AbstractBaseFrontend {
538555
}
539556
}
540557

541-
pyInputSetValue(s: string) { }; // NOP unless subclass overrides
542-
543-
parseQueryString() {
544-
var queryStrOptions = this.getQueryStringOptions();
545-
this.setToggleOptions(queryStrOptions);
546-
if (queryStrOptions.preseededCode) {
547-
this.pyInputSetValue(queryStrOptions.preseededCode);
548-
}
549-
if (queryStrOptions.rawInputLst) {
550-
this.rawInputLst = queryStrOptions.rawInputLst; // global
551-
}
552-
else {
553-
this.rawInputLst = [];
554-
}
555-
556-
if (queryStrOptions.codeopticonSession) {
557-
assert(false); // TODO: this won't currently work with Webpack, so fix it later
558-
codeopticonSession = queryStrOptions.codeopticonSession; // GLOBAL defined in codeopticon-learner.js
559-
codeopticonUsername = queryStrOptions.codeopticonUsername; // GLOBAL defined in codeopticon-learner.js
560-
}
561-
562-
if (queryStrOptions.testCasesLst && this.loadTestCases) {
563-
this.loadTestCases(queryStrOptions.testCasesLst);
564-
}
565-
566-
// ugh tricky -- always start in edit mode by default, and then
567-
// switch to display mode only after the code successfully executes
568-
this.appMode = 'edit';
569-
if ((queryStrOptions.appMode == 'display' ||
570-
queryStrOptions.appMode == 'visualize' /* 'visualize' is deprecated */) &&
571-
queryStrOptions.preseededCode /* jump to display only with pre-seeded code */) {
572-
this.executeCode(queryStrOptions.preseededCurInstr); // will switch to 'display' mode
573-
}
574-
$.bbq.removeState(); // clean up the URL no matter what
575-
}
576-
577-
// parsing the URL query string hash
578-
getQueryStringOptions() {
579-
var ril = $.bbq.getState('rawInputLstJSON');
580-
var testCasesLstJSON = $.bbq.getState('testCasesJSON');
581-
// note that any of these can be 'undefined'
582-
return {preseededCode: $.bbq.getState('code'),
583-
preseededCurInstr: Number($.bbq.getState('curInstr')),
584-
verticalStack: $.bbq.getState('verticalStack'),
585-
appMode: $.bbq.getState('mode'),
586-
py: $.bbq.getState('py'),
587-
cumulative: $.bbq.getState('cumulative'),
588-
heapPrimitives: $.bbq.getState('heapPrimitives'),
589-
textReferences: $.bbq.getState('textReferences'),
590-
rawInputLst: ril ? $.parseJSON(ril) : undefined,
591-
codeopticonSession: $.bbq.getState('cosession'),
592-
codeopticonUsername: $.bbq.getState('couser'),
593-
testCasesLst: testCasesLstJSON ? $.parseJSON(testCasesLstJSON) : undefined
594-
};
595-
}
596-
597-
setToggleOptions(dat) {
598-
// ugh, ugly tristate due to the possibility of each being undefined
599-
if (dat.py !== undefined) {
600-
$('#pythonVersionSelector').val(dat.py);
601-
}
602-
if (dat.cumulative !== undefined) {
603-
$('#cumulativeModeSelector').val(dat.cumulative);
604-
}
605-
if (dat.heapPrimitives !== undefined) {
606-
$('#heapPrimitivesSelector').val(dat.heapPrimitives);
607-
}
608-
if (dat.textReferences !== undefined) {
609-
$('#textualMemoryLabelsSelector').val(dat.textReferences);
610-
}
611-
}
612-
613558
// Compress updateHistory before encoding and sending to
614559
// the server so that it takes up less room in the URL. Have each
615560
// entry except for the first be a delta from the FIRST entry.

‎v5-unity/js/opt-frontend.ts‎

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ class OptFrontend extends AbstractBaseFrontend {
272272
originFrontendJsFile: string = 'opt-frontend.js';
273273
pyInputAceEditor; // Ace editor object that contains the input code
274274

275-
appStateAugmenter;
276-
loadTestCases;
275+
appStateAugmenter: (appState: any) => void;
276+
loadTestCases: (testCasesLst: any[]) => void;
277277

278278
constructor(params) {
279279
super(params);
@@ -793,6 +793,55 @@ class OptFrontend extends AbstractBaseFrontend {
793793
return x;
794794
}
795795

796+
setToggleOptions(dat) {
797+
// ugh, ugly tristate due to the possibility of each being undefined
798+
if (dat.py !== undefined) {
799+
$('#pythonVersionSelector').val(dat.py);
800+
}
801+
if (dat.cumulative !== undefined) {
802+
$('#cumulativeModeSelector').val(dat.cumulative);
803+
}
804+
if (dat.heapPrimitives !== undefined) {
805+
$('#heapPrimitivesSelector').val(dat.heapPrimitives);
806+
}
807+
if (dat.textReferences !== undefined) {
808+
$('#textualMemoryLabelsSelector').val(dat.textReferences);
809+
}
810+
}
811+
812+
parseQueryString() {
813+
var queryStrOptions = this.getQueryStringOptions();
814+
this.setToggleOptions(queryStrOptions);
815+
if (queryStrOptions.preseededCode) {
816+
this.pyInputSetValue(queryStrOptions.preseededCode);
817+
}
818+
if (queryStrOptions.rawInputLst) {
819+
this.rawInputLst = queryStrOptions.rawInputLst; // global
820+
}
821+
else {
822+
this.rawInputLst = [];
823+
}
824+
825+
if (queryStrOptions.codeopticonSession) {
826+
assert(false); // TODO: this won't currently work with Webpack, so fix it later
827+
codeopticonSession = queryStrOptions.codeopticonSession; // GLOBAL defined in codeopticon-learner.js
828+
codeopticonUsername = queryStrOptions.codeopticonUsername; // GLOBAL defined in codeopticon-learner.js
829+
}
830+
831+
if (queryStrOptions.testCasesLst && this.loadTestCases) {
832+
this.loadTestCases(queryStrOptions.testCasesLst);
833+
}
834+
835+
// ugh tricky -- always start in edit mode by default, and then
836+
// switch to display mode only after the code successfully executes
837+
this.appMode = 'edit';
838+
if ((queryStrOptions.appMode == 'display' ||
839+
queryStrOptions.appMode == 'visualize' /* 'visualize' is deprecated */) &&
840+
queryStrOptions.preseededCode /* jump to display only with pre-seeded code */) {
841+
this.executeCode(queryStrOptions.preseededCurInstr); // will switch to 'display' mode
842+
}
843+
$.bbq.removeState(); // clean up the URL no matter what
844+
}
796845

797846
} // END class OptFrontend
798847

0 commit comments

Comments
 (0)