Created
September 28, 2017 15:04
-
-
Save vtambourine/9aea96144e9ab6b5a1dff6c42f38984b 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) { | |
this.tableNode = $(domNode); | |
this.tableBody = this.tableNode.find('tbody'); | |
} | |
updateFlight(flightDetails) { | |
var rowElement = $(` | |
<tr> | |
<td>${flightDetails.flightName}</td> | |
<td>${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: 'D', | |
includedelays: true, | |
sort: '+scheduletime' | |
}, | |
context: this, | |
success: function (data, status, xhr) { | |
data.flights.forEach((flights) => { | |
this.updateFlight(flights); | |
}) | |
} | |
}); | |
} | |
} | |
const flightTable = new FlightTable( | |
document.getElementById('flight-departures-table') | |
); | |
flightTable.fetchFlights(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment