2023-06-16 22:55:18 +01:00
|
|
|
<script>
|
|
|
|
export let station = "";
|
2023-06-17 01:53:08 +01:00
|
|
|
import { onMount } from 'svelte'
|
|
|
|
|
|
|
|
let requestedStation;
|
2023-06-16 22:55:18 +01:00
|
|
|
$: requestedStation = station;
|
2023-06-17 01:53:08 +01:00
|
|
|
|
|
|
|
let jsonData = null;
|
2023-06-16 22:55:18 +01:00
|
|
|
let services = [];
|
2023-06-17 01:53:08 +01:00
|
|
|
|
2023-06-16 22:55:18 +01:00
|
|
|
$: {
|
2023-06-17 01:53:08 +01:00
|
|
|
if (jsonData === null && requestedStation) {
|
|
|
|
fetchData();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jsonData && jsonData.GetStationBoardResult && jsonData.GetStationBoardResult.trainServices && jsonData.GetStationBoardResult.trainServices.service) {
|
|
|
|
services = [...jsonData.GetStationBoardResult.trainServices.service];
|
|
|
|
} else {
|
|
|
|
services = ["No train services available"];
|
|
|
|
}
|
2023-06-16 22:55:18 +01:00
|
|
|
}
|
2023-06-17 01:53:08 +01:00
|
|
|
|
|
|
|
async function fetchData() {
|
|
|
|
console.log(`Requested Station: ${requestedStation}`);
|
|
|
|
const data = await fetch(`https://owlboard.info/api/v1/ldb/${requestedStation}`);
|
|
|
|
jsonData = await data.json();
|
|
|
|
}
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
if (requestedStation && jsonData === null) {
|
|
|
|
fetchData();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
2023-06-16 22:55:18 +01:00
|
|
|
|
|
|
|
<p>{requestedStation.toUpperCase()}</p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
{#each services as service}
|
|
|
|
<span>{service.origin?.location?.locationName || 'Unknown'}</span>
|
|
|
|
{/each}
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>From</th>
|
|
|
|
<th>To</th>
|
|
|
|
<th>Plat.</th>
|
|
|
|
<th>Sch Arr.</th>
|
|
|
|
<th>Exp Arr.</th>
|
|
|
|
<th>Sch Dep.</th>
|
|
|
|
<th>Exp Dep.</th>
|
|
|
|
</tr>
|
|
|
|
{#each services as service}
|
|
|
|
<tr>
|
|
|
|
<td>{service.origin?.location?.locationName || ''}</td>
|
|
|
|
<td>{service.destination?.location?.locationName || ''}</td>
|
2023-06-17 01:53:08 +01:00
|
|
|
<td>{service.platform || '-'}</td>
|
2023-06-16 22:55:18 +01:00
|
|
|
</tr>
|
|
|
|
{/each}
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
table {
|
|
|
|
width: 100%;
|
|
|
|
margin: auto;
|
2023-06-17 01:53:08 +01:00
|
|
|
color: white;
|
2023-06-16 22:55:18 +01:00
|
|
|
}
|
|
|
|
</style>
|