Skip to content

Instantly share code, notes, and snippets.

@vtambourine
Created September 28, 2017 15:04
Show Gist options
  • Save vtambourine/9aea96144e9ab6b5a1dff6c42f38984b to your computer and use it in GitHub Desktop.
Save vtambourine/9aea96144e9ab6b5a1dff6c42f38984b to your computer and use it in GitHub Desktop.
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