Skip to content

Commit 7e68c34

Browse files
committed
moar refactorings
1 parent b70b20d commit 7e68c34

2 files changed

Lines changed: 66 additions & 41 deletions

File tree

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

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ module.exports = {
4646
getAceEditor: getAceEditor,
4747
setAceEditor: setAceEditor,
4848
compressUpdateHistoryList: compressUpdateHistoryList,
49+
getQueryStringOptions: getQueryStringOptions,
50+
initializeFrontendParams: initializeFrontendParams,
4951
}
5052

5153
var originFrontendJsFile = undefined;
@@ -144,9 +146,6 @@ function setAceEditor(e) {pyInputAceEditor = e;}
144146

145147
var useCodeMirror = false; // true -> use CodeMirror, false -> use Ace
146148

147-
// a list of previous consecutive executions with "compile"-time exceptions
148-
var prevExecutionExceptionObjLst = [];
149-
150149
var CODE_SNAPSHOT_DEBOUNCE_MS = 1000;
151150

152151

@@ -848,31 +847,31 @@ function pyInputSetScrollTop(st) {
848847
}
849848

850849

850+
function initializeFrontendParams(params) {
851+
originFrontendJsFile = params.originFrontendJsFile;
852+
executeCode = params.executeCode;
853+
assert(originFrontendJsFile);
854+
assert(executeCode);
855+
856+
// optional
857+
if (params.TogetherjsReadyHandler) {
858+
TogetherjsReadyHandler = params.TogetherjsReadyHandler;
859+
}
860+
if (params.TogetherjsCloseHandler) {
861+
TogetherjsCloseHandler = params.TogetherjsCloseHandler;
862+
}
863+
if (params.initAceEditor) {
864+
initAceEditor = params.initAceEditor;
865+
}
866+
}
867+
868+
851869
var num414Tries = 0; // hacky global
852870

853871
// run at the END so that everything else can be initialized first
854872
function genericOptFrontendReady(params) {
855873
assert(params);
856-
857-
function initializeFrontend(params) {
858-
originFrontendJsFile = params.originFrontendJsFile;
859-
executeCode = params.executeCode;
860-
assert(originFrontendJsFile);
861-
assert(executeCode);
862-
863-
// optional
864-
if (params.TogetherjsReadyHandler) {
865-
TogetherjsReadyHandler = params.TogetherjsReadyHandler;
866-
}
867-
if (params.TogetherjsCloseHandler) {
868-
TogetherjsCloseHandler = params.TogetherjsCloseHandler;
869-
}
870-
if (params.initAceEditor) {
871-
initAceEditor = params.initAceEditor;
872-
}
873-
}
874-
initializeFrontend(params);
875-
874+
initializeFrontendParams(params);
876875
initTogetherJS(); // initialize early
877876

878877

@@ -1387,7 +1386,7 @@ function updateAppDisplay(newAppMode) {
13871386

13881387
function executeCodeFromScratch() {
13891388
// don't execute empty string:
1390-
if ($.trim(pyInputGetValue()) == '') {
1389+
if (pyInputAceEditor && $.trim(pyInputGetValue()) == '') {
13911390
setFronendError(["Type in some code to visualize."]);
13921391
return;
13931392
}
@@ -1484,12 +1483,6 @@ function optFinishSuccessfulExecution() {
14841483
// For version 3+, dynamically generate a survey whenever the user
14851484
// successfully executes a piece of code
14861485
initializeDisplayModeSurvey();
1487-
1488-
if (typeof(activateSyntaxErrorSurvey) !== 'undefined' &&
1489-
activateSyntaxErrorSurvey &&
1490-
experimentalPopUpSyntaxErrorSurvey) {
1491-
experimentalPopUpSyntaxErrorSurvey();
1492-
}
14931486
}
14941487

14951488

@@ -1643,13 +1636,6 @@ function executeCodeAndCreateViz(codeToExec,
16431636
});
16441637
}
16451638

1646-
if (killerException) {
1647-
var excObj = {killerException: killerException, myAppState: getAppState()};
1648-
prevExecutionExceptionObjLst.push(excObj);
1649-
} else {
1650-
prevExecutionExceptionObjLst = []; // reset!!!
1651-
}
1652-
16531639
// tricky hacky reset
16541640
num414Tries = 0;
16551641
}

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22
// Copyright (C) Philip Guo (philip@pgbovine.net)
33
// LICENSE: https://github.com/pgbovine/OnlinePythonTutor/blob/master/LICENSE.txt
44

5+
// TODOs:
6+
// qtip doesn't work with Webpack, so experimentalPopUpSyntaxErrorSurvey DOESN'T WORK
7+
// deactivate it for now
8+
var activateSyntaxErrorSurvey = false; // true;
9+
// a list of previous consecutive executions with "compile"-time exceptions
10+
var prevExecutionExceptionObjLst = [];
11+
12+
513
// use Webpack to automatically package up these dependencies
614
//require('./jquery-1.8.2.min.js');
715
require('./jquery-3.0.0.min.js');
816
require('./jquery.ba-bbq.js'); // contains slight pgbovine modifications
17+
require('./jquery.qtip.min.js');
18+
require('../css/jquery.qtip.css');
919

1020
// just punt and use global script dependencies
1121
require("script!./ace/src-min-noconflict/ace.js");
@@ -32,7 +42,6 @@ require('../css/opt-frontend.css');
3242

3343
var originFrontendJsFile = 'opt-frontend.js';
3444

35-
var activateSyntaxErrorSurvey = true; // true;
3645

3746
function startSharedSession() { // override default
3847
$("#ssDiv,#surveyHeader").hide(); // hide ASAP!
@@ -70,8 +79,38 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
7079
backend_script, backendOptionsObj,
7180
frontendOptionsObj,
7281
'pyOutputPane',
73-
optCommon.optFinishSuccessfulExecution,
74-
optCommon.handleUncaughtExceptionFunc);
82+
optFrontendFinishSuccessfulExecution,
83+
optFrontendHandleUncaughtException);
84+
}
85+
86+
function optFrontendFinishSuccessfulExecution() {
87+
optCommon.optFinishSuccessfulExecution();
88+
89+
if (typeof(activateSyntaxErrorSurvey) !== 'undefined' &&
90+
activateSyntaxErrorSurvey &&
91+
experimentalPopUpSyntaxErrorSurvey) {
92+
experimentalPopUpSyntaxErrorSurvey();
93+
}
94+
}
95+
96+
function optFrontendHandleUncaughtException(trace) {
97+
optCommon.handleUncaughtExceptionFunc(trace);
98+
99+
var killerException = null;
100+
101+
if (trace.length == 1) {
102+
killerException = trace[0]; // killer!
103+
}
104+
else if (trace.length > 0 && trace[trace.length - 1].exception_msg) {
105+
killerException = trace[trace.length - 1]; // killer!
106+
}
107+
108+
if (killerException) {
109+
var excObj = {killerException: killerException, myAppState: optCommon.getAppState()};
110+
prevExecutionExceptionObjLst.push(excObj);
111+
} else {
112+
prevExecutionExceptionObjLst = []; // reset!!!
113+
}
75114
}
76115

77116

@@ -173,7 +212,7 @@ function experimentalPopUpSyntaxErrorSurvey() {
173212

174213
// destroy then create a new tip:
175214
bub.destroyQTip();
176-
$(bub.hashID).qtip($.extend({}, qtipShared, {
215+
$(bub.hashID).qtip($.extend({}, pytutor.qtipShared, {
177216
content: ' ', // can't be empty!
178217
id: bub.domID,
179218
position: {

0 commit comments

Comments
 (0)