diff --git a/src/lib/ldb/staff-ldb.svelte b/src/lib/ldb/staff-ldb.svelte index ccc3354..e73d003 100644 --- a/src/lib/ldb/staff-ldb.svelte +++ b/src/lib/ldb/staff-ldb.svelte @@ -2,6 +2,7 @@ export let station = ""; export let title = "Loading..."; import { onMount } from 'svelte' + import AlertBar from './alert-bar.svelte'; import StaffTrainDetail from '$lib/ldb/staff-train-detail.svelte'; import Loading from '$lib/navigation/loading.svelte'; import Nav from '$lib/navigation/nav.svelte'; @@ -14,6 +15,7 @@ let services = []; let dataAge = null; let isLoading = true; + let alerts = []; $: { if (jsonData?.GetBoardResult?.generatedAt) { @@ -31,6 +33,10 @@ } else { title = "Loading Board" } + + if (jsonData?.GetBoardResult?.nrccMessages) { + alerts = processNrcc(jsonData.GetBoardResult?.nrccMessages?.message) + } } async function fetchData() { @@ -65,16 +71,44 @@ } return '-' } + + async function getReasonCodeData(code) { + const url = `https://owlboard.info/api/v2/ref/reasonCode/${code}` + const res = await fetch(url); + const json = await res.json(); + return json + } + + async function generateServiceStats(service) { + return; + } + + function processNrcc(messages) { // Remove newlines and then
tags from input and append to array + let arrMessages; + if (!Array.isArray(messages)) { + arrMessages = [messages]; + } else { + arrMessages = messages; + } + let processedMessages = []; + for (const message of arrMessages) { + const msgText = message.xhtmlMessage + processedMessages.push(msgText.replace(/[\n\r]/g, '').replace(/<\/?p[^>]*>/g, '')); + } + return processedMessages; + } onMount(() => { fetchData(); }); -
Staff Boards not yet implemented
+Staff Boards not yet fully implemented
{#if isLoading}Updated: {dataAge.toLocaleTimeString()}
Exp Dep | |||||||
---|---|---|---|---|---|---|---|
{service.trainid} | -{service.origin.location.tiploc} | -{service.destination.location.tiploc} | -{service.platform || '-'} | -{parseDateTime(service.sta)} | -{parseDateTime(service.ata || service.eta)} | -{parseDateTime(service.std)} | - {#if service.isCancelled} -CAN | - {:else} + {#await generateServiceStats(service)} +
+ Loading... + | +|||||||
{service.trainid} | +{service.origin.location.tiploc} | +{service.destination.location.tiploc} | +{service.platform || '-'} | +{parseDateTime(service.sta)} | +{parseDateTime(service.ata || service.eta)} | +{parseDateTime(service.std)} | {parseDateTime(service.atd || service.etd)} | - {/if} -
- {service.operator} - | -|||||||
+ {service.operator} {#if service.length} - {service.length} carriages{/if}
+ + {#if service.isCancelled} + {#await getReasonCodeData(service.cancelReason)} + This train has been cancelled + {:then reasonCode} + {reasonCode[0].cancReason} + + {/await} + {/if} + |
+