@@ -721,6 +721,19 @@ export class ActiveCode extends RunestoneBase {
721721 $ ( this . graphics ) . addClass ( "visible-ac-canvas" ) ;
722722 } . bind ( this )
723723 ) ;
724+
725+ //Anything that wants to add output to coachdiv can do so after the h3
726+ // all those elements will be cleared with each run and coach display will be
727+ // reset to none. Any component that adds content after a run should set display
728+ // to block to ensure visibility
729+ var coachDiv = document . createElement ( "div" ) ;
730+ coachDiv . classList . add ( "alert" , "alert-warning" , "codecoach" ) ;
731+ $ ( coachDiv ) . css ( "display" , "none" ) ;
732+ let coachHead = coachDiv . appendChild ( document . createElement ( "h3" ) ) ;
733+ coachHead . textContent = "Code Coach" ;
734+ this . outerDiv . appendChild ( coachDiv ) ;
735+ this . codecoach = coachDiv ;
736+
724737 outDiv . appendChild ( this . output ) ;
725738 outDiv . appendChild ( this . graphics ) ;
726739 this . outerDiv . appendChild ( outDiv ) ;
@@ -730,11 +743,6 @@ export class ActiveCode extends RunestoneBase {
730743 $ ( lensDiv ) . css ( "display" , "none" ) ;
731744 this . codelens = lensDiv ;
732745 this . outerDiv . appendChild ( lensDiv ) ;
733- var coachDiv = document . createElement ( "div" ) ;
734- coachDiv . classList . add ( "codecoach" ) ;
735- $ ( coachDiv ) . css ( "display" , "none" ) ;
736- this . codecoach = coachDiv ;
737- this . outerDiv . appendChild ( coachDiv ) ;
738746 }
739747
740748 disableSaveLoad ( ) {
@@ -903,38 +911,6 @@ export class ActiveCode extends RunestoneBase {
903911 div_id : this . divid ,
904912 } ) ;
905913 }
906- // <iframe id="%(divid)s_codelens" width="800" height="500" style="display:block"src="#">
907- // </iframe>
908- showCodeCoach ( ) {
909- var myIframe ;
910- var srcURL ;
911- var cl ;
912- var div_id = this . divid ;
913- if ( this . codecoach === null ) {
914- this . codecoach = document . createElement ( "div" ) ;
915- this . codecoach . style . display = "block" ;
916- }
917- cl = this . codecoach . firstChild ;
918- if ( cl ) {
919- this . codecoach . removeChild ( cl ) ;
920- }
921- srcURL = eBookConfig . app + "/admin/diffviewer?divid=" + div_id ;
922- myIframe = document . createElement ( "iframe" ) ;
923- myIframe . setAttribute ( "id" , div_id + "_coach" ) ;
924- myIframe . setAttribute ( "width" , "100%" ) ;
925- myIframe . setAttribute ( "height" , "500px" ) ;
926- myIframe . setAttribute ( "style" , "display:block" ) ;
927- myIframe . style . background = "#fff" ;
928- myIframe . style . width = "100%" ;
929- myIframe . src = srcURL ;
930- this . codecoach . appendChild ( myIframe ) ;
931- $ ( this . codecoach ) . show ( ) ;
932- this . logBookEvent ( {
933- event : "coach" ,
934- act : "view" ,
935- div_id : this . divid ,
936- } ) ;
937- }
938914
939915 toggleEditorVisibility ( ) { }
940916
@@ -1296,13 +1272,8 @@ Yet another is that there is an internal error. The internal error message is:
12961272 }
12971273
12981274 async checkPythonSyntax ( ) {
1299- let checkDiv = this . outerDiv . querySelector ( "div.python_check_results" ) ;
1300- if ( checkDiv != null )
1301- checkDiv . remove ( ) ;
1302-
13031275 let code = this . editor . getValue ( ) ;
1304-
1305- fetch ( '/ns/books/python_check' , {
1276+ fetch ( '/ns/coach/python_check' , {
13061277 method : 'POST' ,
13071278 body : code
13081279 } )
@@ -1332,17 +1303,12 @@ Yet another is that there is an internal error. The internal error message is:
13321303 message = message . slice ( 0 , - 1 ) ; //remove trailing newline
13331304
13341305 //Render
1335- checkDiv = document . createElement ( "div" ) ;
1336- checkDiv . classList . add ( "python_check_results" , "alert" , "alert-warning" ) ;
1337- let checkHead = checkDiv . appendChild ( document . createElement ( "h3" ) ) ;
1338- checkHead . textContent = "Syntax Tips" ;
1306+ let checkDiv = document . createElement ( "div" ) ;
1307+ checkDiv . classList . add ( "python_check_results" ) ;
13391308 let checkPre = checkDiv . appendChild ( document . createElement ( "pre" ) ) ;
1340- //checkPre.classList.add("alert-warning");
13411309 checkPre . textContent = message ;
1342-
1343- //Squeeze check_results right before output pane
1344- const outDiv = this . outDiv ;
1345- outDiv . parentNode . insertBefore ( checkDiv , outDiv ) ;
1310+ this . codecoach . append ( checkDiv ) ;
1311+ $ ( this . codecoach ) . css ( "display" , "block" ) ;
13461312 }
13471313 } )
13481314 . catch ( err => {
@@ -1375,6 +1341,10 @@ Yet another is that there is an internal error. The internal error message is:
13751341 var prog = await this . buildProg ( true ) ;
13761342 this . saveCode = "True" ;
13771343 $ ( this . output ) . text ( "" ) ;
1344+
1345+ //clear anything after header in codecoach
1346+ $ ( this . codecoach ) . children ( ) . slice ( 1 ) . remove ( ) ;
1347+
13781348 while ( $ ( `#${ this . divid } _errinfo` ) . length > 0 ) {
13791349 $ ( `#${ this . divid } _errinfo` ) . remove ( ) ;
13801350 }
0 commit comments