From c8aa5e9917e05683d798e6e42bab4a0bdca6f5a4 Mon Sep 17 00:00:00 2001 From: Sami Abuzakuk Date: Sun, 12 Oct 2025 10:22:20 +0200 Subject: [PATCH] Add frontend support for settings --- frontend/src/lib/api.ts | 46 ++++++++++ frontend/src/routes/+layout.svelte | 3 + frontend/src/routes/scripts/[id]/+page.svelte | 17 +++- frontend/src/routes/settings/+page.svelte | 83 +++++++++++++++++++ 4 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 frontend/src/routes/settings/+page.svelte diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 236b0d8..f37beb5 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1,5 +1,15 @@ export const API_URL = 'http://127.0.0.1:8000'; +/** + * Type definitions for Settings + */ +export interface Settings { + id: number; + requirements: string; + environment: string; + user: string; +} + export async function checkHealth(): Promise<'healthy' | 'unhealthy'> { try { const response = await fetch(`${API_URL}/health`); @@ -58,6 +68,42 @@ export async function addScript( return response.json(); } +// Fetch all settings +export async function fetchSettings(): Promise { + const response = await fetch(`${API_URL}/settings`); + if (!response.ok) { + throw new Error('Failed to fetch settings ' + response.statusText); + } + return response.json(); +} + +// Fetch a single setting by ID +export async function fetchSettingById(id: number): Promise { + const response = await fetch(`${API_URL}/settings/${id}`); + if (!response.ok) { + throw new Error('Failed to fetch setting'); + } + return response.json(); +} + +// Update an existing setting +export async function updateSetting( + id: number, + updatedSetting: Partial +): Promise { + const response = await fetch(`${API_URL}/settings/${id}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(updatedSetting) + }); + if (!response.ok) { + throw new Error('Failed to update setting'); + } + return response.json(); +} + // Fetch a single script by ID export async function fetchScriptById(id: number): Promise + +
+

Settings

+ + {#if $isLoading} +

Loading...

+ {:else if $error} +

{$error}

+ {:else} +
+ {#each $settings as setting (setting.id)} +
+ +
+ +
+ + +
+ +
+ + + + + +
+ {/each} +
+ {/if} +
+ +