Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuqing888 authored Mar 1, 2018
1 parent 9b20c17 commit bc54656
Show file tree
Hide file tree
Showing 4 changed files with 393 additions and 0 deletions.
97 changes: 97 additions & 0 deletions airlinelist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"Mainline": {
"Table": {
"Header": {
"Data": [
"Airline",
"IATA",
"Hubs",
"Notes",
"HomePage",
"Plane"
]
},
"Row": [
{
"Airline": "Alaska Airlines",
"IATA": "AS",
"Hubs": {
"Hub": [
"Seattle/Tacoma",
"Anchorage",
"Portland (OR)",
"San Diego",
"San Jose"
]
},
"Notes":"Founded as McGee Airways, and commenced operations in 1944 as Alaska Airlines. Plans have been made for Alaska Airlines to acquire Virgin America.",
"HomePage": "https://www.alaskaair.com/",
"Plane": "http://cs-server.usc.edu:45678/hw/hw4/Alaska_Airlines,_Boeing_737.jpg"
},
{
"Airline": "American Airlines",
"IATA": "AA",
"Hubs": {
"Hub": [
"Dallas/Fort Worth",
"Charlotte",
"Chicago-O'Hare",
"Los Angeles",
"Miami",
"New York-JFK",
"New York-LaGuardia",
"Philadelphia",
"Phoenix",
"Washington-National"
]
},
"Notes": "Founded as American Airways; largest airline in the world based on airline company revenue, scheduled passenger miles flown (per year), and fleet size.",
"HomePage": "http://www.aa.com",
"Plane": "http://cs-server.usc.edu:45678/hw/hw4/American_Airlines_Boeing_777.png"
},
{
"Airline": "Delta Air Lines",
"IATA": "DL",
"Hubs": {
"Hub": [
"Atlanta",
"Amsterdam",
"Boston",
"Detroit",
"Minneapolis/St Paul",
"Cincinnati",
"New York-JFK",
"New York-LaGuardia",
"Paris-Charles de Gaulle",
"Salt Lake City",
"Seattle",
"Tokyo-Narita"
]
},
"Notes": "Founded as Huff Daland Dusters; largest airline in the world based on number of passengers served per year.",
"HomePage": "https://www.delta.com",
"Plane": "http://cs-server.usc.edu:45678/hw/hw4/Delta_B747.jpg"
},
{
"Airline": "Frontier Airlines",
"IATA": "F9",
"Hubs": {
"Hub": [
"Denver",
"Atlanta",
"Chicago-O'Hare",
"Cleveland",
"Miami",
"Orlando",
"Trenton",
"Washington-Dulles"
]
},
"Notes": "Frontier Airlines is an American ultra low cost carrier headquartered in Denver, Colorado.",
"HomePage": "http://www.flyfrontier.com/",
"Plane": "http://cs-server.usc.edu:45678/hw/hw4/Airbus_A320-214,_Frontier_Airlines.jpg"
}
]
}
}
}
139 changes: 139 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<html lang="en">

<head>
<meta charset="utf-8" />
<title> Airplane Hub</title>
</head>

<center>
<br><br><br><br>
<h1><strong>Enter URL for Airlines List JSON File</strong> </h1>
<form name="myform" method="POST" id="location">
<input type="text" name="URL" maxlength="100" size="30" />
<br><br>
<input type="button" name="submit" value="Submit Query" onClick="viewJSON(this.form)" />
</form>

</center>

<body>

<script>
function generateHTML(info){

var output='<thead>'+'<tr>';
var HeadLine = info.Mainline.Table.Header.Data;
var ErrorControl = jsonObj.Mainline.Table.Row;
if(ErrorControl==null || ErrorControl == "")
{
alert("No data!");
return;
}

for(var i = 0; i <= info.Mainline.Table.Header.Data.length-1; i++){
//HeadLine[i]=info.Mainline.Table.Header.Data[i];

output +='<th>'+info.Mainline.Table.Header.Data[i]+'</th>'

}
output = output +'</tr>'+'</thead>';

output = output+'<tbody>';//Body starts!

for(var i = 0; i <= info.Mainline.Table.Row.length-1; i++){

var k=0;
//AirLine
output +='<tr>'+'<td>'+info.Mainline.Table.Row[i][HeadLine[k]]+'</td>';

k=k+1;
//IATA
output +='<td>'+info.Mainline.Table.Row[i][HeadLine[k]]+'</td>';
k=k+1;
//Hub
output +='<td><a style="padding-top:10px;padding-bottom:10px;padding-left:15px;padding-right:15px;">'
for(var j = 0; j<=info.Mainline.Table.Row[i][HeadLine[k]].Hub.length-1;j++)
{
if(j===0){
output += '<li><strong>'+info.Mainline.Table.Row[i][HeadLine[k]].Hub[j]+'</strong></li>';
}
else{
output += '<li>'+info.Mainline.Table.Row[i][HeadLine[k]].Hub[j]+'</li>';
}
}
output +='</a></td>';
k=k+1;
//Notes
output +='<td>'+info.Mainline.Table.Row[i][HeadLine[k]]+'</td>';
k=k+1;
//HomePage
output +='<td><a href="'+info.Mainline.Table.Row[i][HeadLine[k]]+'">'+info.Mainline.Table.Row[i][HeadLine[k]]+' </a></td>';
k=k+1;
//Plane
output +='<td> <img src="'+info.Mainline.Table.Row[i][HeadLine[k]]+'"height="100" width="200"/></td>'+'</tr>';

}
output = output +'</tbody>';


var update = document.getElementById('TableData');
var mesg=open();
//mesg.innerHTML = output;
//mesg.document.write(update.innerHTML = output);
mesg.document.write("<table border=1>"+output+"</table>");

}

//end of function generateHTML

function viewJSON(what){
var URL = what.URL.value; //URL=airline.json
if(URL==null || URL == ""){
alert("Empty!Please enter data!");
return;
}

function loadJSON(url) {

if (window.XMLHttpRequest){
request=new XMLHttpRequest();
} else {
request=new ActiveXObject("Microsoft.XMLHTTP");
}

request.open("GET",url,false);
request.send();
if(request.status == 404){
alert("No Files Found! Type again!");
return;
}

jsonObj = JSON.parse(request.responseText);
return jsonObj;
}

jsonObj = loadJSON(URL);


if (window.ActiveXObject){//if IE, simply execute script (due to async prop).
if (jsonObj.parseError.errorCode != 0) {
var myErr = jsonObj.parseError;
generateError(jsonObj);
hWin = window.open("", "Error", "height=300,width=340"); hWin.document.write(html_text);
}
else {
generateHTML(jsonObj);
hWin = window.open("", "Assignment4", "height=800,width=600"); hWin.document.write(html_text);
}
}
else {
generateHTML(jsonObj);

}

}
</script>

</body>

</html>
140 changes: 140 additions & 0 deletions initial.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
h1 {
position: absolute;
left: 28%;
}
#searchText {
position: absolute;
margin-top: 100px;
left: 25%;
}
#submit {
position: absolute;
left: 45%;
margin-top: 140px;
border-radius: 5px;
}
</style>
</head>
<body>
<h1>Enter URL for Airlines List JSON File</h1>
<form name="myForm" method="post" id="location">
<input type="text" name="URL" value="data.json" id="searchText" maxlength="255" size="100">
<br>
<input type="button" name="submit" value="Submit Query" id="submit" onclick="viewJSON(this.form)">
</form>

<script>
//var html_text;
function generateHTML(jsonObj) {

root = jsonObj.DocumentElement;
html_text = "<html><head><title>JSON Parse Result</title></head><body>";
html_text += "<table border='2'>";

var header = jsonObj.Mainline.Table.Header.Data;
var planes = jsonObj.Mainline.Table.Row; // an array of planes
if(!planes) {
alert("No airlines!");
return;
}
html_text += "<tbody>";
html_text += "<tr>";

// output the headers

//var header_keys = Object.keys(header);
for (var i = 0; i < header.length; i++) {
html_text += "<th>" + header[i] + "</th>";
}
html_text += "</tr>";

// output out the values
for (i = 0; i < planes.length; i++) //do for all planes (one per row)
{
var planeNodeList = planes[i]; //get properties of a plane (an object)
html_text += "<tr>"; //start a new row of the output table
//var aircraft_keys = Object.keys(planeNodeList);
for (var k = 0; k < header.length; k++) {
var prop = header[k]; //property
if (k == 5) {//handle images separately
html_text += "<td><img src='" + planeNodeList[prop] + "' width='200 px'; height='150 px'></td>";
}
else if (k == 2) {
html_text += "<td><ul>";
for (var m = 0; m < planeNodeList[prop].Hub.length; m++) {
if(m == 0)
html_text += "<li><b>" + planeNodeList[prop].Hub[m] + "</b></li>";
else html_text += "<li>" + planeNodeList[prop].Hub[m] + "</li>";
}
html_text += "</ul></td>"
}
else if(k == 4) {
html_text += "<td><a href='" + planeNodeList[prop] + "' target='_parent'>" + planeNodeList[prop] + "</a></td>";
}
else {
html_text += "<td>" + planeNodeList[prop] + "</td>";
}

}
html_text += "</tr>";
}
html_text += "</tbody>";
html_text += "</table>";
html_text += "</body></html>";
}


function viewJSON(what) {
var URL = what.URL.value;
if (URL === "") {
alert("filename cannot be empty!");
return;
}

function loadJSON(url) {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", url, false);
xmlhttp.send();
if(xmlhttp.status == 404) {
alert("No such file!");
return;
}
jsonObj = JSON.parse(xmlhttp.responseText);
return jsonObj;
}

jsonObj = loadJSON(URL);
if (window.ActiveXObject) //if IE, simply execute script (due to async prop).
{
if (jsonObj.parseError.errorCode != 0) {
var myErr = jsonObj.parseError;
generateError(jsonObj);
hWin = window.open("", "Error", "height=300,width=340");
hWin.document.write(html_text);
} else {
generateHTML(jsonObj);
hWin = window.open("", "Assignment4", "height=800,width=600");
hWin.document.write(html_text);
}
} else //else if FF, execute script once JSON object has loaded
{
//alert("start");
jsonObj.onload = generateHTML(jsonObj);
hWin = window.open("", "Assignment4", "height=800,width=600");
hWin.document.write(html_text);
}
hWin.document.close();
}
</script>
</body>
</html>
Loading

0 comments on commit bc54656

Please sign in to comment.