From aa004155d4fef597bd700be09581193210df5277 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Thu, 6 Jul 2023 12:26:57 +0100 Subject: [PATCH] Further work on staff LDB --- src/lib/ldb/staff-ldb.svelte | 92 ++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 20 deletions(-) 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} {:else} - + {#if alerts.length} + + {/if}

Updated: {dataAge.toLocaleTimeString()}

@@ -88,25 +122,42 @@ {#each services as service} - - - - - - - - - {#if service.isCancelled} - - {:else} + {#await generateServiceStats(service)} + + + + {:then serviceStats} + + + + + + + + + + - {/if} - - - - + + + + + {/await} {/each}
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)}CAN
+ 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)}
- {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} +
{/if} @@ -143,6 +194,7 @@ .text-data { text-align: left; color: cyan; + font-size: smaller; } .can-time {