Compare commits

..

1 Commits

6 changed files with 334 additions and 171 deletions

View File

@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import type { ApiStationsBoard } from '@owlboard/owlboard-ts'; import type { ApiStationsBoard } from '@owlboard/owlboard-ts';
import { formatUkTime, estClass, delayClassFromTimePair } from '$lib/utils/time'; import { formatUkTime, estClass, delayClassFromTimePair } from '$lib/utils/time';
let { services }: { services: ApiStationsBoard.BoardService[] } = $props(); let { services }: { services: ApiStationsBoard.BoardService[] } = $props();
@@ -8,141 +8,263 @@
`${s.r}${s.sta ?? ''}${s.std ?? ''}${s.wtp ?? ''}`; `${s.r}${s.sta ?? ''}${s.std ?? ''}${s.wtp ?? ''}`;
</script> </script>
<table class="departure-board"> <table class="departure-board">
<thead> <thead>
<tr> <tr>
<th colspan="4" aria-hidden="true"></th> <th colspan="4" aria-hidden="true"></th>
<th scope="colgroup" colspan="2" class="upper-head"><abbr title="Arrival">Arr</abbr></th> <th scope="colgroup" colspan="2" class="upper-head"><abbr title="Arrival">Arr</abbr></th>
<th scope="colgroup" colspan="2" class="upper-head"><abbr title="Departure">Dep</abbr></th> <th scope="colgroup" colspan="2" class="upper-head"><abbr title="Departure">Dep</abbr></th>
</tr> </tr>
<tr> <tr>
<th scope="col"><abbr title="Headcode">ID</abbr></th> <th scope="col"><abbr title="Headcode">ID</abbr></th>
<th scope="col"><abbr title="Origin">Orig</abbr></th> <th scope="col"><abbr title="Origin">Orig</abbr></th>
<th scope="col"><abbr title="Destination">Dest</abbr></th> <th scope="col"><abbr title="Destination">Dest</abbr></th>
<th scope="col"><abbr title="Platform">Plt</abbr></th> <th scope="col"><abbr title="Platform">Plt</abbr></th>
<th scope="col"><abbr title="Scheduled">Sch</abbr></th> <th scope="col"><abbr title="Scheduled">Sch</abbr></th>
<th scope="col"><abbr title="Actual/Expected">Act</abbr></th> <th scope="col"><abbr title="Actual/Expected">Act</abbr></th>
<th scope="col"><abbr title="Scheduled">Sch</abbr></th> <th scope="col"><abbr title="Scheduled">Sch</abbr></th>
<th scope="col"><abbr title="Actual/Expected">Act</abbr></th> <th scope="col"><abbr title="Actual/Expected">Act</abbr></th>
</tr>
</thead>
{#each services as service (getRowKey(service))}
<tbody>
<tr class="service-row" class:serviceCancelled={service.c} class:servicePass={service.wtp} class:serviceNonPassenger={!service.ip}>
<td class="id-cell">{service.h}</td>
<td class="orig-cell"><abbr title={service.og.n.toLocaleUpperCase()}>{service.og.t}</abbr></td>
<td class="dest-cell"><abbr title={service.dt.n.toLocaleUpperCase()}>{service.dt.t}</abbr></td>
<td class="plt-cell" class:platSup={service.ps} class:platChange={service.pc}
>{service.p || '-'}</td
>
<!-- Handle different display for a passing train -->
{#if service.wtp}
<td class="pass-cell" colspan="2">Pass</td>
<td class="time-cell">{formatUkTime(service.wtp)}</td>
<!-- If cancelled, show '-', otherwise check for RT or show time -->
<td
class="time-cell {estClass(service.atp, service.etp)} {delayClassFromTimePair(
service.wtp,
service.atp || service.etp
)}"
>
<span>
{service.c
? '-'
: delayClassFromTimePair(service.wtp, service.atp || service.etp) === 'delay-rt'
? 'RT'
: formatUkTime(service.atp || service.etp)}
</span>
</td>
{:else}
<td class="time-cell">{formatUkTime(service.sta)}</td>
<!-- Arrival Actual/Expected -->
<td
class="time-cell {estClass(service.ata, service.eta)} {delayClassFromTimePair(
service.sta,
service.ata || service.eta
)}"
>
<span>
{service.c
? '-'
: delayClassFromTimePair(service.sta, service.ata || service.eta) === 'delay-rt'
? 'RT'
: formatUkTime(service.ata || service.eta)}
</span>
</td>
<td class="time-cell">{formatUkTime(service.std)}</td>
<!-- Departure Actual/Expected -->
<td
class="time-cell {estClass(service.atd, service.etd)} {delayClassFromTimePair(
service.std,
service.atd || service.etd
)}"
>
<span>
{service.c
? '-'
: delayClassFromTimePair(service.std, service.atd || service.etd) === 'delay-rt'
? 'RT'
: formatUkTime(service.atd || service.etd)}
</span>
</td>
{/if}
</tr> </tr>
</thead>
{#each services as service (getRowKey(service))} {#if service.c && service.cr?.r}
<tbody> <tr class="cancel-row">
<tr class="service-row" class:serviceCancelled={service.c} class:servicePass={service.wtp}> <td colspan="9">
<td class="id-cell">{service.h}</td> {service.cr.r}
<td class="orig-cell">{service.og.t}</td> {#if service.cr.l}
<td class="dest-cell">{service.dt.t}</td> {service.cr.n ? 'near' : 'at'}
<td class="plt-cell" class:platSup={service.ps} class:platChange={service.pc}>{service.p}</td> {service.cr.l}
{/if}
<!-- Handle different display for a passing train --> </td>
{#if service.wtp} </tr>
<td class="pass-cell" colspan="2">Pass</td> {/if}
<td class="time-cell">{formatUkTime(service.wtp)}</td> {#if service.dr?.r}
<td class="time-cell {estClass(service.atp, service.etp)} {delayClassFromTimePair(service.wtp, service.atp || service.etp)}">{formatUkTime(service.atp || service.etp)}</td> <tr class="delay-row">
{:else} <td colspan="9">
<td class="time-cell">{formatUkTime(service.sta)}</td> {service.dr.r}
<td class="time-cell {estClass(service.ata, service.eta)} {delayClassFromTimePair(service.sta, service.ata || service.eta)}">{formatUkTime(service.ata || service.eta)}</td> {#if service.dr.l}
<td class="time-cell">{formatUkTime(service.std)}</td> {service.dr.n ? 'near' : 'at'}
<td class="time-cell {estClass(service.atd, service.etd)} {delayClassFromTimePair(service.std, service.atd || service.etd)}">{formatUkTime(service.atd || service.etd)}</td> {service.dr.l}
{/if} {/if}
</tr> </td>
</tr>
{#if service.c && service.cr?.r} {/if}
<tr> </tbody>
<td aria-hidden="true"></td> {/each}
<td colspan="8"> </table>
{service.cr.r}
{#if service.cr.l}
{service.cr.n ? "near" : "at"}
{service.cr.l}
{/if}
</td>
</tr>
{/if}
{#if service.dr?.r}
<tr>
<td aria-hidden="true"></td>
<td colspan="8">
{service.dr.r}
{#if service.dr.l}
{service.dr.n ? "near" : "at"}
{service.dr.l}
{/if}
</td>
</tr>
{/if}
</tbody>
{/each}
</table>
<style> <style>
.departure-board { .departure-board {
width: 100%; width: 100%;
margin: 0 auto; margin: 5px auto;
font-family: 'URW Gothic', sans-serif; border-collapse: collapse;
font-variant-numeric: tabular-nums; }
border-collapse: collapse;
} .departure-board td {
thead { font-family: 'Inconsolate Variable', monospace;
position: sticky; font-size: 1rem;
top: 0; font-variant-numeric: tabular-nums;
z-index: 2; font-variant-ligatures: additional-ligatures;
background: var(--color-bg-dark); }
}
.serviceCancelled { thead,
text-decoration: line-through; .cancel-row td,
} .delay-row td {
.servicePass { font-family: 'URW Gothic', sans-serif;
font-style: italic; letter-spacing: 0.02ch;
}
thead {
position: sticky;
top: 0;
z-index: 2;
background: var(--color-bg-dark);
}
abbr {
text-decoration: none;
border-bottom: none;
cursor:help;
}
/* Row Logic */
.serviceCancelled {
color: rgb(255, 131, 131);
}
.servicePass td {
opacity: 0.75;
font-weight: 200;
}
.serviceNonPassenger td {
opacity: 0.5; opacity: 0.5;
font-weight: 200;
font-style: italic;
} }
.id-cell{
font-family:'Courier New', Courier, monospace; /* Special Row Styles */
text-align: center; .cancel-row td,
} .delay-row td {
.orig-cell, .dest-cell { font-size: 0.88rem;
color: var(--location-yellow); padding-bottom: 8px;
} }
.orig-cell {
text-align: left; .cancel-row td[colspan],
} .delay-row td[colspan] {
.dest-cell { padding-left: 0.75ch;
text-align: right; }
}
.plt-cell { .cancel-row td {
text-align: center; color: rgb(255, 131, 131);
} font-weight: 400;
.platChange { }
animation: 2s fast-pulse ease-in-out infinite;
} .delay-row td {
.platSup { color: var(--delay-orange);
filter: opacity(0.5); font-style: italic;
} }
.pass-cell {
text-align: center; /* Column Specifics */
} .id-cell {
.time-cell { text-align: center;
text-align: center; font-weight: 400;
} font-stretch: 80%;
.est { filter: brightness(0.75);
font-style: oblique; }
opacity: 0.75; .orig-cell,
} .dest-cell {
.act { font-stretch: 90%;
font-weight: 600; font-weight: 400;
color: green; }
} .orig-cell {
.delay-cell { text-align: left;
text-align: center; color: var(--location-yellow);
} }
.delay-late { .dest-cell {
color: var(--delay-orange); text-align: right;
animation: 2s fast-pulse ease-in-out infinite; color: var(--location-yellow);
} }
.delay-early { .plt-cell {
color: var(--early-blue); text-align: center;
animation: 2s fast-pulse ease-in-out infinite; font-weight: 405;
} font-stretch: 70%;
}
.plt-cell.platSup {
font-weight: 200;
opacity: 0.3;
}
.plt-cell.platChange {
animation: fast-pulse 2s ease-out infinite;
}
.service-row.serviceCancelled .plt-cell {
text-decoration: line-through;
}
.pass-cell {
text-align: center;
}
/* Colour orig and dest values when cancelled */
.service-row.serviceCancelled .orig-cell,
.service-row.serviceCancelled .dest-cell {
color: rgb(255, 131, 131);
}
.time-cell {
text-align: center;
font-stretch: 70%;
}
/* RT Logic */
.time-cell.delay-rt span {
display: none;
}
.time-cell.delay-rt::after {
content: 'RT';
}
.time-cell.delay-early {
color: var(--early-blue);
}
.time-cell.delay-late {
color: var(--delay-orange);
}
/* Time Types */
.est {
font-style: italic;
opacity: 0.75;
font-weight: 200;
}
.act {
font-weight: 600;
}
</style> </style>

View File

@@ -49,6 +49,11 @@
margin-bottom: 0; margin-bottom: 0;
width: 95%; width: 95%;
max-width: 750px; max-width: 750px;
-webkit-tap-highlight-color: transparent;
}
.alert-card:active {
filter: brightness(1.2);
} }
.trigger { .trigger {
@@ -56,7 +61,7 @@
display: flex; display: flex;
border-radius: 8px; border-radius: 8px;
align-items: center; align-items: center;
padding: 0.4rem 1rem; padding: 0.1rem 1.05rem;
background: var(--alert-orange); background: var(--alert-orange);
color: white; color: white;
border: none; border: none;
@@ -64,13 +69,13 @@
text-align: left; text-align: left;
position: relative; position: relative;
z-index: 2; z-index: 2;
height: 46px; height: 40px;
transition: all 0.65s 0.2s; transition: all 0.65s 0.2s;
} }
.trigger.active { .trigger.active {
border-radius: 8px 8px 0 0; border-radius: 8px 8px 0 0;
transition: all 0.1s 0s; transition: all 0.01s 0s;
} }
.warning-icon { .warning-icon {
@@ -105,7 +110,7 @@
.content { .content {
padding: 1rem; padding: 1rem;
position: absolute; position: absolute;
top: 46px; top: 40px;
border-radius: 0 0 8px 8px; border-radius: 0 0 8px 8px;
left: 0; left: 0;
right: 0; right: 0;

View File

@@ -129,6 +129,36 @@
font-style: normal; font-style: normal;
font-display: swap; font-display: swap;
} }
/* Fira Code - Variable with fallback */
@font-face {
font-family: 'Fira Code';
src: url('/type/fira-code/FiraCode-VF.woff2') format('woff2-variations');
font-weight: 300 700;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Fira Code';
src: url('/type/fira-code/FiraCode-Regular.woff2') format('woff2');
font-weight: 400;
font-style: normal;
font-display: swap;
}
/* Inconsolata Variable */
@font-face {
font-family: 'Inconsolata Variable';
font-style: normal;
font-display: swap;
font-weight: 200 900;
font-stretch: 50% 200%;
src: url(type/Inconsolata/latin-wdth-normal.woff2) format('woff2-variations');
unicode-range:
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
:root { :root {
/* Fixed Heights */ /* Fixed Heights */
--header-height: 80px; --header-height: 80px;
@@ -163,7 +193,7 @@
opacity: 1; opacity: 1;
} }
50% { 50% {
opacity: 0.3; opacity: 0.5;
} }
} }

View File

@@ -1,6 +1,6 @@
import type { ApiTrainsTrainDetails } from '@owlboard/owlboard-ts'; import type { ApiTrainsTrainDetails } from '@owlboard/owlboard-ts';
export const estClass = (act: any, est: any) => (!act && est ? 'est' : 'act'); export const estClass = (act: any, est: any) => (act ? 'act' : 'est');
/** /**
* Converts ISO/JSON time to UK-formatted HH:MM string, with optional (default off) seconds * Converts ISO/JSON time to UK-formatted HH:MM string, with optional (default off) seconds
@@ -10,10 +10,10 @@ export function formatUkTime(
dateStr: string | Date | undefined, dateStr: string | Date | undefined,
includeSeconds: boolean = false includeSeconds: boolean = false
): string { ): string {
if (!dateStr) return '--:--'; if (!dateStr) return '-';
const date = typeof dateStr === 'string' ? new Date(dateStr) : dateStr; const date = typeof dateStr === 'string' ? new Date(dateStr) : dateStr;
if (isNaN(date.getTime())) return '--:--'; if (isNaN(date.getTime())) return '-';
return date.toLocaleTimeString('en-GB', { return date.toLocaleTimeString('en-GB', {
hour: '2-digit', hour: '2-digit',
@@ -56,15 +56,21 @@ export function formatUkDateTime(
* Specific type that can handle the TrainDetails.ServiceLocation and the ApiStationsBoard.BoardService types for delay calculation * Specific type that can handle the TrainDetails.ServiceLocation and the ApiStationsBoard.BoardService types for delay calculation
*/ */
interface DelayInput { interface DelayInput {
// Board types // Board types
sta?: string | null; std?: string | null; sta?: string | null;
eta?: string | null; etd?: string | null; std?: string | null;
ata?: string | null; atd?: string | null; eta?: string | null;
etd?: string | null;
ata?: string | null;
atd?: string | null;
// Journey types // Journey types
pta?: string | null; ptd?: string | null; pta?: string | null;
wta?: string | null; wtd?: string | null; ptd?: string | null;
atp?: string | null; wtp?: string | null; wta?: string | null;
wtd?: string | null;
atp?: string | null;
wtp?: string | null;
etp?: string | null; etp?: string | null;
} }
@@ -79,13 +85,13 @@ export function calculateDelay(loc: DelayInput): {
type: string; type: string;
} { } {
const pairs = [ const pairs = [
// Departure check (Board: atd/etd vs std | Journey: atd vs ptd/wtd) // Departure check (Board: atd/etd vs std | Journey: atd vs ptd/wtd)
{ actual: loc.atd || loc.etd, sched: loc.std || loc.ptd || loc.wtd }, { actual: loc.atd || loc.etd, sched: loc.std || loc.ptd || loc.wtd },
// Arrival check (Board: ata/eta vs sta | Journey: ata vs pta/wta) // Arrival check (Board: ata/eta vs sta | Journey: ata vs pta/wta)
{ actual: loc.ata || loc.eta, sched: loc.sta || loc.pta || loc.wta }, { actual: loc.ata || loc.eta, sched: loc.sta || loc.pta || loc.wta },
// Passing check // Passing check
{ actual: loc.atp || loc.etp, sched: loc.wtp } { actual: loc.atp || loc.etp, sched: loc.wtp }
]; ];
const match = pairs.find((p) => p.actual && p.sched); const match = pairs.find((p) => p.actual && p.sched);
@@ -109,20 +115,20 @@ export function calculateDelay(loc: DelayInput): {
* @param act Actual Time (string, Date) * @param act Actual Time (string, Date)
*/ */
export function delayClassFromTimePair(sched: any, act: any): string { export function delayClassFromTimePair(sched: any, act: any): string {
if (!sched || !act) return ''; if (!sched || !act) return '';
const s = new Date(sched).getTime(); const s = new Date(sched).getTime();
const a = new Date(act).getTime(); const a = new Date(act).getTime();
if (isNaN(s) || isNaN(a)) return ''; if (isNaN(s) || isNaN(a)) return '';
const diff = a - s; const diff = a - s;
const oneMinute = 60000; const oneMinute = 60000;
// on-time if within one minute // on-time if within one minute
if (Math.abs(diff) < oneMinute) { if (Math.abs(diff) < oneMinute) {
return 'delay-rt'; return 'delay-rt';
} }
return diff > 0 ? 'delay-late' : 'delay-early'; return diff > 0 ? 'delay-late' : 'delay-early';
} }

View File

@@ -44,9 +44,9 @@
<StationAlertCard messages={data.boardData.data.m} /> <StationAlertCard messages={data.boardData.data.m} />
{/if} {/if}
{#if data.boardData.data.s?.length} {#if data.boardData.data.s?.length}
<div class="service-list-wrapper"> <div class="service-list-wrapper">
<StaffServicesTable services={data.boardData.data.s} /> <StaffServicesTable services={data.boardData.data.s} />
</div> </div>
{/if} {/if}
</section> </section>

Binary file not shown.