Add 'getTrainByUID - and format

This commit is contained in:
Fred Boniface 2023-07-13 19:40:32 +01:00
parent 6795809098
commit be7d0106d5
3 changed files with 84 additions and 41 deletions

View File

@ -333,7 +333,10 @@
.tableTxt { .tableTxt {
font-size: 14px; font-size: 14px;
} }
td.to,td.from,th.to,th.from { td.to,
td.from,
th.to,
th.from {
text-align: center; text-align: center;
} }
} }

View File

@ -0,0 +1,15 @@
<p id="load">Loading...</p>
<style>
#load {
margin-top: 5px;
font-size: 18px;
font-weight: 600;
color: white;
animation: pulse-loading 2.5s linear infinite;
}
@keyframes pulse-loading {
50% {
color: rgb(136, 164, 255);
}
}
</style>

View File

@ -1,15 +1,34 @@
<script> <script>
import { fly } from 'svelte/transition'; import { fly } from 'svelte/transition';
import { uuid } from '$lib/stores/uuid';
import LoadingText from '$lib/navigation/loading-text.svelte';
export let service = ''; export let service = '';
let isExpanded = false; let isExpanded = false;
async function getTrainByUID(tuid = '') {
const url = `https://owlboard.info/api/v2/timetable/train/byTrainUid/${tuid}`;
const options = {
method: 'GET',
headers: {
uuid: $uuid
}
};
const res = await fetch(url, options);
if (res.status === 200) {
return await res.json();
} else {
throw new Error('Unable to Fetch');
}
}
async function expand() { async function expand() {
isExpanded = !isExpanded; isExpanded = !isExpanded;
} }
</script> </script>
<!-- The next version of backend will only return a subset of information required to display the container-header
<!-- The next version of backend will only return a subset of information required to display the container-header
, the container will then be responsible for fetching more data using the trainUid. --> , the container will then be responsible for fetching more data using the trainUid. -->
<div class="container"> <div class="container">
<div class="container-header" on:click={expand} on:keypress={expand}> <div class="container-header" on:click={expand} on:keypress={expand}>
@ -21,48 +40,54 @@
</div> </div>
{#if isExpanded} {#if isExpanded}
<div class="container-detail" in:fly={{ y: -20, duration: 200 }}> <div class="container-detail" in:fly={{ y: -20, duration: 200 }}>
{#if service.pis} {#await getTrainByUID(service.trainUid)}
<p class="pis">PIS: {service.pis}</p> <LoadingText />
{/if} {:then serviceDetail}
<p class="svc-detail"> {#if serviceDetail.pis}
Planned Type: {parseInt(service.planSpeed) || 68}mph {service.powerType || 'Bus'} <p class="pis">PIS: {serviceDetail.pis}</p>
</p> {/if}
<p class="svc-detail"> <p class="svc-detail">
Days Run: {service.daysRun.join(', ').toUpperCase()} Planned Type: {parseInt(serviceDetail.planSpeed) || 68}mph {serviceDetail.powerType || 'Bus'}
</p> </p>
<p class="svc-detail validity"> <p class="svc-detail">
Valid From: {new Date(service.scheduleStartDate).toLocaleDateString('en-GB', { Days Run: {serviceDetail.daysRun.join(', ').toUpperCase()}
timeZone: 'UTC' </p>
})} - {new Date(service.scheduleEndDate).toLocaleDateString('en-GB', { <p class="svc-detail validity">
timeZone: 'UTC' Valid From: {new Date(serviceDetail.scheduleStartDate).toLocaleDateString('en-GB', {
})} timeZone: 'UTC'
</p> })} - {new Date(serviceDetail.scheduleEndDate).toLocaleDateString('en-GB', {
<table> timeZone: 'UTC'
<tr> })}
<th>Location</th> </p>
<th>Sch Arr.</th> <table>
<th>Sch Dep.</th> <tr>
</tr> <th>Location</th>
{#if service.stops[0]['publicDeparture']} <th>Sch Arr.</th>
{#each service.stops as stop} <th>Sch Dep.</th>
{#if stop.publicArrival || stop.publicDeparture} </tr>
{#if serviceDetail.stops[0]['publicDeparture']}
{#each serviceDetail.stops as stop}
{#if stop.publicArrival || stop.publicDeparture}
<tr>
<td>{stop.tiploc}</td>
<td>{stop.publicArrival || '-'}</td>
<td>{stop.publicDeparture || '-'}</td>
</tr>
{/if}
{/each}
{:else}
{#each serviceDetail.stops as stop}
<tr> <tr>
<td>{stop.tiploc}</td> <td>{stop.tiploc}</td>
<td>{stop.publicArrival || '-'}</td> <td>{stop.wttArrival || '-'}</td>
<td>{stop.publicDeparture || '-'}</td> <td>{stop.wttDeparture || '-'}</td>
</tr> </tr>
{/if} {/each}
{/each} {/if}
{:else} </table>
{#each service.stops as stop} {:catch}
<tr> <p>Unable to fetch train data</p>
<td>{stop.tiploc}</td> {/await}
<td>{stop.wttArrival || '-'}</td>
<td>{stop.wttDeparture || '-'}</td>
</tr>
{/each}
{/if}
</table>
</div> </div>
{/if} {/if}
</div> </div>