Changeset 363 in tmcsimulator for trunk/webapps/EInotebook/scripts/LoadEvents.js
- Timestamp:
- 04/11/2019 10:35:31 AM (7 years ago)
- File:
-
- 1 edited
-
trunk/webapps/EInotebook/scripts/LoadEvents.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 22 2 23 3 // Parse the entire Incident XML Script file … … 27 7 // Create a parser and grab the high level tag we're interested in 28 8 var parser = new DOMParser(); 29 xmlDoc = parser.parseFromString(response,"text/xml");9 var xmlDoc = parser.parseFromString(response,"text/xml"); 30 10 var eventTags = xmlDoc.getElementsByTagName("SCRIPT_EVENT"); 31 11 console.log("parsing incident xml file"); 32 12 // Process each SCRIPT_EVENT tag 33 13 for (var i = 0; i < eventTags.length; i++) … … 54 34 incidentNum = Number(currEvt.childNodes[child].attributes["LogNum"].value); 55 35 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; 57 43 case "CAD_DATA": 58 44 var caddata = parseCAD(currEvt.childNodes[child]); … … 84 70 } 85 71 //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) 87 74 { 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), 89 78 new Evaluations(evalarray)) ); 90 79 } 91 80 } 81 } 92 82 93 }94 83 function parseCAD(element) 95 84 { … … 148 137 149 138 // MAIN 150 loadJSON("full_script.xml", parseXml) 151 // Note: the script has the Media Log event removed 139 console.log("starting LoadEvents"); 140 /** Load the sim script name file and extract the filename of the Incident Script */ 141 loadJSON("../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) 152 152 153 } catch(e) { 154 console.log("Error attempt to parse sim_scriptname.json: "+response) 155 } 156 }); 157
Note: See TracChangeset
for help on using the changeset viewer.
