Skip to content

Commit c15cfc4

Browse files
committed
first prototype version of post-syntax error survey
1 parent 93b40c1 commit c15cfc4

5 files changed

Lines changed: 225 additions & 4 deletions

File tree

‎v3/css/pytutor.css‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,11 @@ textarea.bubbleInputText {
692692
*/
693693
}
694694

695+
.ui-tooltip-pgbootstrap-RED {
696+
border: 1px solid #e93f34; /* should match brightRed JavaScript variable */
697+
698+
}
699+
695700
.ui-tooltip-pgbootstrap-stub .ui-tooltip-content{
696701
padding: 6px 9px;
697702
}
@@ -788,6 +793,39 @@ div.ExecutionVisualizer .pycrazy-highlight-prev-and-cur {
788793
}
789794

790795

796+
#syntaxErrBubbleContents {
797+
font-size: 9pt;
798+
cursor: default;
799+
}
800+
801+
#syntaxErrHeader {
802+
margin-bottom: 4pt;
803+
}
804+
805+
#syntaxErrCodeDisplay {
806+
border: 1px solid #ddd;
807+
}
808+
809+
#syntaxErrMsg {
810+
color: #e93f34; /* should match brightRed JavaScript variable */
811+
font-size: 10pt;
812+
margin-bottom: 4pt;
813+
}
814+
815+
#syntaxErrQuestion {
816+
margin-top: 10px;
817+
}
818+
819+
#syntaxErrTxtInput {
820+
margin-top: 3px;
821+
margin-bottom: 6px;
822+
}
823+
824+
#syntaxErrSubmitBtn, #syntaxErrCloseBtn {
825+
margin-right: 5px;
826+
}
827+
828+
791829
/* BEGIN Java frontend by David Pritchard and Will Gwozdz */
792830

793831
/* stack and queue css by Will Gwozdz */

‎v3/js/opt-frontend-common.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ var pyInputAceEditor; // Ace editor object that contains the input code
7777

7878
var useCodeMirror = false; // true -> use CodeMirror, false -> use Ace
7979

80+
var prevExecutionExceptionObj = null; // did the PREVIOUS execution have an exception? if so, what was its context?
81+
8082

8183
var loggingSocketIO = undefined; // socket.io instance -- OPTIONAL: not all frontends use it
8284

@@ -1237,6 +1239,10 @@ function optFinishSuccessfulExecution() {
12371239
// For version 3+, dynamically generate a survey whenever the user
12381240
// successfully executes a piece of code
12391241
initializeDisplayModeSurvey();
1242+
1243+
if (activateSyntaxErrorSurvey && experimentalPopUpSyntaxErrorSurvey) {
1244+
experimentalPopUpSyntaxErrorSurvey();
1245+
}
12401246
}
12411247

12421248

@@ -1362,6 +1368,13 @@ function executePythonCode(pythonSourceCode,
13621368
});
13631369
}
13641370

1371+
if (killerException) {
1372+
var excObj = {killerException: killerException, myAppState: getAppState()};
1373+
prevExecutionExceptionObj = excObj;
1374+
} else {
1375+
prevExecutionExceptionObj = null; // reset!!!
1376+
}
1377+
13651378
// tricky hacky reset
13661379
num414Tries = 0;
13671380
}

‎v3/js/opt-frontend.js‎

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ var helpQueueSize = 0;
5454
var tutorAvailable = false;
5555
var tutorWaitText = 'Please wait for the next available tutor.';
5656

57+
var activateSyntaxErrorSurvey = false; // true;
58+
5759
function setHelpQueueSizeLabel() {
5860
if (helpQueueSize == 1) {
5961
$("#helpQueueText").html('There is 1 person in line.');
@@ -175,6 +177,174 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
175177
}
176178

177179

180+
181+
// domID is the ID of the element to attach to (without the leading '#' sign)
182+
function SyntaxErrorSurveyBubble(parentViz, domID) {
183+
this.parentViz = parentViz;
184+
185+
this.domID = domID;
186+
this.hashID = '#' + domID;
187+
188+
this.my = 'left center';
189+
this.at = 'right center';
190+
191+
this.qtipHidden = false; // is there a qtip object present but hidden? (TODO: kinda confusing)
192+
}
193+
194+
SyntaxErrorSurveyBubble.prototype.destroyQTip = function() {
195+
$(this.hashID).qtip('destroy');
196+
}
197+
198+
SyntaxErrorSurveyBubble.prototype.redrawCodelineBubble = function() {
199+
if (isOutputLineVisibleForBubbles(this.domID)) {
200+
if (this.qtipHidden) {
201+
$(this.hashID).qtip('show');
202+
}
203+
else {
204+
$(this.hashID).qtip('reposition');
205+
}
206+
207+
this.qtipHidden = false;
208+
}
209+
else {
210+
$(this.hashID).qtip('hide');
211+
this.qtipHidden = true;
212+
}
213+
}
214+
215+
SyntaxErrorSurveyBubble.prototype.qTipContentID = function() {
216+
return '#ui-tooltip-' + this.domID + '-content';
217+
}
218+
219+
SyntaxErrorSurveyBubble.prototype.qTipID = function() {
220+
return '#ui-tooltip-' + this.domID;
221+
}
222+
223+
224+
// created on 2015-04-18
225+
function experimentalPopUpSyntaxErrorSurvey() {
226+
if (prevExecutionExceptionObj &&
227+
prevExecutionExceptionObj.killerException.line !== undefined) {
228+
var offendingLine = prevExecutionExceptionObj.killerException.line;
229+
// make sure jquery.qtip has been imported
230+
231+
var codelineIDs = [];
232+
$.each(myVisualizer.domRoot.find('#pyCodeOutput .cod'), function(i, e) {
233+
// hacky!
234+
var domID = $(e).attr('id');
235+
var lineRE = new RegExp('cod' + String(offendingLine) + '$'); // $ for end-of-line match
236+
if (lineRE.test(domID)) {
237+
codelineIDs.push($(e).attr('id'));
238+
}
239+
});
240+
241+
// should find only 1 match, or else something is wonky, maybe
242+
// because the code changed so much that the line number in question
243+
// is no longer available
244+
if (codelineIDs.length === 1) {
245+
console.log('PREV', prevExecutionExceptionObj);
246+
var codLineId = codelineIDs[0];
247+
248+
var bub = new SyntaxErrorSurveyBubble(myVisualizer, codLineId);
249+
250+
// destroy then create a new tip:
251+
bub.destroyQTip();
252+
$(bub.hashID).qtip($.extend({}, qtipShared, {
253+
content: ' ', // can't be empty!
254+
id: bub.domID,
255+
position: {
256+
my: bub.my,
257+
at: bub.at,
258+
adjust: {
259+
x: -10,
260+
},
261+
effect: null, // disable all cutesy animations
262+
},
263+
style: {
264+
classes: 'ui-tooltip-pgbootstrap ui-tooltip-pgbootstrap-RED'
265+
}
266+
}));
267+
268+
// need to set both max-width and width() ...
269+
$(bub.qTipID()).css('max-width', '350px').width('350px');
270+
271+
$(bub.qTipContentID()).html('<div id="syntaxErrBubbleContents"><div id="syntaxErrHeader">You just fixed the following error:</div>\
272+
<div id="syntaxErrMsg">[ERROR MSG]</div>\
273+
<div id="syntaxErrCodeDisplay"></div>\
274+
<div id="syntaxErrQuestion">\
275+
What would have been a better error message here?<br/>\
276+
<input type="text" id="syntaxErrTxtInput" size=60 maxlength=150/><br/>\
277+
<button class="syntaxErrSubmitBtn" type="button">Submit</button>\
278+
<button class="syntaxErrCloseBtn" type="button">Cancel</button>\
279+
</div></div>\
280+
');
281+
// unbind first, then bind a new one
282+
myVisualizer.domRoot.find('#pyCodeOutputDiv')
283+
.unbind('scroll')
284+
.scroll(function() {
285+
bub.redrawCodelineBubble();
286+
});
287+
288+
289+
var bubbleAceEditor = ace.edit('syntaxErrCodeDisplay');
290+
291+
var s = bubbleAceEditor.getSession();
292+
// tab -> 4 spaces
293+
s.setTabSize(4);
294+
s.setUseSoftTabs(true);
295+
// disable extraneous indicators:
296+
s.setFoldStyle('manual'); // no code folding indicators
297+
bubbleAceEditor.setHighlightActiveLine(false);
298+
bubbleAceEditor.setShowPrintMargin(false);
299+
bubbleAceEditor.setBehavioursEnabled(false);
300+
301+
bubbleAceEditor.setFontSize(10);
302+
303+
bubbleAceEditor.setOptions({minLines: 5, maxLines: 5}); // keep this SMALL
304+
305+
$('#syntaxErrCodeDisplay').css('width', '320px');
306+
$('#syntaxErrCodeDisplay').css('height', '200px'); // VERY IMPORTANT so that it works on I.E., ugh!
307+
308+
// don't do real-time syntax checks:
309+
// https://github.com/ajaxorg/ace/wiki/Syntax-validation
310+
s.setOption("useWorker", false);
311+
312+
var lang = prevExecutionExceptionObj.myAppState.py;
313+
var mod = 'python';
314+
if (lang === 'java') {
315+
mod = 'java';
316+
} else if (lang === 'js') {
317+
mod = 'javascript';
318+
} else if (lang === 'ts') {
319+
mod = 'typescript';
320+
}
321+
s.setMode("ace/mode/" + mod);
322+
323+
bubbleAceEditor.setValue(prevExecutionExceptionObj.myAppState.code.rtrim() /* kill trailing spaces */,
324+
-1 /* do NOT select after setting text */);
325+
bubbleAceEditor.setReadOnly(true);
326+
327+
s.setAnnotations([{row: offendingLine - 1 /* zero-indexed */,
328+
type: 'error',
329+
text: prevExecutionExceptionObj.killerException.exception_msg}]);
330+
331+
// scroll down to the line where the error occurred, trying to center it
332+
// by subtracing 3 from it (which should center it, assuming we're
333+
// displaying 5 lines of context)
334+
if ((offendingLine - 3) > 0) {
335+
bubbleAceEditor.scrollToLine(offendingLine - 3);
336+
}
337+
338+
// don't forget htmlspecialchars
339+
$("#syntaxErrMsg").html(htmlspecialchars(prevExecutionExceptionObj.killerException.exception_msg));
340+
341+
// TODO: why is this positioning so wonky in the beginning?!?
342+
bub.redrawCodelineBubble(); // do an initial redraw to align everything
343+
}
344+
}
345+
}
346+
347+
178348
function initAceAndOptions() {
179349
if ($('#pythonVersionSelector').val() === 'java') {
180350
$("#javaOptionsPane").show();

‎v3/js/pytutor.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,9 +1443,11 @@ ExecutionVisualizer.prototype.updateOutputFull = function(smoothTransition) {
14431443
}
14441444

14451445

1446+
// TODO: don't do this since it screws with other stuff, and we're not
1447+
// activating annotation bubbles right now ...
14461448
// crucial resets for annotations (TODO: kludgy)
1447-
myViz.destroyAllAnnotationBubbles();
1448-
myViz.initStepAnnotation();
1449+
//myViz.destroyAllAnnotationBubbles();
1450+
//myViz.initStepAnnotation();
14491451

14501452

14511453
var prevDataVizHeight = myViz.domRoot.find('#dataViz').height();

‎v3/visualize.html‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@
5252

5353

5454
<!-- for annotation bubbles -->
55-
<!--
5655
<script type="text/javascript" src="js/jquery.qtip.min.js"></script>
5756
<link type="text/css" href="css/jquery.qtip.css" rel="stylesheet" />
58-
-->
5957

6058
<script type="text/javascript" src="js/pytutor.js"></script>
6159
<link rel="stylesheet" href="css/pytutor.css"/>

0 commit comments

Comments
 (0)