Last active
September 28, 2017 23:13
-
-
Save vtambourine/014778156e48acd6be2c0ef400f5ddb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FlightTable { | |
constructor(domNode, options) { | |
this.tableNode = $(domNode); | |
this.tableBody = this.tableNode.find('tbody'); | |
this.direction = options.direction; | |
} | |
updateFlight(flightDetails) { | |
var rowElement = $(` | |
<tr> | |
<td>${flightDetails.flightName}</td> | |
<td>${flightDetails.route ? flightDetails.route.destinations[0] : ''}</td> | |
<td>${flightDetails.scheduleTime}</td> | |
<td>${flightDetails.gate}</td> | |
<td>${flightDetails.publicFlightState.flightStates[0]}</td> | |
</tr> | |
`); | |
this.tableBody.append(rowElement); | |
} | |
fetchFlights() { | |
$.ajax({ | |
url: 'https://api.schiphol.nl/public-flights/flights', | |
headers: { | |
'ResourceVersion': 'v3', | |
}, | |
dataType: 'json', | |
data: { | |
app_id: window.B.appId, | |
app_key: window.B.appKey, | |
flightdirection: this.direction, | |
includedelays: true, | |
sort: '+scheduletime' | |
}, | |
context: this, | |
success: function (data, status, xhr) { | |
data.flights.forEach((flights) => { | |
this.updateFlight(flights); | |
}) | |
} | |
}); | |
} | |
} | |
const departuresFlightTable = new FlightTable( | |
document.getElementById('flight-departures-table'), | |
{ direction: 'D' } | |
); | |
departuresFlightTable.fetchFlights(); | |
const arrivalsFlightTable = new FlightTable( | |
document.getElementById('flight-arrivals-table'), | |
{ direction: 'A' } | |
); | |
arrivalsFlightTable.fetchFlights(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment