From cb8aff5788ccc0c0c61c11aaaff736c1bca27914 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 7 Jul 2023 13:53:49 +0100 Subject: [PATCH] Work on staff train detail --- src/lib/islands/overlay-island.svelte | 2 +- src/lib/ldb/staff-ldb.svelte | 35 ++++++- src/lib/ldb/staff-train-detail.svelte | 142 ++++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 6 deletions(-) diff --git a/src/lib/islands/overlay-island.svelte b/src/lib/islands/overlay-island.svelte index acd8a96..971731c 100644 --- a/src/lib/islands/overlay-island.svelte +++ b/src/lib/islands/overlay-island.svelte @@ -21,7 +21,7 @@ top: 50%; left: 50%; transform: translateY(-50%) translateX(-50%); - width: 75%; + width: 85%; height: auto; max-height: 75vh; overflow-y: auto; diff --git a/src/lib/ldb/staff-ldb.svelte b/src/lib/ldb/staff-ldb.svelte index 373befb..4578cd6 100644 --- a/src/lib/ldb/staff-ldb.svelte +++ b/src/lib/ldb/staff-ldb.svelte @@ -16,6 +16,7 @@ let dataAge = null; let isLoading = true; let alerts = []; + let detail = {show: false, rid:'',uid:'', headcode:''} $: { if (jsonData?.GetBoardResult?.generatedAt) { @@ -213,11 +214,35 @@ return processedMessages; } + async function showDetails(rid, uid, tid) { + detail = { + rid: rid, + uid: uid, + headcode: tid, + show: true + }; + } + + function hideDetails() { + detail = { + rid: '', + uid: '', + headcode: '', + show: false + }; + } + onMount(() => { fetchData(); }); +{#key detail} + {#if detail.show} + + {/if} +{/key} + {#if isLoading} {:else} @@ -242,10 +267,10 @@ Loading... {:then serviceStats} - - {service.trainid} - {serviceStats.from} - {serviceStats.to} + + {service.trainid} + {serviceStats.from} + {serviceStats.to} {serviceStats.platform.number || '-'} {serviceStats.schArr} + import OverlayIsland from "$lib/islands/overlay-island.svelte"; + import Loading from "$lib/navigation/loading.svelte"; + import { uuid } from "$lib/stores/uuid"; + export let detail = { + uid: '', + rid: '', + headcode: '', + show: true, + }; + export let close; + + function handleClick() { + close(); + } + + async function getTrain(rid) { + try { + console.log(`Requested Station: ${rid}`); + const url = `https://owlboard.info/api/v2/live/train/rid/${rid}`; + const opt = { + method: 'GET', + headers: { + uuid: $uuid + } + }; + const data = await fetch(url, opt); + return await data.json(); + } catch (error) { + console.error('Error fetching data:', error); + } + } + + async function parseDelay(location) { + let string, state; + if (location?.lateness) { + try { + const result = Math.floor(location.lateness / 60) + if (result === 0) {string = "RT", state = ''} + else if (result < 0) {string = -result + 'E', state = "early"} + else if (result > 0) {string = result + 'L', state = "late"}; + } catch { + string = '-', state = ''; + } + } else if (location.arrivalType === "Delayed") { + string = "LATE", state = "late"; + } + return { + string: string, + state: state + }; + } + + + +
+ {#await getTrain(detail.rid)} +
{detail.headcode}
+ + {:then train} +
{train.GetServiceDetailsResult.operatorCode}: {detail.headcode}
+

Locations in grey are not scheduled stops +
+ Some stops may be operational stops, not passenger stops. +

+ + + + + + + + + + {#each train.GetServiceDetailsResult.locations.location as location} + + + + + + {#await parseDelay(location)} + + {:then delay} + + {/await} + + {/each} +
LocationPlat.Sch ArrSch DepDelay
{location.tiploc}{location.platform || ''}ARDP-{delay.string}
+ {:catch} +
Error loading data
+ {/await} +
+
+ + \ No newline at end of file