Compare commits
6 Commits
v3.0.0-dev
...
fd213d6340
| Author | SHA1 | Date | |
|---|---|---|---|
| fd213d6340 | |||
| 3eceddf20a | |||
| 1d461780ab | |||
| ec4dd5dd3b | |||
| a7c244171c | |||
| 3467f97889 |
17
package-lock.json
generated
17
package-lock.json
generated
@@ -13,7 +13,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/compat": "^2.0.2",
|
"@eslint/compat": "^2.0.2",
|
||||||
"@eslint/js": "^9.39.2",
|
"@eslint/js": "^9.39.2",
|
||||||
"@owlboard/owlboard-ts": "^3.0.0-dev.20260319T2004",
|
"@owlboard/api-schema-types": "^3.0.2-alpha1",
|
||||||
|
"@owlboard/owlboard-ts": "^3.0.0-dev.20260324T1240",
|
||||||
"@playwright/test": "^1.58.1",
|
"@playwright/test": "^1.58.1",
|
||||||
"@sveltejs/adapter-static": "^3.0.10",
|
"@sveltejs/adapter-static": "^3.0.10",
|
||||||
"@sveltejs/kit": "^2.50.2",
|
"@sveltejs/kit": "^2.50.2",
|
||||||
@@ -780,20 +781,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@owlboard/api-schema-types": {
|
"node_modules/@owlboard/api-schema-types": {
|
||||||
"version": "3.0.1-alpha3",
|
"version": "3.0.2-alpha1",
|
||||||
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fapi-schema-types/-/3.0.1-alpha3/api-schema-types-3.0.1-alpha3.tgz",
|
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fapi-schema-types/-/3.0.2-alpha1/api-schema-types-3.0.2-alpha1.tgz",
|
||||||
"integrity": "sha512-5CVm1k/C++/VrtAw4NkvclDunH+RmYLnDZZMSWTM1mm+WlEVnmD+MVnTgC/FhcsAmsNHV8swm66RCqkCuhbOnA==",
|
"integrity": "sha512-3yqWw28y2DZQmNXgAz8emCN5avX/upBXrTOXj9XLuay3gdVcdELd7BiYODBWfgtwZnSbT0fCgVXgKeTzbhHoSQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@owlboard/owlboard-ts": {
|
"node_modules/@owlboard/owlboard-ts": {
|
||||||
"version": "3.0.0-dev.20260319T2004",
|
"version": "3.0.0-dev.20260324T1240",
|
||||||
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fowlboard-ts/-/3.0.0-dev.20260319T2004/owlboard-ts-3.0.0-dev.20260319t2004.tgz",
|
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fowlboard-ts/-/3.0.0-dev.20260324T1240/owlboard-ts-3.0.0-dev.20260324t1240.tgz",
|
||||||
"integrity": "sha512-pphq1/l/8eOH4C0O7ocwBOUzt0HkCWGUlhy1itzKnQbmog7oPUEdyaxzS4Evw8onLsxZwkyqsLAyK7okYi+4XA==",
|
"integrity": "sha512-s528RtkKLZmx6jZPdj159eKOBEmDHAjKDV0dSEU8/55JMt+7cSXYEqdXC3Cqs6t39wDxsOaPe8P0Q2z6P+d0jg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@owlboard/api-schema-types": "^3.0.1-alpha3"
|
"@owlboard/api-schema-types": "^3.0.2-alpha1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@playwright/test": {
|
"node_modules/@playwright/test": {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/compat": "^2.0.2",
|
"@eslint/compat": "^2.0.2",
|
||||||
"@eslint/js": "^9.39.2",
|
"@eslint/js": "^9.39.2",
|
||||||
"@owlboard/owlboard-ts": "^3.0.0-dev.20260319T2004",
|
"@owlboard/owlboard-ts": "^3.0.0-dev.20260325T1023",
|
||||||
"@playwright/test": "^1.58.1",
|
"@playwright/test": "^1.58.1",
|
||||||
"@sveltejs/adapter-static": "^3.0.10",
|
"@sveltejs/adapter-static": "^3.0.10",
|
||||||
"@sveltejs/kit": "^2.50.2",
|
"@sveltejs/kit": "^2.50.2",
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
import { LOCATIONS } from '$lib/locations-object.svelte.ts';
|
import { LOCATIONS } from '$lib/locations-object.svelte';
|
||||||
|
import type { ApiLocationFilter } from '@owlboard/api-schema-types';
|
||||||
|
|
||||||
let { value = $bindable() } = $props();
|
let { value = $bindable() } = $props();
|
||||||
|
|
||||||
@@ -26,13 +27,16 @@
|
|||||||
return LOCATIONS.data
|
return LOCATIONS.data
|
||||||
.filter((r) => tokens.every((t) => r.s.includes(t)))
|
.filter((r) => tokens.every((t) => r.s.includes(t)))
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
// Check if query matches CRS
|
|
||||||
const aIsCrs = a.c?.toLowerCase() === lowerQuery;
|
|
||||||
const bIsCrs = b.c?.toLowerCase() === lowerQuery;
|
|
||||||
|
|
||||||
// Sort matching CRS first
|
// Priority One - Exact CRS Match
|
||||||
if (aIsCrs && !bIsCrs) return -1;
|
const aExactCrs = a.c?.toLowerCase() === lowerQuery;
|
||||||
if (!aIsCrs && bIsCrs) return 1;
|
const bExactCrs = b.c?.toLowerCase() === lowerQuery;
|
||||||
|
if (aExactCrs && !bExactCrs) return -1;
|
||||||
|
if (!aExactCrs && bExactCrs) return 1;
|
||||||
|
|
||||||
|
// Priority Two - 'Stations' with CRS
|
||||||
|
if (!!a.c && !b.c) return -1;
|
||||||
|
if (!a.c & !! b.c) return 1;
|
||||||
|
|
||||||
// Alphabetical Sort
|
// Alphabetical Sort
|
||||||
return a.n.localeCompare(b.n);
|
return a.n.localeCompare(b.n);
|
||||||
@@ -59,7 +63,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function choose(loc: LocationRecord) {
|
function choose(loc: ApiLocationFilter.LocationFilterObject) {
|
||||||
showResults = false;
|
showResults = false;
|
||||||
selectedIndex = -1;
|
selectedIndex = -1;
|
||||||
value = '';
|
value = '';
|
||||||
@@ -195,6 +199,7 @@
|
|||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
text-transform: capitalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tiploc {
|
.tiploc {
|
||||||
|
|||||||
53
src/lib/components/ui/TocStyle.svelte
Normal file
53
src/lib/components/ui/TocStyle.svelte
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
interface Props {
|
||||||
|
toc: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
toc
|
||||||
|
}: Props = $props();
|
||||||
|
|
||||||
|
let code = $derived(toc.toUpperCase());
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="toc-container {code}">
|
||||||
|
{code}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.toc-container {
|
||||||
|
border-radius: 10px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 2px 8px;
|
||||||
|
font-weight: 800;
|
||||||
|
background-color: #333;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.GW { /* Great Western Railway */
|
||||||
|
background: #004225;
|
||||||
|
color: #E2E2E2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.GR { /* LNER */
|
||||||
|
background-color: #C00000;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.VT { /* Avanti West Coast */
|
||||||
|
background-color: #004354;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.SW { /* South Western Railway */
|
||||||
|
background-color: #2A3389;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.XC { /* CrossCountry */
|
||||||
|
background-color: #660000;
|
||||||
|
color: #E4D5B1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,27 +1,23 @@
|
|||||||
interface LocationRecord {
|
import { OwlClient } from "./owlClient";
|
||||||
n: string; // name
|
import type { ApiLocationFilter } from '@owlboard/owlboard-ts'
|
||||||
t: string; // tiploc
|
|
||||||
c?: string; // crs
|
|
||||||
s: string; // search string
|
|
||||||
}
|
|
||||||
|
|
||||||
class LocationStore {
|
class LocationStore {
|
||||||
data = $state<LocationRecord[]>([]);
|
data = $state<ApiLocationFilter.LocationFilterObject[]>([]);
|
||||||
loaded = $state(false);
|
loaded = $state(false);
|
||||||
|
|
||||||
async init(fetcher = fetch) {
|
async init() {
|
||||||
if (this.loaded) return;
|
if (this.loaded) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetcher('/api/tiplocs');
|
const fetch = await OwlClient.locationFilter.getLocationFilterData()
|
||||||
this.data = await res.json();
|
this.data = fetch.data;
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load locations', err);
|
console.error('Failed to load locations', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
find(id: string | null): LocationRecord | undefined {
|
find(id: string | null): ApiLocationFilter.LocationFilterObject | undefined {
|
||||||
if (!id) return undefined;
|
if (!id) return undefined;
|
||||||
|
|
||||||
const query = id.toUpperCase().trim();
|
const query = id.toUpperCase().trim();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { slide, fade } from 'svelte/transition';
|
import { slide, fade } from 'svelte/transition';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
import { LOCATIONS } from '$lib/locations-object.svelte.ts';
|
import { LOCATIONS } from '$lib/locations-object.svelte';
|
||||||
|
|
||||||
import '$lib/global.css';
|
import '$lib/global.css';
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
import { IconHome, IconDialpad, IconSettings, IconHelp, IconDots } from '@tabler/icons-svelte';
|
import { IconHome, IconDialpad, IconSettings, IconHelp, IconDots } from '@tabler/icons-svelte';
|
||||||
|
|
||||||
onMount(() => LOCATIONS.init(fetch));
|
onMount(() => LOCATIONS.init());
|
||||||
|
|
||||||
let { children } = $props();
|
let { children } = $props();
|
||||||
|
|
||||||
@@ -167,6 +167,7 @@
|
|||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
padding-bottom: 2px;
|
padding-bottom: 2px;
|
||||||
color: var(--color-title);
|
color: var(--color-title);
|
||||||
|
text-transform: capitalize;
|
||||||
}
|
}
|
||||||
header,
|
header,
|
||||||
nav {
|
nav {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export const load: PageLoad = async ({ url }) => {
|
|||||||
const locId = url.searchParams.get('loc');
|
const locId = url.searchParams.get('loc');
|
||||||
|
|
||||||
if (!LOCATIONS.loaded) {
|
if (!LOCATIONS.loaded) {
|
||||||
await LOCATIONS.init(fetch);
|
await LOCATIONS.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
let title: string = '';
|
let title: string = '';
|
||||||
|
|||||||
@@ -2,36 +2,53 @@
|
|||||||
import PisStartEndCard from '$lib/components/ui/cards/pis/PisStartEndCard.svelte';
|
import PisStartEndCard from '$lib/components/ui/cards/pis/PisStartEndCard.svelte';
|
||||||
import PisCode from '$lib/components/ui/cards/pis/PisCode.svelte';
|
import PisCode from '$lib/components/ui/cards/pis/PisCode.svelte';
|
||||||
import Button from '$lib/components/ui/Button.svelte';
|
import Button from '$lib/components/ui/Button.svelte';
|
||||||
import type { PisObjects } from '@owlboard/api-schema-types';
|
import type { ApiPisObject } from '@owlboard/owlboard-ts';
|
||||||
import { OwlClient, ApiError, ValidationError } from '$lib/owlClient';
|
import { OwlClient, ApiError, ValidationError } from '$lib/owlClient';
|
||||||
|
import TocStyle from '$lib/components/ui/TocStyle.svelte';
|
||||||
|
|
||||||
let results = $state<PisObjects[]>([]);
|
let results = $state<ApiPisObject.PisObjects[]>([]);
|
||||||
let resultsLoaded = $state<boolean>(false);
|
let resultsLoaded = $state<boolean>(false);
|
||||||
let errorState = $state<{status: number, message: message} | null>(null);
|
let errorState = $state<{status: number, message: string} | null>(null);
|
||||||
|
|
||||||
async function handleStartEndSearch(start: string, end: string): Promise<void> {
|
async function handleStartEndSearch(start: string, end: string): Promise<void> {
|
||||||
console.log(`PIS Search: ${start}-${end}`);
|
console.log(`PIS Search: ${start}-${end}`);
|
||||||
errorState = null;
|
errorState = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
results = await OwlClient.pis.getByStartEndCrs(start, end);
|
const response = await OwlClient.pis.getByStartEndCrs(start, end);
|
||||||
|
results = response.data || [];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ValidationError) {
|
if (e instanceof ValidationError) {
|
||||||
errorState = { status: 400, message: e.message };
|
errorState = { status: 400, message: e.message };
|
||||||
} else if (e instanceof ApiError) {
|
} else if (e instanceof ApiError) {
|
||||||
errorState = { status: 500, message: e.message };
|
console.log(e)
|
||||||
|
errorState = { status: 20, message: e.message };
|
||||||
} else {
|
} else {
|
||||||
errorState = { status: 0, message: `Unknown Error: ${e.message}` };
|
errorState = { status: 0, message: `Unknown Error: ${e.message}` };
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
resultsLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
resultsLoaded = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCodeSearch(code: string) {
|
async function handleCodeSearch(code: string) {
|
||||||
console.log(`PIS Search: ${code}`);
|
console.log(`PIS Search: ${code}`);
|
||||||
// Fetch API Results Here
|
errorState = null;
|
||||||
resultsLoaded = true;
|
try {
|
||||||
|
const response = await OwlClient.pis.getByCode(code);
|
||||||
|
results = response.data || []
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof ValidationError) {
|
||||||
|
errorState = { status: 400, message: e.message };
|
||||||
|
} else if (e instanceof ApiError) {
|
||||||
|
console.log(e)
|
||||||
|
errorState = { status: 20, message: e.message };
|
||||||
|
} else {
|
||||||
|
errorState = { status: 0, message: `Unknown Error: ${e.message}` };
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
resultsLoaded = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearResults() {
|
function clearResults() {
|
||||||
@@ -49,16 +66,33 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<div class="result-container">
|
<div class="result-container">
|
||||||
{#if errorState}
|
{#if errorState}
|
||||||
<span class="errCode">{errorState.status}</span>
|
<span class="errCode">Error: {errorState.status}</span>
|
||||||
<span class="errMsg">{errorState.message}</span>
|
<span class="errMsg">{errorState.message}</span>
|
||||||
{:else}
|
{:else}
|
||||||
{#if !results.length}
|
{#if results.length}
|
||||||
<p class="no-results">No results found</p>
|
<h2 class="result-title">{results.length} Result{#if results.length > 1}s{/if} found</h2>
|
||||||
{:else}
|
<table class="result-table">
|
||||||
<p class="no-results">Results Loaded - Display logic not present</p>
|
<thead>
|
||||||
{/if}{/if}
|
<tr>
|
||||||
|
<th style="width:16%">TOC</th>
|
||||||
|
<th style="width:14%">Code</th>
|
||||||
|
<th style="width:70%">Locations</th>
|
||||||
|
</tr></thead>
|
||||||
|
{#each results as result}
|
||||||
|
<tbody><tr>
|
||||||
|
<td><TocStyle toc={result.toc || ""} /></td>
|
||||||
|
<td>{result.code}</td>
|
||||||
|
<td class="locations-row">{result.crsStops?.join(' ') || ''}</td>
|
||||||
|
</tr></tbody>
|
||||||
|
{/each}
|
||||||
|
</table>
|
||||||
|
{:else}
|
||||||
|
<p class="no-results">No matching results</p>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
<div class="reset-button-container">
|
||||||
<Button onclick={clearResults}>Reset</Button>
|
<Button onclick={clearResults}>Reset</Button>
|
||||||
</div>
|
</div> </div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -82,11 +116,43 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
background: var(--color-accent);
|
background: var(--color-accent);
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
padding: 0 0 20px 0;
|
padding: 20px 0 20px 0;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
margin-top: 25px;
|
margin-top: 25px;
|
||||||
|
margin-bottom: 25px;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
max-width: 1000px;
|
max-width: 500px;
|
||||||
box-shadow: var(--shadow-std);
|
box-shadow: var(--shadow-std);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.result-title {
|
||||||
|
color: var(--color-brand);
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-table {
|
||||||
|
width: 90%;
|
||||||
|
max-width: 350px;
|
||||||
|
margin: auto;
|
||||||
|
text-align: center;
|
||||||
|
table-layout: fixed;
|
||||||
|
border-collapse: separate;
|
||||||
|
border-spacing: 0 20px;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.locations-row {
|
||||||
|
font-family:'Courier New', Courier, monospace;
|
||||||
|
text-align: left;
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.errCode {
|
||||||
|
color: rgb(255, 54, 54);
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reset-button-container {
|
||||||
|
padding: 20px 0 3px 0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user