Trial date selection in timetable search
This commit is contained in:
parent
29b2054b4c
commit
8b361bb7de
@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount, onDestroy } from "svelte";
|
import { onDestroy } from "svelte";
|
||||||
export let text: string;
|
export let text: string;
|
||||||
|
|
||||||
let isVisible: boolean = false;
|
let isVisible: boolean = false;
|
||||||
@ -44,15 +44,16 @@
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
bottom: 125%;
|
top: 50%;
|
||||||
left: 50%;
|
right: 125%;
|
||||||
|
transform: translateY(-50%);
|
||||||
margin-left: -60px;
|
margin-left: -60px;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transition: opacity 0.3s;
|
transition: opacity 0.5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tooltip:hover .tooltiptext {
|
.tooltip:hover .tooltiptext {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
opacity: 1;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
export const version: string = "2024.11.2";
|
export const version: string = "2024.11.3";
|
||||||
export const versionTag: string = "";
|
export const versionTag: string = "";
|
||||||
|
@ -10,11 +10,12 @@
|
|||||||
import TrainIcons from "./trainIcons.svelte";
|
import TrainIcons from "./trainIcons.svelte";
|
||||||
|
|
||||||
export let service: OB_TrainTT_service;
|
export let service: OB_TrainTT_service;
|
||||||
|
export let date: Date;
|
||||||
|
|
||||||
let isExpanded = false;
|
let isExpanded = false;
|
||||||
|
|
||||||
async function getTrainByUID(tuid = "") {
|
async function getTrainByUID(tuid = "") {
|
||||||
const url = `${getApiUrl()}/api/v2/timetable/train/now/byTrainUid/${tuid}`;
|
const url = `${getApiUrl()}/api/v2/timetable/train/${date.toISOString().split('T')[0]}/byTrainUid/${tuid}`;
|
||||||
const options = {
|
const options = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<h1>{$page.status}: {$page?.error?.message}</h1>
|
<h1>{$page.status}: {$page?.error?.message}</h1>
|
||||||
|
|
||||||
{#if $page.status === 404}
|
{#if $page.status === 404}
|
||||||
<p>This is not the page you're looking for.</p>
|
<p>There's no light at the end of this tunnel</p>
|
||||||
<p>The page you are looking for doesn't exist, use the tabs below to find another page.</p>
|
<p>The page you are looking for doesn't exist, use the tabs below to find another page.</p>
|
||||||
{:else if $page.status === 500}
|
{:else if $page.status === 500}
|
||||||
<p>
|
<p>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import Header from "$lib/navigation/header.svelte";
|
import Header from "$lib/navigation/header.svelte";
|
||||||
import Nav from "$lib/navigation/nav.svelte";
|
import Nav from "$lib/navigation/nav.svelte";
|
||||||
import {
|
import {
|
||||||
IconCode,
|
|
||||||
IconHelp,
|
IconHelp,
|
||||||
IconInfoCircle,
|
IconInfoCircle,
|
||||||
IconLocation,
|
IconLocation,
|
||||||
|
@ -146,7 +146,10 @@
|
|||||||
<button id="reset" type="reset" on:click={reset}>Reset</button>
|
<button id="reset" type="reset" on:click={reset}>Reset</button>
|
||||||
{:else}
|
{:else}
|
||||||
<Card config={findByHeadcodeCard}>
|
<Card config={findByHeadcodeCard}>
|
||||||
Find by Headcode from the homepage
|
<span class="important">Find by Headcode from the homepage</span>
|
||||||
|
<br>
|
||||||
|
The tools below are more helpful if you've been diverted or are not starting your journey at your scheduled origin.
|
||||||
|
<br><br>
|
||||||
</Card>
|
</Card>
|
||||||
<Card config={findByStartEndCard}>
|
<Card config={findByStartEndCard}>
|
||||||
<form on:submit={findByStartEnd}>
|
<form on:submit={findByStartEnd}>
|
||||||
@ -169,6 +172,10 @@
|
|||||||
<Nav />
|
<Nav />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
.important {
|
||||||
|
font-weight: 900;
|
||||||
|
color: whitesmoke;
|
||||||
|
}
|
||||||
p {
|
p {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type { LookupCardConfig } from "$lib/cards/Card.types";
|
|
||||||
import LookupCard from "$lib/cards/LookupCard.svelte";
|
|
||||||
import NearToMeCard from "$lib/cards/NearToMeCard.svelte";
|
|
||||||
import QuickLinkCard from "$lib/cards/QuickLinkCard.svelte";
|
|
||||||
import Header from "$lib/navigation/header.svelte";
|
|
||||||
import Nav from "$lib/navigation/nav.svelte";
|
|
||||||
import TimeBar from "$lib/navigation/TimeBar.svelte";
|
|
||||||
|
|
||||||
let LookupConfig: LookupCardConfig = {
|
|
||||||
title: "Live Arr/Dep Boards",
|
|
||||||
helpText: "Enter CRS, TIPLOC or STANOX code to see live departures",
|
|
||||||
placeholder: "Enter CRS/TIPLOC",
|
|
||||||
maxLen: 7,
|
|
||||||
formAction: "/ldb/",
|
|
||||||
fieldName: "station",
|
|
||||||
};
|
|
||||||
|
|
||||||
let TimetableConfig: LookupCardConfig = {
|
|
||||||
title: "Timetable & PIS",
|
|
||||||
helpText: "Enter a headcode to search the timetable and check PIS Codes",
|
|
||||||
placeholder: "Enter headcode",
|
|
||||||
maxLen: 4,
|
|
||||||
formAction: "/train/",
|
|
||||||
fieldName: "headcode",
|
|
||||||
};
|
|
||||||
|
|
||||||
function onRefresh() {
|
|
||||||
console.log("Refresh");
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<Header title={"Test"} />
|
|
||||||
<TimeBar updatedTime={new Date()} />
|
|
||||||
<LookupCard config={LookupConfig} />
|
|
||||||
<LookupCard config={TimetableConfig} />
|
|
||||||
<NearToMeCard />
|
|
||||||
<QuickLinkCard />
|
|
||||||
<Nav />
|
|
@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Header from "$lib/navigation/header.svelte";
|
import Header from "$lib/navigation/header.svelte";
|
||||||
import Loading from "$lib/navigation/loading.svelte";
|
|
||||||
import Island from "$lib/islands/island.svelte";
|
import Island from "$lib/islands/island.svelte";
|
||||||
import Nav from "$lib/navigation/nav.svelte";
|
import Nav from "$lib/navigation/nav.svelte";
|
||||||
import { uuid } from "$lib/stores/uuid";
|
import { uuid } from "$lib/stores/uuid";
|
||||||
@ -10,14 +9,17 @@
|
|||||||
import { getApiUrl } from "$lib/scripts/upstream";
|
import { getApiUrl } from "$lib/scripts/upstream";
|
||||||
import toast from "svelte-french-toast";
|
import toast from "svelte-french-toast";
|
||||||
import TimeBar from "$lib/navigation/TimeBar.svelte";
|
import TimeBar from "$lib/navigation/TimeBar.svelte";
|
||||||
|
import { IconArrowLeft, IconArrowRight, IconCheck } from "@tabler/icons-svelte";
|
||||||
|
|
||||||
let title = "Timetable Results";
|
let title = "Timetable Results";
|
||||||
let id = "";
|
let id = "";
|
||||||
let data = [];
|
let data = [];
|
||||||
let isLoading = true;
|
|
||||||
let error = false;
|
let error = false;
|
||||||
let errMsg = "";
|
let errMsg = "";
|
||||||
|
|
||||||
|
let dateInput: Date = new Date();
|
||||||
|
$: formattedDate = dateInput.toISOString().split('T')[0];
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (id) {
|
if (id) {
|
||||||
title = id.toUpperCase();
|
title = id.toUpperCase();
|
||||||
@ -30,26 +32,39 @@
|
|||||||
return new URLSearchParams(window.location.search).get("headcode");
|
return new URLSearchParams(window.location.search).get("headcode");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function incrementDate() {
|
||||||
|
dateInput.setDate(dateInput.getDate() + 1);
|
||||||
|
dateInput = new Date(dateInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
function decrementDate() {
|
||||||
|
dateInput.setDate(dateInput.getDate() - 1);
|
||||||
|
dateInput = new Date(dateInput);
|
||||||
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
isLoading = true;
|
|
||||||
id = (await getHeadcode()) || "";
|
id = (await getHeadcode()) || "";
|
||||||
const res = await fetchData(id);
|
load();
|
||||||
if (res) {
|
|
||||||
data = res;
|
|
||||||
if (!data.length) {
|
|
||||||
error = true;
|
|
||||||
errMsg = "No services found";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isLoading = false;
|
|
||||||
|
|
||||||
toast("Registration soon required for timetable features.\n\nClick 'Register' in the menu.", {
|
toast("Registration soon required for timetable features.\n\nClick 'Register' in the menu.", {
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function load() {
|
||||||
|
toast.promise(
|
||||||
|
fetchData(id),
|
||||||
|
{
|
||||||
|
loading: 'Searching Timetable',
|
||||||
|
success: 'Done',
|
||||||
|
error: 'Error'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchData(id = "") {
|
async function fetchData(id = "") {
|
||||||
const date = "now";
|
data = [];
|
||||||
const searchType = "headcode";
|
const searchType = "headcode";
|
||||||
const options = {
|
const options = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@ -57,44 +72,56 @@
|
|||||||
uuid: $uuid,
|
uuid: $uuid,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const url = `${getApiUrl()}/api/v2/timetable/train/${date}/${searchType}/${id}`;
|
const url = `${getApiUrl()}/api/v2/timetable/train/${formattedDate}/${searchType}/${id}`;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(url, options);
|
const res = await fetch(url, options);
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
return await res.json();
|
let services = await res.json();
|
||||||
|
if (!services.length) {
|
||||||
|
error = true;
|
||||||
|
errMsg = "No services found";
|
||||||
|
return Promise.reject(new Error(errMsg));
|
||||||
|
}
|
||||||
|
data = services
|
||||||
} else if (res.status === 401) {
|
} else if (res.status === 401) {
|
||||||
error = true;
|
error = true;
|
||||||
errMsg = "You must be logged into the staff version for this feature";
|
errMsg = "You must be logged into the staff version for this feature";
|
||||||
return false;
|
return Promise.reject(new Error(errMsg));
|
||||||
} else {
|
} else {
|
||||||
error = true;
|
error = true;
|
||||||
errMsg = "Unable to connect, check your connection and try again";
|
errMsg = "Unable to connect, check your connection and try again";
|
||||||
return false;
|
return Promise.reject(new Error(errMsg));
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error = true;
|
error = true;
|
||||||
errMsg = "Connection error, try again later";
|
errMsg = "Connection error, try again later";
|
||||||
|
return Promise.reject(new Error(errMsg));
|
||||||
}
|
}
|
||||||
isLoading = false;
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Header {title} />
|
<Header {title} />
|
||||||
<TimeBar updatedTime={undefined} />
|
<TimeBar updatedTime={undefined} />
|
||||||
|
<div id="dateSelector">
|
||||||
|
<button on:click={decrementDate}><IconArrowLeft /></button>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
id="dateInput"
|
||||||
|
bind:value={formattedDate}
|
||||||
|
on:input={(e) => dateInput = new Date(e.target.value)}
|
||||||
|
/>
|
||||||
|
<button on:click={incrementDate}><IconArrowRight /></button>
|
||||||
|
<button on:click={load}><IconCheck /></button>
|
||||||
|
</div>
|
||||||
{#if error}
|
{#if error}
|
||||||
<Island>
|
<Island>
|
||||||
<p style="font-weight:600">{errMsg}</p>
|
<p style="font-weight:600">{errMsg}</p>
|
||||||
</Island>
|
</Island>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if isLoading}
|
|
||||||
<Loading />
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#each data as service}
|
{#each data as service}
|
||||||
{#if service}
|
{#if service}
|
||||||
<TrainDetail {service} />
|
<TrainDetail {service} date={dateInput} />
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
@ -106,4 +133,18 @@
|
|||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#dateInput {
|
||||||
|
height: 25px;
|
||||||
|
transform: translateY(-7px);
|
||||||
|
}
|
||||||
|
#dateSelector {
|
||||||
|
transform: translateY(3px);
|
||||||
|
transform: translateX(20px);
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user