2023-06-13 13:38:59 +01:00
|
|
|
<script>
|
2023-06-15 21:32:14 +01:00
|
|
|
import Header from '$lib/navigation/header.svelte'
|
2023-06-26 15:34:01 +01:00
|
|
|
import Loading from '$lib/navigation/loading.svelte';
|
2023-06-27 12:38:41 +01:00
|
|
|
import Island from '$lib/islands/island.svelte';
|
2023-06-26 15:34:01 +01:00
|
|
|
import Nav from '$lib/navigation/nav.svelte';
|
|
|
|
import { uuid } from '$lib/stores/uuid';
|
2023-06-13 13:38:59 +01:00
|
|
|
|
|
|
|
import { onMount } from 'svelte'
|
|
|
|
|
2023-06-19 21:55:23 +01:00
|
|
|
let title = "Timetable Results"
|
|
|
|
let id = ""
|
|
|
|
let data = [];
|
2023-06-26 15:34:01 +01:00
|
|
|
let isLoading = true;
|
2023-06-27 12:38:41 +01:00
|
|
|
let error = false;
|
|
|
|
let errMsg = "";
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-06-20 19:22:59 +01:00
|
|
|
$: {
|
|
|
|
if (id) {
|
|
|
|
title = id.toUpperCase();
|
|
|
|
} else {
|
|
|
|
title = "Querying Timetable"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-13 13:38:59 +01:00
|
|
|
async function getHeadcode() {
|
|
|
|
return new URLSearchParams(window.location.search).get('headcode');
|
|
|
|
}
|
|
|
|
|
|
|
|
onMount(async () => {
|
2023-06-26 15:34:01 +01:00
|
|
|
isLoading = true;
|
2023-06-19 21:55:23 +01:00
|
|
|
id = await getHeadcode() || "";
|
2023-06-27 12:38:41 +01:00
|
|
|
const res = await fetchData(id);
|
|
|
|
if (res) {
|
|
|
|
data = res;
|
|
|
|
}
|
|
|
|
isLoading = false;
|
2023-06-13 13:38:59 +01:00
|
|
|
})
|
|
|
|
|
2023-06-19 21:55:23 +01:00
|
|
|
async function fetchData(id = "") {
|
|
|
|
const date = 'now';
|
|
|
|
const searchType = 'headcode'
|
2023-06-26 15:34:01 +01:00
|
|
|
const options = {
|
|
|
|
method: "GET",
|
|
|
|
headers: {
|
|
|
|
"uuid": $uuid
|
|
|
|
}
|
|
|
|
}
|
2023-06-19 21:55:23 +01:00
|
|
|
const url = `https://owlboard.info/api/v2/timetable/train/${date}/${searchType}/${id}`
|
2023-06-26 15:34:01 +01:00
|
|
|
const res = await fetch(url, options);
|
2023-06-27 12:38:41 +01:00
|
|
|
isLoading = false;
|
|
|
|
if (res.status == 200) {
|
|
|
|
return await res.json();
|
|
|
|
} else if (res.status === 401) {
|
|
|
|
error = true;
|
|
|
|
errMsg = "You must be logged into the staff version for this feature"
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
errMsg = "Unable to connect, check your connection and try again"
|
|
|
|
return false;
|
|
|
|
}
|
2023-06-19 21:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-06-19 21:55:23 +01:00
|
|
|
<Header {title} />
|
2023-06-26 15:34:01 +01:00
|
|
|
|
2023-06-27 12:38:41 +01:00
|
|
|
{#if error}
|
|
|
|
<Island>
|
|
|
|
<p class="error">{errMsg}</p>
|
|
|
|
</Island>
|
|
|
|
{/if}
|
|
|
|
|
2023-06-26 15:34:01 +01:00
|
|
|
{#if isLoading}
|
|
|
|
<Loading />
|
|
|
|
{/if}
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-06-19 21:55:23 +01:00
|
|
|
{#each data as service}
|
2023-06-20 19:22:59 +01:00
|
|
|
{#if service.stops[0]['publicDeparture']}
|
|
|
|
<h2>GW: {service.stops[0]['publicDeparture']} {service.stops[0]['tiploc']} to {service.stops[service['stops'].length -1]['tiploc']}</h2>
|
|
|
|
<p>PIS: {service.pis}</p>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>Location</th>
|
|
|
|
<th>Sch Arr.</th>
|
|
|
|
<th>Sch Dep.</th>
|
|
|
|
</tr>
|
|
|
|
{#each service.stops as stop}
|
|
|
|
{#if stop.publicArrival || stop.publicDeparture}
|
|
|
|
<tr>
|
|
|
|
<td>{stop.tiploc}</td>
|
|
|
|
<td>{stop.publicArrival || '-'}</td>
|
|
|
|
<td>{stop.publicDeparture || '-'}</td>
|
|
|
|
</tr>
|
|
|
|
{/if}
|
|
|
|
{/each}
|
|
|
|
</table>
|
|
|
|
{:else}
|
|
|
|
<h2>GW: {service.stops[0]['wttDeparture']} {service.stops[0]['tiploc']} to {service.stops[service['stops'].length -1]['tiploc']}</h2>
|
|
|
|
<p>PIS: {service.pis}</p>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>Location</th>
|
|
|
|
<th>Sch Arr.</th>
|
|
|
|
<th>Sch Dep.</th>
|
|
|
|
</tr>
|
|
|
|
{#each service.stops as stop}
|
|
|
|
<tr>
|
|
|
|
<td>{stop.tiploc}</td>
|
2023-06-20 19:26:01 +01:00
|
|
|
<td>{stop.wttArrival || '-'}</td>
|
|
|
|
<td>{stop.wttDeparture || '-'}</td>
|
2023-06-20 19:22:59 +01:00
|
|
|
</tr>
|
|
|
|
{/each}
|
|
|
|
</table>
|
|
|
|
{/if}
|
2023-06-19 21:55:23 +01:00
|
|
|
{/each}
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-06-20 19:22:59 +01:00
|
|
|
<Nav />
|
|
|
|
|
|
|
|
<style>
|
|
|
|
h2 {
|
2023-06-21 20:55:31 +01:00
|
|
|
margin-top: 20px;
|
2023-06-20 19:22:59 +01:00
|
|
|
}
|
|
|
|
p {
|
2023-06-20 19:24:17 +01:00
|
|
|
color: white;
|
2023-06-21 20:55:31 +01:00
|
|
|
font-size: 18px;
|
2023-06-20 19:22:59 +01:00
|
|
|
font-weight: 600;
|
|
|
|
}
|
|
|
|
table {
|
|
|
|
margin: auto;
|
2023-06-20 19:24:17 +01:00
|
|
|
color: white;
|
2023-06-21 20:55:31 +01:00
|
|
|
font-size: 16px;
|
2023-06-20 19:22:59 +01:00
|
|
|
}
|
|
|
|
th, td {
|
|
|
|
padding-left: 8px;
|
|
|
|
padding-right: 8px;
|
|
|
|
}
|
|
|
|
</style>
|