Skip to content

Commit df52f5f

Browse files
committed
bam
1 parent 2b12f2c commit df52f5f

8 files changed

Lines changed: 87 additions & 98 deletions

File tree

2.97 KB
Loading
2.7 KB
Loading

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ module.exports = {
3131
populateTogetherJsShareUrl: populateTogetherJsShareUrl,
3232
getAppState: getAppState,
3333
appMode: appMode,
34+
getBaseBackendOptionsObj: getBaseBackendOptionsObj,
35+
getBaseFrontendOptionsObj: getBaseFrontendOptionsObj,
3436
}
3537

3638
var originFrontendJsFile = undefined; // init in initializeFrontend
@@ -1785,6 +1787,46 @@ function submitUpdateHistory(why) {
17851787
}
17861788

17871789

1790+
function getBaseBackendOptionsObj() {
1791+
var ret = {cumulative_mode: ($('#cumulativeModeSelector').val() == 'true'),
1792+
heap_primitives: ($('#heapPrimitivesSelector').val() == 'true'),
1793+
show_only_outputs: false,
1794+
py_crazy_mode: ($('#pythonVersionSelector').val() == '2crazy'),
1795+
origin: originFrontendJsFile};
1796+
1797+
var surveyObj = getSurveyObject();
1798+
if (surveyObj) {
1799+
ret.survey = surveyObj;
1800+
}
1801+
1802+
return ret;
1803+
}
1804+
1805+
function getBaseFrontendOptionsObj() {
1806+
var ret = {// tricky: selector 'true' and 'false' values are strings!
1807+
disableHeapNesting: ($('#heapPrimitivesSelector').val() == 'true'),
1808+
textualMemoryLabels: ($('#textualMemoryLabelsSelector').val() == 'true'),
1809+
executeCodeWithRawInputFunc: executeCodeWithRawInput,
1810+
1811+
// always use the same visualizer ID for all
1812+
// instantiated ExecutionVisualizer objects,
1813+
// so that they can sync properly across
1814+
// multiple clients using TogetherJS. this
1815+
// shouldn't lead to problems since only ONE
1816+
// ExecutionVisualizer will be shown at a time
1817+
visualizerIdOverride: '1',
1818+
updateOutputCallback: function() {$('#urlOutput,#embedCodeOutput').val('');},
1819+
1820+
// undocumented experimental modes:
1821+
pyCrazyMode: ($('#pythonVersionSelector').val() == '2crazy'),
1822+
holisticMode: ($('#cumulativeModeSelector').val() == 'holistic')
1823+
};
1824+
return ret;
1825+
}
1826+
1827+
1828+
1829+
17881830
/* For survey questions:
17891831
17901832
Versions of survey wording:

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

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
//require('./jquery-1.8.2.min.js');
77
require('./jquery-3.0.0.min.js');
88
require('./jquery.ba-bbq.js'); // contains slight pgbovine modifications
9-
require('./ace/src-min-noconflict/ace.js');
109

11-
// TODO: can we avoid explicitly including all Ace modes and lazy-load instead?
12-
require('./ace/src-min-noconflict/mode-python.js');
13-
require('./ace/src-min-noconflict/mode-javascript.js');
14-
require('./ace/src-min-noconflict/mode-typescript.js');
15-
require('./ace/src-min-noconflict/mode-c_cpp.js');
16-
require('./ace/src-min-noconflict/mode-java.js');
17-
require('./ace/src-min-noconflict/mode-ruby.js');
10+
// just punt and use global script dependencies
11+
require("script!./ace/src-min-noconflict/ace.js");
12+
require('script!./ace/src-min-noconflict/mode-python.js');
13+
require('script!./ace/src-min-noconflict/mode-javascript.js');
14+
require('script!./ace/src-min-noconflict/mode-typescript.js');
15+
require('script!./ace/src-min-noconflict/mode-c_cpp.js');
16+
require('script!./ace/src-min-noconflict/mode-java.js');
17+
require('script!./ace/src-min-noconflict/mode-ruby.js');
18+
19+
require('script!./socket.io-client/socket.io.js');
20+
1821

1922
var optCommon = require('./opt-frontend-common.js');
2023
var pytutor = require('./pytutor.js');
2124
var assert = pytutor.assert;
2225

23-
// TODO: copy in yellow-happy-face.jpg and red-sad-face.jpg, and test this
24-
require('./opt-testcases.js');
26+
var optTests = require('./opt-testcases.js');
2527

2628
require('../css/opt-frontend.css');
27-
require('../css/opt-testcases.css');
2829

2930
// TODO: add Codeopticon dependencies later
3031

@@ -52,54 +53,17 @@ function TogetherjsCloseHandler() {
5253
}
5354
}
5455

55-
function getBaseBackendOptionsObj() {
56-
var ret = {cumulative_mode: ($('#cumulativeModeSelector').val() == 'true'),
57-
heap_primitives: ($('#heapPrimitivesSelector').val() == 'true'),
58-
show_only_outputs: false,
59-
py_crazy_mode: ($('#pythonVersionSelector').val() == '2crazy'),
60-
origin: originFrontendJsFile};
61-
62-
var surveyObj = optCommon.getSurveyObject();
63-
if (surveyObj) {
64-
ret.survey = surveyObj;
65-
}
66-
67-
return ret;
68-
}
69-
70-
function getBaseFrontendOptionsObj() {
71-
var ret = {// tricky: selector 'true' and 'false' values are strings!
72-
disableHeapNesting: ($('#heapPrimitivesSelector').val() == 'true'),
73-
textualMemoryLabels: ($('#textualMemoryLabelsSelector').val() == 'true'),
74-
executeCodeWithRawInputFunc: optCommon.executeCodeWithRawInput,
75-
76-
// always use the same visualizer ID for all
77-
// instantiated ExecutionVisualizer objects,
78-
// so that they can sync properly across
79-
// multiple clients using TogetherJS. this
80-
// shouldn't lead to problems since only ONE
81-
// ExecutionVisualizer will be shown at a time
82-
visualizerIdOverride: '1',
83-
updateOutputCallback: function() {$('#urlOutput,#embedCodeOutput').val('');},
84-
85-
// undocumented experimental modes:
86-
pyCrazyMode: ($('#pythonVersionSelector').val() == '2crazy'),
87-
holisticMode: ($('#cumulativeModeSelector').val() == 'holistic')
88-
};
89-
return ret;
90-
}
91-
9256
function executeCode(forceStartingInstr, forceRawInputLst) {
9357
if (forceRawInputLst !== undefined) {
9458
rawInputLst = forceRawInputLst; // UGLY global across modules, FIXME
9559
}
9660

9761
var backend_script = optCommon.langToBackendScript($('#pythonVersionSelector').val());
98-
var backendOptionsObj = getBaseBackendOptionsObj();
62+
var backendOptionsObj = optCommon.getBaseBackendOptionsObj();
9963

10064
var startingInstruction = forceStartingInstr ? forceStartingInstr : 0;
10165

102-
var frontendOptionsObj = getBaseFrontendOptionsObj();
66+
var frontendOptionsObj = optCommon.getBaseFrontendOptionsObj();
10367
frontendOptionsObj.startingInstruction = startingInstruction;
10468

10569
optCommon.executeCodeAndCreateViz(optCommon.pyInputGetValue(),
@@ -700,7 +664,7 @@ $(document).ready(function() {
700664
}
701665

702666
$("#createTestsLink").click(function() {
703-
initTestcasesPane('#testCasesPane');
667+
optTests.initTestcasesPane('#testCasesPane');
704668
$(this).hide();
705669
return false;
706670
});

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

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,20 @@
1-
/*
1+
// Python Tutor: https://github.com/pgbovine/OnlinePythonTutor/
2+
// Copyright (C) Philip Guo (philip@pgbovine.net)
3+
// LICENSE: https://github.com/pgbovine/OnlinePythonTutor/blob/master/LICENSE.txt
24

3-
Online Python Tutor
4-
https://github.com/pgbovine/OnlinePythonTutor/
5+
// use Webpack to automatically package up these dependencies
6+
require('../css/opt-testcases.css');
57

6-
Copyright (C) Philip J. Guo (philip@pgbovine.net)
8+
var optCommon = require('./opt-frontend-common.js');
9+
var pytutor = require('./pytutor.js');
710

8-
Permission is hereby granted, free of charge, to any person obtaining a
9-
copy of this software and associated documentation files (the
10-
"Software"), to deal in the Software without restriction, including
11-
without limitation the rights to use, copy, modify, merge, publish,
12-
distribute, sublicense, and/or sell copies of the Software, and to
13-
permit persons to whom the Software is furnished to do so, subject to
14-
the following conditions:
11+
var redSadFace = require('./images/red-sad-face.jpg');
12+
var yellowHappyFace = require('./images/yellow-happy-face.jpg');
1513

16-
The above copyright notice and this permission notice shall be included
17-
in all copies or substantial portions of the Software.
18-
19-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26-
27-
*/
28-
29-
// Pre-reqs:
30-
// - jquery-1.8.2.min.js
31-
// - pytutor.js
32-
// - opt-frontend-common.js
33-
// - ace/src-min-noconflict/ace.js
34-
// should all be imported BEFORE this file
14+
// TODO: abstract this better
15+
module.exports = {
16+
initTestcasesPane: initTestcasesPane,
17+
}
3518

3619

3720
var testcasesPaneHtml = '\
@@ -68,7 +51,7 @@ function initTestcasesPane(parentDivId, onChangeCallback /* optional */) {
6851
}
6952

7053
function getCombinedCode(id) {
71-
var userCod = pyInputGetValue();
54+
var userCod = optCommon.pyInputGetValue();
7255
var testCod = ace.edit('testCaseEditor_' + id).getValue();
7356
// for reporting syntax errors separately for user and test code
7457
var userCodNumLines = userCod.split('\n').length;
@@ -105,7 +88,7 @@ function runTestFinishSuccessfulExecution() {
10588
}
10689

10790
function vizTestFinishSuccessfulExecution() {
108-
optFinishSuccessfulExecution();
91+
optCommon.optFinishSuccessfulExecution();
10992
doneRunningTest();
11093
}
11194

@@ -146,6 +129,7 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
146129
te.setShowPrintMargin(false);
147130
te.setBehavioursEnabled(false);
148131
te.setFontSize(11);
132+
te.$blockScrolling = Infinity; // kludgy to shut up weird warnings
149133
//te.setReadOnly(true);
150134

151135
var s = te.getSession();
@@ -185,6 +169,7 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
185169

186170
te.setValue(initialCod ? initialCod.rtrim() : defaultVal,
187171
-1 /* do NOT select after setting text */);
172+
te.focus();
188173

189174
function runOrVizTestCase(isViz /* true for visualize, false for run */) {
190175
if (isViz) {
@@ -197,9 +182,9 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
197182
var dat = getCombinedCode(id);
198183

199184
// adapted from executeCode in opt-frontend.js
200-
var backend_script = langToBackendScript($('#pythonVersionSelector').val());
201-
var backendOptionsObj = getBaseBackendOptionsObj();
202-
var frontendOptionsObj = getBaseFrontendOptionsObj();
185+
var backend_script = optCommon.langToBackendScript($('#pythonVersionSelector').val());
186+
var backendOptionsObj = optCommon.getBaseBackendOptionsObj();
187+
var frontendOptionsObj = optCommon.getBaseFrontendOptionsObj();
203188
frontendOptionsObj.jumpToEnd = true;
204189

205190
if (isViz) {
@@ -221,9 +206,9 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
221206
});
222207

223208
if (exceptionMsg) {
224-
$('#outputTd_' + id).html('<img src="red-sad-face.jpg"></img>');
209+
$('#outputTd_' + id).html('<img src="' + redSadFace + '"></img>');
225210
} else {
226-
$('#outputTd_' + id).html('<img src="yellow-happy-face.jpg"></img>');
211+
$('#outputTd_' + id).html('<img src="' + yellowHappyFace + '"></img>');
227212
}
228213
};
229214
}
@@ -245,13 +230,13 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
245230

246231
var msg = trace[0].exception_msg;
247232
var trimmedMsg = msg.split(':')[0];
248-
$('#outputTd_' + id).html(htmlspecialchars(trimmedMsg));
233+
$('#outputTd_' + id).html(pytutor.htmlspecialchars(trimmedMsg));
249234

250-
handleUncaughtExceptionFunc(trace);
235+
optCommon.handleUncaughtExceptionFunc(trace);
251236
doneRunningTest();
252237
}
253238

254-
executeCodeAndCreateViz(dat.cod,
239+
optCommon.executeCodeAndCreateViz(dat.cod,
255240
backend_script, backendOptionsObj,
256241
frontendOptionsObj,
257242
'pyOutputPane',

‎v5-unity/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"dependencies" : {
1515
"css-loader" : "",
1616
"style-loader" : "",
17-
"file-loader" : ""
17+
"url-loader" : "",
18+
"script-loader" : ""
1819
}
1920
}

‎v5-unity/visualize.html‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616
https://webpack.github.io/docs/long-term-caching.html -->
1717
<script type="text/javascript" src="bundle.js" charset="utf-8"></script>
1818

19-
<!-- include these AFTER opt-frontend.js so that configuration
19+
<!-- include this AFTER opt-frontend.js so that configuration
2020
global variables are already defined at load time.
21-
22-
Also, it's too hard to figure out how to include these in Webpack,
23-
so just include them externally -->
21+
It's too hard to figure out how to load this within Webpack -->
2422
<script type="text/javascript" src="js/togetherjs/togetherjs-min.js"></script>
25-
<script type="text/javascript" src="js/socket.io-client/socket.io.js"></script>
2623

2724
<!-- insert google-analytics.txt contents here -->
2825

‎v5-unity/webpack.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
module: {
4242
loaders: [
4343
{ test: /\.css$/, loader: "style!css" },
44-
{ test: /\.(png|jpg)$/, loader: 'file-loader' }
44+
{ test: /\.(png|jpg)$/, loader: 'url-loader' }
4545
]
4646
},
4747

0 commit comments

Comments
 (0)