diff --git a/web/src/lib/models/api/settings_schema.ts b/web/src/lib/models/api/settings_schema.ts index 6f1464a8..293261c8 100644 --- a/web/src/lib/models/api/settings_schema.ts +++ b/web/src/lib/models/api/settings_schema.ts @@ -13,7 +13,7 @@ const SettingsCreateSchema = z.object({ lon: z.number() }).optional().nullable(), category: z.string().optional(), - tilesets: z.array(z.object({ name: z.string(), url: z.string().url() })).optional(), + tilesets: z.array(z.object({ name: z.string(), url: z.string().url() })).optional().nullable(), terrain: z.object({ terrain: z.string().url(), hillshading: z.string().url() }).optional().nullable(), user: z.string().optional(), privacy: z.object({ diff --git a/web/src/lib/models/list.ts b/web/src/lib/models/list.ts index 5d571a8e..ce6cb41b 100644 --- a/web/src/lib/models/list.ts +++ b/web/src/lib/models/list.ts @@ -35,4 +35,35 @@ export interface ListFilter { public?: boolean; shared?: boolean; sortOrder?: "+" | "-" -} \ No newline at end of file +} + +export const enum ExpandType { + None = 0, + Trails = 1 << 0, + Waypoints = 1 << 1, + TrailCategories = 1 << 2, + ListShares = 1 << 3, + All = ~(~0 << 4), +} + +export function ExpandTypeToString(e: ExpandType) : string { + + if (e == ExpandType.None) + return ""; + + var ret = ""; + if ((e & ExpandType.Trails) === ExpandType.Trails) { + ret += "trails,"; + } + if ((e & ExpandType.Waypoints) === ExpandType.Waypoints) { + ret += "trails.waypoints,"; + } + if ((e & ExpandType.TrailCategories) === ExpandType.TrailCategories) { + ret += "trails.category,"; + } + if ((e & ExpandType.ListShares) === ExpandType.ListShares) { + ret += "list_share_via_list,"; + } + + return ret.slice(0, -1); +} \ No newline at end of file diff --git a/web/src/lib/stores/list_store.ts b/web/src/lib/stores/list_store.ts index 7d7f0536..689dbdb4 100644 --- a/web/src/lib/stores/list_store.ts +++ b/web/src/lib/stores/list_store.ts @@ -1,4 +1,4 @@ -import { List, type ListFilter } from "$lib/models/list"; +import { List, type ListFilter, ExpandType, ExpandTypeToString } from "$lib/models/list"; import type { Trail } from "$lib/models/trail"; import { pb } from "$lib/pocketbase"; import { type ListResult } from "pocketbase"; @@ -11,7 +11,9 @@ let lists: List[] = [] export const list: Writable = writable(null) export const listTrail: Writable = writable(null); -export async function lists_index(filter?: ListFilter, page: number = 1, perPage: number = 5, f: (url: RequestInfo | URL, config?: RequestInit) => Promise = fetch) { +export async function lists_index(filter?: ListFilter, page: number = 1, perPage: number = 5, + f: (url: RequestInfo | URL, config?: RequestInit) => Promise = fetch, + e: ExpandType = ExpandType.All) { const filterText = filter ? buildFilterText(filter) : "" const r = await f('/api/v1/list?' + new URLSearchParams({ @@ -19,7 +21,7 @@ export async function lists_index(filter?: ListFilter, page: number = 1, perPage perPage: perPage.toString(), page: page.toString(), filter: filterText, - expand: "trails,trails.waypoints,trails.category,list_share_via_list" + expand: ExpandTypeToString(e), }), { method: 'GET', }) @@ -92,9 +94,11 @@ export async function lists_search_filter(filter: ListFilter, page: number = 1, } -export async function lists_show(id: string, f: (url: RequestInfo | URL, config?: RequestInit) => Promise = fetch) { +export async function lists_show(id: string, f: (url: RequestInfo | URL, config?: RequestInit) => Promise = fetch + , e: ExpandType = ExpandType.All) { + const r = await f(`/api/v1/list/${id}?` + new URLSearchParams({ - expand: "trails,trails.waypoints,trails.category,list_share_via_list" + expand: ExpandTypeToString(e) }), { method: 'GET', }) diff --git a/web/src/routes/lists/+page.ts b/web/src/routes/lists/+page.ts index 60b53572..e6e2265a 100644 --- a/web/src/routes/lists/+page.ts +++ b/web/src/routes/lists/+page.ts @@ -1,4 +1,4 @@ -import type { List, ListFilter } from "$lib/models/list"; +import { ExpandType, type List, type ListFilter } from "$lib/models/list"; import { lists_index, lists_show } from "$lib/stores/list_store"; import { APIError } from "$lib/util/api_util"; import { error, type Load, type NumericRange } from "@sveltejs/kit"; @@ -17,7 +17,7 @@ export const load: Load = async ({ params, fetch, url }) => { let lists: ListResult; if (url.searchParams.get("list")) { try { - const list = await lists_show(url.searchParams.get("list") ?? "", fetch) + const list = await lists_show(url.searchParams.get("list") ?? "", fetch, ExpandType.None) lists = { items: [list], page: 1, perPage: 1, totalItems: 1, totalPages: 1 } } catch (e) { diff --git a/web/src/routes/trail/edit/[id]/+page.ts b/web/src/routes/trail/edit/[id]/+page.ts index 08795775..cd447e3c 100644 --- a/web/src/routes/trail/edit/[id]/+page.ts +++ b/web/src/routes/trail/edit/[id]/+page.ts @@ -1,3 +1,4 @@ +import { ExpandType } from "$lib/models/list"; import { Trail } from "$lib/models/trail"; import { pb } from "$lib/pocketbase"; import { categories_index } from "$lib/stores/category_store"; @@ -10,8 +11,8 @@ export const load: Load = async ({ params, fetch }) => { return error(400, "Bad Request") } const categories = await categories_index(fetch) - const lists = await lists_index({ q: "", author: pb.authStore.record?.id ?? "" }, 1, -1, fetch) - + const lists = await lists_index({ q: "", author: pb.authStore.record?.id ?? "" }, 1, -1, fetch, ExpandType.None) + let trail: Trail; if (params.id === "new") { trail = new Trail("", { category: categories[0] });