diff --git a/src/lib/ldb/staff/fetch.ts b/src/lib/ldb/staff/fetch.ts new file mode 100644 index 0000000..c1d64ac --- /dev/null +++ b/src/lib/ldb/staff/fetch.ts @@ -0,0 +1,10 @@ +// Fetches StaffLDB Data, correctly formats DATE fields and returns the data + +import { getApiUrl } from "$lib/scripts/upstream"; +import type { ApiResponse, StaffLdb } from "@owlboard/ts-types"; + +// Fetch StaffLDB Data, and returns the data after hydration (convert date types etc.) +export async function fetchStaffLdb(station: string, auth: string): Promise> { + const url = `${getApiUrl()}//api/v2/live/station/${station}/staff`; + +} \ No newline at end of file diff --git a/src/lib/ldb/staff/staff-ldb.svelte b/src/lib/ldb/staff/staff-ldb.svelte index 7245c43..b5cab68 100644 --- a/src/lib/ldb/staff/staff-ldb.svelte +++ b/src/lib/ldb/staff/staff-ldb.svelte @@ -1,16 +1,30 @@ +{#key detail} + {#if detail.show} + + {/if} +{/key} + {#await fetchStaffLdb(station)} - Loading + {:then data} - Loaded {JSON.stringify(data)} + {#if data} +

Updated: {new Date(data.generatedAt).toLocaleTimeString()}

+ {#if data.trainServices?.length} + + {/if} + {#if data.busServices?.length} + Bus services
+ Bus Services + + {/if} + {#if data.ferryServices?.length} + Ferry services
+ Ferry Services + + {/if} + {/if} {:catch} - Error Loading + Error Loading Data {/await} {#if error.state} -{#if error.name === 'unauthorized'} -

Error: {error.name.toLocaleUpperCase()}

-{/if} + {#if error.name === 'unauthorized'} +

Error: {error.name.toLocaleUpperCase()}

+ {/if} {/if} diff --git a/src/lib/ldb/staff/table/table-generator.svelte b/src/lib/ldb/staff/table/table-generator.svelte index a6c3cc7..675bcad 100644 --- a/src/lib/ldb/staff/table/table-generator.svelte +++ b/src/lib/ldb/staff/table/table-generator.svelte @@ -5,7 +5,7 @@ import type { TrainServices, ServiceLocation } from '@owlboard/ts-types'; export let services: TrainServices[]; - export let click: any; // Not sure of the type here! + export let click: Function; function detail(event: any, rid: string, uid: string, tid: string) { const target = event.target; @@ -17,10 +17,14 @@ for (const location of locations) { tiplocs.push(location.tiploc); } - return tiplocs.join(' & '); + let location = tiplocs.join(' & '); + if (locations[0]['via']) { + location = `${location} ${locations[0]['via']}` // Maybe this should be converted to TIPLOC server-side? + } + return location } - async function classGenerator(service: TrainServices) { + async function classGenerator(service: TrainServices) { // This function needs updating next let otherArr: string[] = []; let arrArr: string[] = []; let depArr: string[] = []; @@ -88,6 +92,7 @@

Your display is too small to view this data

+

Try rotating your device

@@ -112,10 +117,10 @@ > {#await classGenerator(service) then classes} - - + + - + diff --git a/src/lib/ldb/staff/train-detail.ts b/src/lib/ldb/staff/train-detail.ts new file mode 100644 index 0000000..17c4eb0 --- /dev/null +++ b/src/lib/ldb/staff/train-detail.ts @@ -0,0 +1,26 @@ +export interface Detail { + show: boolean; + headcode: string; + rid: string; + uid: string; +} + +export function detailInit(): Detail { + const detail: Detail = { + show: false, + headcode: '', + rid: '', + uid: '' + }; + return detail; +} + +export function defineDetail(rid: string, uid: string, tid: string) { + const detail: Detail = { + rid: rid, + uid: uid, + headcode: tid, + show: true + }; + return detail; +}
ID{service.trainid}{#await formatLocations(service.origin) then txt}{txt}{/await}{#await formatLocations(service.destination) then txt}{txt}{/await}{#await formatLocations(service.origin) then origin}{origin}{/await}{#await formatLocations(service.destination) then dest}{dest}{/await} {service.platform || '-'}{service.sta || '-'}{service?.sta || '-'} {service.eta || service.ata || '-'}