This commit is contained in:
2021-11-20 17:19:07 +01:00
parent 2baa2c7257
commit b6686811d9
9 changed files with 414 additions and 2 deletions

View File

@@ -8,6 +8,8 @@
import PackageList from "./routes/PackageList.svelte";
import Preparation from "./routes/Preparation.svelte";
import Trips from "./routes/Trips.svelte";
import Trip from "./routes/Trip.svelte";
import NotFound from "./routes/NotFound.svelte";
function normalize(path) {
return path.replace(/\/+$/, '') + "/";
@@ -32,6 +34,10 @@
} else if (urlParts[0] == "trips" && urlParts.length == 1) {
console.log("=> Trips");
currentRoute = Trips;
} else if (urlParts[0] == "trips" && urlParts.length == 2) {
console.log("=> Trip");
currentRoute = Trip;
data = {id: urlParts[1]};
} else if (urlParts[0] == "lists" && urlParts.length == 2) {
console.log("=> PackageList");
currentRoute = PackageList;
@@ -45,6 +51,7 @@
data = {list_id: urlParts[1], item_id: urlParts[3]};
} else {
console.log("No matching route found");
currentRoute = NotFound;
}
}

View File

@@ -0,0 +1,10 @@
<script lang="ts">
export let redirect;
</script>
<main>
<div>
404 -- Not Found
</div>
<button on:click={() => redirect("/")}>Back to home</button>
</main>

78
ui/src/routes/Trip.svelte Normal file
View File

@@ -0,0 +1,78 @@
<script lang="ts">
export let redirect;
export let data;
export const url = "/trips/"
async function getTrip() {
let response = await fetch(`http://localhost:9000/v1/trips/${data.id}`, {
method: "GET",
headers: {
"Accept": "application/json"
},
cache: "no-store",
});
let trip = await response.json();
return trip;
}
async function getTripItems() {
let response = await fetch(`http://localhost:9000/v1/trips/${data.id}/items`, {
method: "GET",
headers: {
"Accept": "application/json"
},
cache: "no-store",
});
let items = await response.json();
return items;
}
</script>
<main>
<div class="container mx-auto mt-12">
{#await getTrip()}
<p>Loading</p>
{:then trip}
<h2 class="text-3xl mt-12 mb-20 font-semibold text-center mb-5 mt-3">{trip.name}</h2>
<table>
<tr>
<td>Date</td>
<td>{trip.date}</td>
</tr>
<tr>
<td>Duration</td>
<td>{trip.parameters.days} Days</td>
</tr>
<tr>
<td>Status</td>
<td>{trip.state}</td>
</tr>
</table>
<table class="table-auto w-full">
<thead>
<tr class="font-semibold tracking-wider text-left bg-gray-100 uppercase border-b border-gray-400">
<th class="p-3">Name</th>
<th class="p-3">Status</th>
</tr>
</thead>
<tbody>
{#await getTripItems()}
<p>Loading</p>
{:then items}
{#each items as item}
<tr class="border">
<td class="p-3">{item.packageItem.name}</td>
<td class="p-3">{item.status}</td>
</tr>
{/each}
{:catch error}
{error}
{/await}
</tbody>
</table>
{/await}
</div>
</main>

View File

@@ -36,7 +36,7 @@
{:then trips}
{#each trips as trip}
<tr class="border" on:click={e => redirect(url + trip.id)}>
<td class="p-3">{trip.name}</td>
<td class="p-3" on:click={() => redirect(`/trips/${trip.id}`)}>{trip.name}</td>
<td class="p-3">{trip.date}</td>
<td class="p-3">{trip.parameters.days}</td>
{#if trip.state == "active"}