Begin work on StaffLDB

This commit is contained in:
Fred Boniface 2023-07-02 21:40:54 +01:00
parent 5b1daf31e6
commit 475746300e

View File

@ -1,9 +1,10 @@
<script> <script>
export let station = ""; export let station = "";
export let title = ""; export let title = "Loading...";
import { onMount } from 'svelte' import { onMount } from 'svelte'
import Loading from '$lib/navigation/loading.svelte'; import Loading from '$lib/navigation/loading.svelte';
import Nav from '$lib/navigation/nav.svelte'; import Nav from '$lib/navigation/nav.svelte';
import { uuid } from '$lib/stores/uuid';
let requestedStation; let requestedStation;
$: requestedStation = station; $: requestedStation = station;
@ -14,22 +15,18 @@
let isLoading = true; let isLoading = true;
$: { $: {
if (jsonData === null && requestedStation) { if (jsonData?.GetBoardResult?.generatedAt) {
fetchData(); dataAge = new Date(jsonData.GetBoardResult.generatedAt);
} }
if (jsonData?.GetStationBoardResult?.generatedAt) { if (jsonData?.GetBoardResult?.trainServices?.service) {
dataAge = new Date(jsonData.GetStationBoardResult.generatedAt); services = jsonData.GetBoardResult.trainServices.service;
}
if (jsonData?.GetStationBoardResult?.trainServices?.service) {
services = jsonData.GetStationBoardResult.trainServices.service;
} else { } else {
services = []; services = [];
} }
if (jsonData?.GetStationBoardResult?.locationName) { if (jsonData?.GetBoardResult?.locationName) {
title = jsonData.GetStationBoardResult.locationName title = jsonData.GetBoardResult.locationName
} else { } else {
title = "Loading Board" title = "Loading Board"
} }
@ -39,7 +36,14 @@
isLoading = true; // Set loading state isLoading = true; // Set loading state
try { try {
console.log(`Requested Station: ${requestedStation}`); console.log(`Requested Station: ${requestedStation}`);
const data = await fetch(`https://owlboard.info/api/v1/ldb/${requestedStation}`); const url = `https://owlboard.info/api/v2/live/station/${requestedStation}/staff`;
const opt = {
method: "GET",
headers: {
"uuid": $uuid
}
}
const data = await fetch(url, opt);
jsonData = await data.json(); jsonData = await data.json();
} catch (error) { } catch (error) {
console.error("Error fetching data:", error); console.error("Error fetching data:", error);
@ -88,9 +92,7 @@
} }
onMount(() => { onMount(() => {
if (requestedStation && jsonData === null) {
fetchData(); fetchData();
}
}); });
</script> </script>
<p>Staff Boards not yet implemented</p> <p>Staff Boards not yet implemented</p>
@ -101,7 +103,16 @@
<p id="timestamp">Updated: {dataAge.toLocaleTimeString()}</p> <p id="timestamp">Updated: {dataAge.toLocaleTimeString()}</p>
<p>Staff LDB for {station}</p> <p>Staff LDB for {station}</p>
<!-- REST OF PAGE HERE --> {#each services as service}
<div class="service">
<p class="service-operator">{service.operatorCode}</p>
<p class="service-headcode">{service.trainid}</p>
<p class="service-origin">{service.origin.location.tiploc}</p>
<p class="service-dest">{service.destination.location.tiploc}</p>
<p class="service-plat">{service.platform}</p>
<p class="service-expArr">{new Date(service.sta).toLocaleTimeString() || '-'}</p>
</div>
{/each}
{/if} {/if}
<Nav /> <Nav />