Changeset 363 in tmcsimulator for trunk


Ignore:
Timestamp:
04/11/2019 10:35:31 AM (7 years ago)
Author:
jdalbey
Message:

Implement #136 to read script file name from a config file. EInotebook v0.2

Location:
trunk/webapps/EInotebook
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/webapps/EInotebook/index.html

    r359 r363  
    11<html> 
    22  <head> 
    3     <title>Electronic Instructor Notebook v0.1</title> 
     3    <title>Electronic Instructor Notebook v0.2</title> 
    44    <meta name="apple-mobile-web-app-capable" content="yes"> 
    55    <meta name="viewport" content="width=device-width; initial-scale=1.0; user-scalable=0;"> 
     
    88    <link rel="stylesheet" type="text/css" href="notebook.css">  
    99    <link rel="stylesheet" type="text/css" href="ipadapp.css"> 
     10    <script type="text/javascript" src="../js/common.js"></script>  
    1011    <script type="text/javascript" src="scripts/cookies.js"></script> 
    1112    <script type="text/javascript" src="scripts/Events.js"></script> 
     
    1819    <script type="text/javascript" src="scripts/Incident.js"></script> 
    1920    <script type="text/javascript" src="scripts/Incidents.js"></script> 
     21    <script type="text/javascript" src="scripts/LoadEvents.js"></script>  
    2022    <script type="text/javascript" src="scripts/PopulateIncidents.js"></script> 
    2123    <!--script type="text/javascript" src="scripts/PopulateEvents.js"></script--> 
    2224    <script type="text/javascript" src="summary/summary.js"></script>  
    2325    <script type="text/javascript" src="notebook.js"></script>  
    24     <script type="text/javascript" src="scripts/LoadEvents.js"></script>  
    2526  </head> 
    2627  <body onLoad="setupNotebook(); run();"> 
  • trunk/webapps/EInotebook/notebook.js

    r359 r363  
    3030function setupNotebook() 
    3131{ 
     32   console.log("setupNotebook() starting"); 
    3233   changeTab('summaryTab'); 
    3334   showContent('summaryPageContent') 
     
    138139    }); 
    139140} 
    140 // Load the dynamic json file for highways, etc. 
    141 function loadJSON(inFile, callback) 
    142 { 
    143     var xobj = new XMLHttpRequest(); 
    144     // Assume XML unless filename ends with .json 
    145     if (inFile.endsWith(".json")) 
    146     { 
    147         xobj.overrideMimeType("application/json"); 
    148     } 
    149     xobj.open('GET', inFile, true); 
    150     xobj.onreadystatechange = function() 
    151     { 
    152         if (xobj.readyState == 4 && xobj.status == "200") 
    153         { 
    154             callback(xobj.responseText); 
    155         } 
    156     }; 
    157     // We want ajax to ignore any cached responses 
    158     xobj.setRequestHeader('If-Modified-Since', 'Sat, 01 Jan 2000 01:01:01 GMT') 
    159     xobj.send(null); 
    160 } 
    161141/** 
    162142 * Selects a new tab to be viewed.  
  • trunk/webapps/EInotebook/scripts/Event.js

    r359 r363  
    5050189: "#ffe680",        // CornSilk 
    5151190: "MistyRose",  
    52 191: "Moccasin" } 
     52191: "Moccasin", 
     53181: "PowderBlue" } 
    5354 
    5455         
  • trunk/webapps/EInotebook/scripts/Events.js

    r359 r363  
    309309{ 
    310310        var event = null; 
    311          
     311        if (this.length == 0) 
     312    { 
     313        console.log("Error: event list is empty in getLastExecutedEvent"); 
     314        return; 
     315    } 
    312316        // IF there is only one event and it has been executed THEN 
    313317        if (this.length == 1 && this[0].time.getSeconds() <= time) 
  • trunk/webapps/EInotebook/scripts/LoadEvents.js

    r361 r363  
    1 var xmlDoc; 
    2 function loadJSON(inFile, callback) 
    3 { 
    4     var xobj = new XMLHttpRequest(); 
    5     // Assume XML unless filename ends with .json 
    6     if (inFile.endsWith(".json")) 
    7     { 
    8         xobj.overrideMimeType("application/json"); 
    9     } 
    10     xobj.open('GET', inFile, true); 
    11     xobj.onreadystatechange = function() 
    12     { 
    13         if (xobj.readyState == 4 && xobj.status == "200") 
    14         { 
    15             callback(xobj.responseText); 
    16         } 
    17     }; 
    18     // We want ajax to ignore any cached responses 
    19     xobj.setRequestHeader('If-Modified-Since', 'Sat, 01 Jan 2000 01:01:01 GMT') 
    20     xobj.send(null); 
    21 } 
     1 
    222 
    233// Parse the entire Incident XML Script file  
     
    277    // Create a parser and grab the high level tag we're interested in 
    288    var parser = new DOMParser(); 
    29     xmlDoc = parser.parseFromString(response,"text/xml"); 
     9    var xmlDoc = parser.parseFromString(response,"text/xml"); 
    3010    var eventTags = xmlDoc.getElementsByTagName("SCRIPT_EVENT"); 
    31  
     11    console.log("parsing incident xml file"); 
    3212    // Process each SCRIPT_EVENT tag 
    3313    for (var i = 0; i < eventTags.length; i++) 
     
    5434                        incidentNum = Number(currEvt.childNodes[child].attributes["LogNum"].value);  
    5535                        break; 
    56                     case "GENERAL_INFO":  break; 
     36                    case "GENERAL_INFO":   
     37                        /* This tag identifies a new incident.  As long as it appears before any 
     38                        other tags, we can use it to create a new incident. (The alternative is to 
     39                        have a separate function that parses xml to extract incidents before 
     40                        we load events.)  Creating an event (below) requires that the incident has already 
     41                        been created. */ 
     42                        break; 
    5743                    case "CAD_DATA":  
    5844                        var caddata = parseCAD(currEvt.childNodes[child]);  
     
    8470        } 
    8571        //console.log(evtTime.format(), incidentNum, proparray.length, evalarray.length); 
    86         if (incidentNum != undefined) 
     72        // Ignore Media Log incident and empty nodes 
     73        if (incidentNum != undefined && incidentNum != 100) 
    8774        { 
    88           events.add(new Event(evtTime, incidents.get(incidentNum), new Properties(proparray),  
     75          // Create new event with fields obtained from xml file 
     76          events.add(new Event(evtTime, incidents.get(incidentNum),  
     77                new Properties(proparray),  
    8978                new Evaluations(evalarray)) ); 
    9079        } 
    9180    } 
     81} 
    9282 
    93 } 
    9483function parseCAD(element) 
    9584{ 
     
    148137 
    149138// MAIN 
    150 loadJSON("full_script.xml", parseXml) 
    151 // Note: the script has the Media Log event removed 
     139console.log("starting LoadEvents"); 
     140/** Load the sim script name file and extract the filename of the Incident Script */ 
     141loadJSON("../sim_scriptname.json", function(response) 
     142{ 
     143    console.log("scriptname file loaded"); 
     144    try { 
     145        var scriptnamejson = JSON.parse(response); 
     146        // For now the script must be located in the EInotebook folder. 
     147        // It would be better to use the file located in trunk/scripts folder.  
     148        var scriptFilename = scriptnamejson.filename; 
     149        console.log("Attempting to load", scriptFilename); 
     150        // Now load the Incident Script and go parse it 
     151        loadJSON(scriptFilename, parseXml) 
    152152 
     153        } catch(e) { 
     154            console.log("Error attempt to parse sim_scriptname.json: "+response) 
     155        } 
     156}); 
     157 
  • trunk/webapps/EInotebook/scripts/PopulateIncidents.js

    r359 r363  
    55incidents.add(new Incident(new Time(1, 51, 0), 190, "Tanker Truck vs. Car/Spill", "Incident Description - This is a collision involving a tanker truck and a car that block the #3 and 4 lanes on NB I-5 just north of Main Street. There are 2 minor injured and 1 major injured. Liquid is leaking out of the tanker truck which is identified as milk. The leak is plugged and the fire department sprays the milk down the drain. The fire department, ambulance, additional units, TMT, a big rig tow, and a rotational tow are sent to the scene.")); 
    66incidents.add(new Incident(new Time(2, 17, 0), 191, "RV Fire", "This is an RV fire on the shoulder southbound 73 just north of Bear/Baker Street. There are two injured victims who were pulled from the RV by passers-by. The #3 is closed to fight the fire. The fire department, paramedics, an extra unit, sign truck/s, and ambulance are sent to the scene.")); 
     7// Practice Incident 
     8incidents.add(new Incident(new Time(0,0,0), 181, "Overturned Hay Truck", "This is a three-vehicle collision involving a hay truck and two cars blocking the #1, 2, and 3 lanes on NB 405 just south of MacArthur Boulevard. The truck spills hay over the #2 and 3 lanes. There is one 11-44 and two minor injured. Ambulance, fire, paramedics, additional units, Maintenance, and coroner are requested on this incident.")); 
Note: See TracChangeset for help on using the changeset viewer.