Further work on staff LDB
This commit is contained in:
parent
9dae8671ff
commit
aa004155d4
@ -2,6 +2,7 @@
|
|||||||
export let station = "";
|
export let station = "";
|
||||||
export let title = "Loading...";
|
export let title = "Loading...";
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
|
import AlertBar from './alert-bar.svelte';
|
||||||
import StaffTrainDetail from '$lib/ldb/staff-train-detail.svelte';
|
import StaffTrainDetail from '$lib/ldb/staff-train-detail.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';
|
||||||
@ -14,6 +15,7 @@
|
|||||||
let services = [];
|
let services = [];
|
||||||
let dataAge = null;
|
let dataAge = null;
|
||||||
let isLoading = true;
|
let isLoading = true;
|
||||||
|
let alerts = [];
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (jsonData?.GetBoardResult?.generatedAt) {
|
if (jsonData?.GetBoardResult?.generatedAt) {
|
||||||
@ -31,6 +33,10 @@
|
|||||||
} else {
|
} else {
|
||||||
title = "Loading Board"
|
title = "Loading Board"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (jsonData?.GetBoardResult?.nrccMessages) {
|
||||||
|
alerts = processNrcc(jsonData.GetBoardResult?.nrccMessages?.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
@ -66,15 +72,43 @@
|
|||||||
return '-'
|
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 <p> 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(() => {
|
onMount(() => {
|
||||||
fetchData();
|
fetchData();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<p>Staff Boards not yet implemented</p>
|
<p>Staff Boards not yet fully implemented</p>
|
||||||
{#if isLoading}
|
{#if isLoading}
|
||||||
<Loading />
|
<Loading />
|
||||||
{:else}
|
{:else}
|
||||||
|
{#if alerts.length}
|
||||||
|
<AlertBar {alerts} />
|
||||||
|
{/if}
|
||||||
<p id="timestamp">Updated: {dataAge.toLocaleTimeString()}</p>
|
<p id="timestamp">Updated: {dataAge.toLocaleTimeString()}</p>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
@ -88,25 +122,42 @@
|
|||||||
<th class="time">Exp Dep</th>
|
<th class="time">Exp Dep</th>
|
||||||
</tr>
|
</tr>
|
||||||
{#each services as service}
|
{#each services as service}
|
||||||
<tr>
|
{#await generateServiceStats(service)}
|
||||||
<th class="id id-data data">{service.trainid}</th>
|
<tr>
|
||||||
<th class="from from-data data">{service.origin.location.tiploc}</th>
|
<td colspan="8">
|
||||||
<th class="to to-data data">{service.destination.location.tiploc}</th>
|
Loading...
|
||||||
<th class="plat plat-data data">{service.platform || '-'}</th>
|
</td>
|
||||||
<th class="time time-data data">{parseDateTime(service.sta)}</th>
|
</tr>
|
||||||
<th class="time time-data data">{parseDateTime(service.ata || service.eta)}</th>
|
{:then serviceStats}
|
||||||
<th class="time time-data data">{parseDateTime(service.std)}</th>
|
|
||||||
{#if service.isCancelled}
|
<!-- Await a 'Generate Stats' function here which can evaluate the data and provide
|
||||||
<th class="time time-data data can-time">CAN</th>
|
relevant BOOLs like isCancelled, isEarly, isLate, isNonPassenger and calculate train length
|
||||||
{:else}
|
where 'length' is not provided but 'formation' is. -->
|
||||||
|
<tr>
|
||||||
|
<th class="id id-data data">{service.trainid}</th>
|
||||||
|
<th class="from from-data data">{service.origin.location.tiploc}</th> <!-- From and To fields are arrays if more than one origin/destination is served -->
|
||||||
|
<th class="to to-data data">{service.destination.location.tiploc}</th>
|
||||||
|
<th class="plat plat-data data">{service.platform || '-'}</th>
|
||||||
|
<th class="time time-data data">{parseDateTime(service.sta)}</th>
|
||||||
|
<th class="time time-data data">{parseDateTime(service.ata || service.eta)}</th>
|
||||||
|
<th class="time time-data data">{parseDateTime(service.std)}</th>
|
||||||
<th class="time time-data data">{parseDateTime(service.atd || service.etd)}</th>
|
<th class="time time-data data">{parseDateTime(service.atd || service.etd)}</th>
|
||||||
{/if}
|
</tr>
|
||||||
</tr>
|
<tr class="text-row">
|
||||||
<tr class="text-row">
|
<td colspan="8" class="text-data">
|
||||||
<td colspan="8" class="text-data">
|
{service.operator} {#if service.length} - {service.length} carriages{/if}
|
||||||
{service.operator}
|
<br>
|
||||||
</td>
|
{#if service.isCancelled}
|
||||||
</tr>
|
{#await getReasonCodeData(service.cancelReason)}
|
||||||
|
This train has been cancelled
|
||||||
|
{:then reasonCode}
|
||||||
|
{reasonCode[0].cancReason}
|
||||||
|
<br>
|
||||||
|
{/await}
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/await}
|
||||||
{/each}
|
{/each}
|
||||||
</table>
|
</table>
|
||||||
{/if}
|
{/if}
|
||||||
@ -143,6 +194,7 @@
|
|||||||
.text-data {
|
.text-data {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
color: cyan;
|
color: cyan;
|
||||||
|
font-size: smaller;
|
||||||
}
|
}
|
||||||
|
|
||||||
.can-time {
|
.can-time {
|
||||||
|
Loading…
Reference in New Issue
Block a user