Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
feat: add UI to create and edit custom templates (#2351)
Mohamed M. Hagag79e706e4aa4d
diff --git a/.gitignore b/.gitignoreindex a7a3506de..85af2db75 100644--- a/.gitignore+++ b/.gitignore@@ -12,6 +12,10 @@ builddata/dist/arcane+arcane-*++# Claude+CLAUDE.md# OS.DS_Storediff --git a/frontend/messages/en.json b/frontend/messages/en.jsonindex 82541d174..3f603f4a6 100644--- a/frontend/messages/en.json+++ b/frontend/messages/en.json@@ -1592,7 +1592,16 @@"templates_load_failed": "Failed to load template content","templates_download_failed": "Failed to download template","templates_create_template": "Create Template",+ "templates_edit_template": "Edit Template","templates_delete_template": "Delete Template",+ "templates_template_name_label": "Template Name",+ "templates_template_name_placeholder": "e.g. My Nginx Stack",+ "templates_template_name_required": "Template name is required",+ "templates_template_description_label": "Description",+ "templates_template_description_placeholder": "Briefly describe this template",+ "templates_content_required": "Compose content is required",+ "templates_save_template_failed": "Failed to save template",+ "templates_create_template_failed": "Failed to create template","templates_browse_templates": "Browse Templates","templates_manage_registries": "Manage Registries","templates_edit_default": "Edit Default",@@ -2030,6 +2039,8 @@"registries_delete_failed": "Failed to delete registry {url}","templates_loaded_success": "Template \"{name}\" loaded successfully","templates_downloaded_success": "Template \"{name}\" downloaded successfully",+ "templates_save_template_success": "Template \"{name}\" saved successfully",+ "templates_create_template_success": "Template \"{name}\" created successfully","templates_registry_removed_success": "Template registry removed successfully","shell_select_placeholder": "Select shell","users_delete_selected_title": "Delete {count} User(s)",diff --git a/frontend/src/lib/services/template-service.ts b/frontend/src/lib/services/template-service.tsindex 997ea8a6b..f7d33c153 100644--- a/frontend/src/lib/services/template-service.ts+++ b/frontend/src/lib/services/template-service.ts@@ -87,6 +87,24 @@ export default class TemplateService extends BaseAPIService {await this.api.delete(`/templates/registries/${id}`);}+ async updateTemplate(+ id: string,+ template: {+ name: string;+ description?: string;+ content: string;+ envContent?: string;+ }+ ): Promise<Template> {+ const response = await this.api.put(`/templates/${encodeURIComponent(id)}`, {+ name: template.name,+ description: template.description || '',+ content: template.content,+ envContent: template.envContent || ''+ });+ return response.data?.data;+ }+async deleteTemplate(id: string): Promise<void> {await this.api.delete(`/templates/${encodeURIComponent(id)}`);}diff --git a/frontend/src/routes/(app)/customize/templates/+page.svelte b/frontend/src/routes/(app)/customize/templates/+page.svelteindex f96d61af5..150e34b71 100644--- a/frontend/src/routes/(app)/customize/templates/+page.svelte+++ b/frontend/src/routes/(app)/customize/templates/+page.svelte@@ -130,6 +130,12 @@}const actionButtons: ActionButton[] = [+ {+ id: 'create',+ action: 'create',+ label: m.templates_create_template(),+ onclick: () => goto('/customize/templates/create')+ },{id: 'default',action: 'edit',diff --git a/frontend/src/routes/(app)/customize/templates/[id]/+page.svelte b/frontend/src/routes/(app)/customize/templates/[id]/+page.svelteindex bc314e0ef..66b272a2d 100644--- a/frontend/src/routes/(app)/customize/templates/[id]/+page.svelte+++ b/frontend/src/routes/(app)/customize/templates/[id]/+page.svelte@@ -2,8 +2,8 @@import { ArcaneButton } from '$lib/components/arcane-button/index.js';import * as Card from '$lib/components/ui/card';import { Badge } from '$lib/components/ui/badge';- import { Spinner } from '$lib/components/ui/spinner';import CodeEditor from '$lib/components/code-editor/editor.svelte';+ import FormInput from '$lib/components/form/form-input.svelte';import IconImage from '$lib/components/icon-image.svelte';import { goto, invalidateAll } from '$app/navigation';import { m } from '$lib/paraglide/messages.js';@@ -11,11 +11,14 @@import { openConfirmDialog } from '$lib/components/confirm-dialog';import { untrack } from 'svelte';import { toast } from 'svelte-sonner';+ import { createForm } from '$lib/utils/form.utils';+ import { tryCatch } from '$lib/utils/try-catch';+ import { handleApiResultWithCallbacks } from '$lib/utils/api.util';+ import { z } from 'zod/v4';import {TrashIcon,ArrowLeftIcon,ProjectsIcon,- FileTextIcon,CodeIcon,TemplateIcon,DownloadIcon,@@ -23,31 +26,110 @@ContainersIcon,BoxIcon,VariableIcon,- MoveToFolderIcon+ FileTextIcon} from '$lib/icons';let { data } = $props();let template = $derived(data.templateData.template);- let compose = $state(untrack(() => data.templateData.content));- let env = $state(untrack(() => data.templateData.envContent));let services = $derived(data.templateData.services);let envVars = $derived(data.templateData.envVariables);- let isDownloading = $state(false);+ // Edit state (custom templates only)+ let saving = $state(false);let isDeleting = $state(false);+ let isDownloading = $state(false);+ let composeHasErrors = $state(false);+ let envHasErrors = $state(false);+ let composeValidationReady = $state(false);+ let envValidationReady = $state(false);++ const globalVariableMap = $derived.by(() =>+ Object.fromEntries((data.globalVariables ?? []).map((item) => [item.key, item.value]))+ );++ // Form schema for custom template editing+ const formSchema = z.object({+ name: z.string().min(1, m.templates_template_name_required()),+ description: z.string().optional().default(''),+ composeContent: z.string().min(1, m.templates_content_required()),+ envContent: z.string().optional().default('')+ });++ let originalName = $state(untrack(() => template.name));+ let originalDescription = $state(untrack(() => template.description ?? ''));+ let originalCompose = $state(untrack(() => data.templateData.content));+ let originalEnv = $state(untrack(() => data.templateData.envContent));++ let formData = $derived({+ name: originalName,+ description: originalDescription,+ composeContent: originalCompose,+ envContent: originalEnv+ });++ let { inputs, ...form } = $derived(createForm<typeof formSchema>(formSchema, formData));++ const hasChanges = $derived(+ $inputs.name.value !== originalName ||+ $inputs.description.value !== originalDescription ||+ $inputs.composeContent.value !== originalCompose ||+ $inputs.envContent.value !== originalEnv+ );++ const canSave = $derived(hasChanges && composeValidationReady && envValidationReady && !composeHasErrors && !envHasErrors);+ async function handleSave() {+ if (!composeValidationReady || !envValidationReady || composeHasErrors || envHasErrors) {+ toast.error(m.templates_validation_error());+ return;+ }+ const validated = form.validate();+ if (!validated) {+ toast.error(m.templates_validation_error());+ return;+ }++ handleApiResultWithCallbacks({+ result: await tryCatch(+ templateService.updateTemplate(template.id, {+ name: validated.name,+ description: validated.description,+ content: validated.composeContent,+ envContent: validated.envContent+ })+ ),+ message: m.templates_save_template_failed(),+ setLoadingState: (value) => (saving = value),+ onSuccess: async () => {+ toast.success(m.templates_save_template_success({ name: validated.name }));+ originalName = validated.name;+ originalDescription = validated.description ?? '';+ originalCompose = validated.composeContent;+ originalEnv = validated.envContent ?? '';+ await invalidateAll();+ }+ });+ }++ function handleReset() {+ $inputs.name.value = originalName;+ $inputs.description.value = originalDescription;+ $inputs.composeContent.value = originalCompose;+ $inputs.envContent.value = originalEnv;+ toast.info(m.templates_reset_success());+ }++ // Read-only view helpers (remote templates)const localVersionOfRemote = $derived(() => {if (!template.isRemote || !template.metadata?.remoteUrl) return null;return data.allTemplates.find((t) => !t.isRemote && t.metadata?.remoteUrl === template.metadata?.remoteUrl);});- const canDelete = $derived(!template.isRemote);const canDownload = $derived(template.isRemote && !localVersionOfRemote());async function handleDownload() {if (isDownloading || !canDownload) return;-isDownloading = true;try {const downloadedTemplate = await templateService.download(template.id);@@ -66,8 +148,7 @@}async function handleDelete() {- if (isDeleting || !canDelete) return;-+ if (isDeleting) return;openConfirmDialog({title: m.common_delete_title({ resource: m.resource_template() }),message: m.common_delete_confirm({ resource: `${m.resource_template()} "${template.name}"` }),@@ -95,218 +176,335 @@}</script>-<div class="mx-auto flex h-full min-h-0 w-full max-w-full flex-col gap-6 p-2 sm:p-6">+<div class="mx-auto flex h-full min-h-0 w-full max-w-full flex-col gap-6 overflow-hidden p-2 pb-10 sm:p-6 sm:pb-10">+ <!-- Header --><div class="flex-shrink-0 space-y-3 sm:space-y-4"><ArcaneButton action="base" tone="ghost" onclick={() => goto('/customize/templates')} class="w-fit gap-2"><ArrowLeftIcon class="size-4" /><span>{m.common_back_to({ resource: m.templates_title() })}</span></ArcaneButton>- <div class="flex min-w-0 items-start gap-3">- <IconImage- src={template.metadata?.iconUrl}- alt={template.name}- fallback={template.isRemote ? GlobeIcon : TemplateIcon}- class="size-6"- containerClass="size-9 bg-transparent ring-0"- />- <div class="min-w-0 flex-1">- <h1 class="text-xl font-bold break-words sm:text-2xl">{template.name}</h1>- {#if template.description}- <p class="text-muted-foreground mt-1.5 text-sm break-words sm:text-base">{template.description}</p>- {/if}+ {#if !template.isRemote}+ <!-- Editable header for custom templates -->+ <div class="flex flex-col justify-between gap-4 sm:flex-row sm:items-start">+ <div class="min-w-0 flex-1 space-y-3">+ <FormInput+ input={$inputs.name}+ label={m.templates_template_name_label()}+ placeholder={m.templates_template_name_placeholder()}+ disabled={saving}+ />+ <FormInput+ input={$inputs.description}+ label={m.templates_template_description_label()}+ placeholder={m.templates_template_description_placeholder()}+ disabled={saving}+ />+ </div>+ <div class="flex flex-col gap-2 sm:flex-row sm:items-start">+ <ArcaneButton+ action="create"+ onclick={() => goto(`/projects/new?templateId=${template.id}`)}+ customLabel={m.compose_create_project()}+ class="w-full gap-2 sm:w-auto"+ />+ <ArcaneButton action="cancel" onclick={handleReset} disabled={!hasChanges || saving}>+ {m.common_reset()}+ </ArcaneButton>+ {#if composeValidationReady && envValidationReady && !composeHasErrors && !envHasErrors}+ <ArcaneButton+ action="save"+ onclick={handleSave}+ disabled={!canSave}+ loading={saving}+ loadingLabel={m.common_action_saving()}+ />+ {/if}+ <ArcaneButton+ action="remove"+ onclick={handleDelete}+ disabled={isDeleting}+ loading={isDeleting}+ loadingLabel={m.common_action_deleting()}+ customLabel={m.templates_delete_template()}+ class="w-full gap-2 sm:w-auto"+ />+ </div></div>- </div>- <div class="flex flex-wrap items-center gap-2">- {#if template.isRemote}- <Badge variant="secondary" class="gap-1">- <GlobeIcon class="size-3" />- {m.templates_remote()}- </Badge>- {:else}+ <div class="flex flex-wrap items-center gap-2"><Badge variant="secondary" class="gap-1"><TemplateIcon class="size-3" />{m.templates_local()}</Badge>- {/if}- {#if template.metadata?.tags && template.metadata.tags.length > 0}- {#each template.metadata.tags as tag}- <Badge variant="outline">{tag}</Badge>- {/each}- {/if}- </div>- <div class="flex flex-col gap-2 sm:flex-row">- <ArcaneButton- action="create"- onclick={() => goto(`/projects/new?templateId=${template.id}`)}- customLabel={m.compose_create_project()}- class="w-full gap-2 sm:w-auto"- />+ </div>+ {:else}+ <!-- Read-only header for remote templates -->+ <div class="flex min-w-0 items-start gap-3">+ <IconImage+ src={template.metadata?.iconUrl}+ alt={template.name}+ fallback={GlobeIcon}+ class="size-6"+ containerClass="size-9 bg-transparent ring-0"+ />+ <div class="min-w-0 flex-1">+ <h1 class="text-xl font-bold break-words sm:text-2xl">{template.name}</h1>+ {#if template.description}+ <p class="text-muted-foreground mt-1.5 text-sm break-words sm:text-base">{template.description}</p>+ {/if}+ </div>+ </div>- {#if canDownload}- <ArcaneButton- action="base"- onclick={handleDownload}- disabled={isDownloading}- loading={isDownloading}- loadingLabel={m.common_action_downloading()}- class="w-full gap-2 sm:w-auto"- >- <DownloadIcon class="size-4" />- {m.templates_download()}- </ArcaneButton>- {:else if template.isRemote && localVersionOfRemote()}- <ArcaneButton- action="base"- onclick={() => goto(`/customize/templates/${localVersionOfRemote()?.id}`)}- class="w-full gap-2 sm:w-auto"- >- <ProjectsIcon class="size-4" />- {m.templates_view_local_version()}- </ArcaneButton>- {/if}+ <div class="flex flex-wrap items-center gap-2">+ <Badge variant="secondary" class="gap-1">+ <GlobeIcon class="size-3" />+ {m.templates_remote()}+ </Badge>+ {#if template.metadata?.tags && template.metadata.tags.length > 0}+ {#each template.metadata.tags as tag}+ <Badge variant="outline">{tag}</Badge>+ {/each}+ {/if}+ </div>- {#if canDelete}+ <div class="flex flex-col gap-2 sm:flex-row"><ArcaneButton- action="remove"- onclick={handleDelete}- disabled={isDeleting}- loading={isDeleting}- loadingLabel={m.common_action_deleting()}- customLabel={m.templates_delete_template()}+ action="create"+ onclick={() => goto(`/projects/new?templateId=${template.id}`)}+ customLabel={m.compose_create_project()}class="w-full gap-2 sm:w-auto"/>- {/if}- </div>+ {#if canDownload}+ <ArcaneButton+ action="base"+ onclick={handleDownload}+ disabled={isDownloading}+ loading={isDownloading}+ loadingLabel={m.common_action_downloading()}+ class="w-full gap-2 sm:w-auto"+ >+ <DownloadIcon class="size-4" />+ {m.templates_download()}+ </ArcaneButton>+ {:else if template.isRemote && localVersionOfRemote()}+ <ArcaneButton+ action="base"+ onclick={() => goto(`/customize/templates/${localVersionOfRemote()?.id}`)}+ class="w-full gap-2 sm:w-auto"+ >+ <ProjectsIcon class="size-4" />+ {m.templates_view_local_version()}+ </ArcaneButton>+ {/if}+ </div>+ {/if}</div>- <div class="grid flex-shrink-0 gap-4 sm:grid-cols-2">- <Card.Root variant="subtle">- <Card.Content class="flex items-center gap-4 p-4">- <div class="flex size-12 shrink-0 items-center justify-center rounded-lg bg-blue-500/10">- <ContainersIcon class="size-6 text-blue-500" />- </div>- <div class="min-w-0 flex-1">- <div class="text-muted-foreground text-xs font-semibold tracking-wide uppercase">{m.compose_services()}</div>- <div class="mt-1">- <div class="text-2xl font-bold">{services?.length ?? 0}</div>- </div>- </div>- </Card.Content>- </Card.Root>-- <Card.Root variant="subtle">- <Card.Content class="flex items-center gap-4 p-4">- <div class="flex size-12 shrink-0 items-center justify-center rounded-lg bg-purple-500/10">- <VariableIcon class="size-6 text-purple-500" />- </div>- <div class="min-w-0 flex-1">- <div class="text-muted-foreground text-xs font-semibold tracking-wide uppercase">- {m.common_environment_variables()}+ {#if !template.isRemote}+ <!-- Edit layout: compose editor + env editor side by side -->+ <div class="flex min-h-0 flex-1 flex-col gap-6 lg:grid lg:grid-cols-5 lg:grid-rows-1 lg:items-stretch">+ <Card.Root class="flex min-h-0 min-w-0 flex-1 flex-col lg:col-span-3">+ <Card.Header icon={CodeIcon} class="shrink-0">+ <div class="flex flex-col space-y-1.5">+ <Card.Title>+ <h2>{m.templates_compose_template_label()}</h2>+ </Card.Title>+ <Card.Description>{m.templates_service_definitions()}</Card.Description></div>- <div class="mt-1 flex flex-wrap items-baseline gap-2">- <div class="text-2xl font-bold">{envVars?.length ?? 0}</div>- {#if envVars?.length}- <div class="text-muted-foreground text-sm">{m.templates_configurable_settings()}</div>- {/if}+ </Card.Header>+ <Card.Content class="flex min-h-0 min-w-0 flex-1 flex-col p-0">+ <div class="min-h-0 min-w-0 flex-1 rounded-b-xl">+ <CodeEditor+ bind:value={$inputs.composeContent.value}+ language="yaml"+ readOnly={saving}+ fontSize="13px"+ bind:hasErrors={composeHasErrors}+ bind:validationReady={composeValidationReady}+ fileId="templates:custom:{template.id}:compose"+ originalValue={originalCompose}+ enableDiff={true}+ editorContext={{+ envContent: $inputs.envContent.value,+ composeContents: [$inputs.composeContent.value],+ globalVariables: globalVariableMap+ }}+ /></div>- </div>- </Card.Content>- </Card.Root>- </div>+ </Card.Content>+ {#if $inputs.composeContent.error}+ <Card.Footer class="pt-0">+ <p class="text-destructive text-xs font-medium">{$inputs.composeContent.error}</p>+ </Card.Footer>+ {/if}+ </Card.Root>- <div class="min-h-0 flex-1">- <div class="grid h-full min-h-0 gap-6 lg:grid-cols-2 xl:grid-cols-3">- <Card.Root class="flex h-full min-h-0 min-w-0 flex-col lg:col-span-1 xl:col-span-2">- <Card.Header icon={CodeIcon} class="flex-shrink-0">+ <Card.Root class="flex min-h-0 min-w-0 flex-1 flex-col lg:col-span-2">+ <Card.Header icon={VariableIcon} class="shrink-0"><div class="flex flex-col space-y-1.5"><Card.Title>- <h2>{m.common_docker_compose()}</h2>+ <h2>{m.templates_env_template_label()}</h2></Card.Title>- <Card.Description>{m.templates_service_definitions()}</Card.Description>+ <Card.Description>{m.templates_default_config_values()}</Card.Description></div></Card.Header>- <Card.Content class="relative z-0 flex min-h-0 min-w-0 flex-1 flex-col overflow-visible p-0">- <div class="absolute inset-0 min-h-0 w-full min-w-0 rounded-t-none rounded-b-xl">- <CodeEditor bind:value={compose} language="yaml" readOnly={true} fontSize="13px" />+ <Card.Content class="flex min-h-0 min-w-0 flex-1 flex-col p-0">+ <div class="min-h-0 min-w-0 flex-1 rounded-b-xl">+ <CodeEditor+ bind:value={$inputs.envContent.value}+ language="env"+ readOnly={saving}+ fontSize="13px"+ bind:hasErrors={envHasErrors}+ bind:validationReady={envValidationReady}+ fileId="templates:custom:{template.id}:env"+ originalValue={originalEnv}+ enableDiff={true}+ editorContext={{+ envContent: $inputs.envContent.value,+ composeContents: [$inputs.composeContent.value],+ globalVariables: globalVariableMap+ }}+ />+ </div>+ </Card.Content>+ {#if $inputs.envContent.error}+ <Card.Footer class="pt-0">+ <p class="text-destructive text-xs font-medium">{$inputs.envContent.error}</p>+ </Card.Footer>+ {/if}+ </Card.Root>+ </div>+ {:else}+ <!-- Read-only view for remote templates -->+ <div class="grid flex-shrink-0 gap-4 sm:grid-cols-2">+ <Card.Root variant="subtle">+ <Card.Content class="flex items-center gap-4 p-4">+ <div class="flex size-12 shrink-0 items-center justify-center rounded-lg bg-blue-500/10">+ <ContainersIcon class="size-6 text-blue-500" />+ </div>+ <div class="min-w-0 flex-1">+ <div class="text-muted-foreground text-xs font-semibold tracking-wide uppercase">{m.compose_services()}</div>+ <div class="mt-1">+ <div class="text-2xl font-bold">{services?.length ?? 0}</div>+ </div></div></Card.Content></Card.Root>- <div class="flex h-full min-h-0 min-w-0 flex-1 flex-col gap-6 lg:col-span-1">- {#if services?.length}- <Card.Root class="min-w-0 flex-shrink-0">- <Card.Header icon={ContainersIcon}>- <div class="flex flex-col space-y-1.5">- <Card.Title>- <h2>{m.services()}</h2>- </Card.Title>- <Card.Description>{m.templates_containers_to_create()}</Card.Description>- </div>- </Card.Header>- <Card.Content class="grid grid-cols-1 gap-2 p-4">- {#each services as service}- <Card.Root variant="subtle" class="min-w-0">- <Card.Content class="flex min-w-0 items-center gap-3 p-3">- <div class="flex size-8 shrink-0 items-center justify-center rounded-lg bg-blue-500/10">- <BoxIcon class="size-4 text-blue-500" />- </div>- <div class="min-w-0 flex-1 truncate font-mono text-sm font-semibold">{service}</div>- </Card.Content>- </Card.Root>- {/each}- </Card.Content>- </Card.Root>- {/if}+ <Card.Root variant="subtle">+ <Card.Content class="flex items-center gap-4 p-4">+ <div class="flex size-12 shrink-0 items-center justify-center rounded-lg bg-purple-500/10">+ <VariableIcon class="size-6 text-purple-500" />+ </div>+ <div class="min-w-0 flex-1">+ <div class="text-muted-foreground text-xs font-semibold tracking-wide uppercase">+ {m.common_environment_variables()}+ </div>+ <div class="mt-1 flex flex-wrap items-baseline gap-2">+ <div class="text-2xl font-bold">{envVars?.length ?? 0}</div>+ {#if envVars?.length}+ <div class="text-muted-foreground text-sm">{m.templates_configurable_settings()}</div>+ {/if}+ </div>+ </div>+ </Card.Content>+ </Card.Root>+ </div>- {#if envVars?.length}- <Card.Root class="min-w-0 flex-shrink-0">- <Card.Header icon={VariableIcon}>- <div class="flex flex-col space-y-1.5">- <Card.Title>- <h2>{m.common_environment_variables()}</h2>- </Card.Title>- <Card.Description>{m.templates_default_config_values()}</Card.Description>- </div>- </Card.Header>- <Card.Content class="grid grid-cols-1 gap-2 p-4">- {#each envVars as envVar}- <Card.Root variant="subtle" class="min-w-0">- <Card.Content class="flex min-w-0 flex-col gap-2 p-3">- <div class="text-muted-foreground text-xs font-semibold tracking-wide break-words uppercase select-all">- {envVar.key}- </div>- {#if envVar.value}- <div class="text-foreground min-w-0 font-mono text-sm break-words select-all">{envVar.value}</div>- {:else}- <div class="text-muted-foreground text-xs italic">{m.common_no_default_value()}</div>- {/if}- </Card.Content>- </Card.Root>- {/each}- </Card.Content>- </Card.Root>- {/if}+ <div class="min-h-0 flex-1">+ <div class="grid h-full min-h-0 gap-6 lg:grid-cols-2 xl:grid-cols-3">+ <Card.Root class="flex h-full min-h-0 min-w-0 flex-col lg:col-span-1 xl:col-span-2">+ <Card.Header icon={CodeIcon} class="flex-shrink-0">+ <div class="flex flex-col space-y-1.5">+ <Card.Title>+ <h2>{m.common_docker_compose()}</h2>+ </Card.Title>+ <Card.Description>{m.templates_service_definitions()}</Card.Description>+ </div>+ </Card.Header>+ <Card.Content class="relative z-0 flex min-h-0 min-w-0 flex-1 flex-col overflow-visible p-0">+ <div class="absolute inset-0 min-h-0 w-full min-w-0 rounded-t-none rounded-b-xl">+ <CodeEditor bind:value={data.templateData.content} language="yaml" readOnly={true} fontSize="13px" />+ </div>+ </Card.Content>+ </Card.Root>- {#if env}- <Card.Root class="flex h-full min-h-0 min-w-0 flex-1 flex-col">- <Card.Header icon={FileTextIcon} class="flex-shrink-0">- <div class="flex flex-col space-y-1.5">- <Card.Title>- <h2>{m.environment_file()}</h2>- </Card.Title>- <Card.Description>{m.templates_raw_env_config()}</Card.Description>- </div>- </Card.Header>- <Card.Content class="relative z-0 flex min-h-0 min-w-0 flex-1 flex-col overflow-visible p-0">- <div class="absolute inset-0 min-h-0 w-full min-w-0 rounded-b-xl">- <CodeEditor bind:value={env} language="env" readOnly={true} fontSize="13px" />- </div>- </Card.Content>- </Card.Root>- {/if}+ <div class="flex h-full min-h-0 min-w-0 flex-1 flex-col gap-6 lg:col-span-1">+ {#if services?.length}+ <Card.Root class="min-w-0 flex-shrink-0">+ <Card.Header icon={ContainersIcon}>+ <div class="flex flex-col space-y-1.5">+ <Card.Title>+ <h2>{m.services()}</h2>+ </Card.Title>+ <Card.Description>{m.templates_containers_to_create()}</Card.Description>+ </div>+ </Card.Header>+ <Card.Content class="grid grid-cols-1 gap-2 p-4">+ {#each services as service}+ <Card.Root variant="subtle" class="min-w-0">+ <Card.Content class="flex min-w-0 items-center gap-3 p-3">+ <div class="flex size-8 shrink-0 items-center justify-center rounded-lg bg-blue-500/10">+ <BoxIcon class="size-4 text-blue-500" />+ </div>+ <div class="min-w-0 flex-1 truncate font-mono text-sm font-semibold">{service}</div>+ </Card.Content>+ </Card.Root>+ {/each}+ </Card.Content>+ </Card.Root>+ {/if}++ {#if envVars?.length}+ <Card.Root class="min-w-0 flex-shrink-0">+ <Card.Header icon={VariableIcon}>+ <div class="flex flex-col space-y-1.5">+ <Card.Title>+ <h2>{m.common_environment_variables()}</h2>+ </Card.Title>+ <Card.Description>{m.templates_default_config_values()}</Card.Description>+ </div>+ </Card.Header>+ <Card.Content class="grid grid-cols-1 gap-2 p-4">+ {#each envVars as envVar}+ <Card.Root variant="subtle" class="min-w-0">+ <Card.Content class="flex min-w-0 flex-col gap-2 p-3">+ <div class="text-muted-foreground text-xs font-semibold tracking-wide break-words uppercase select-all">+ {envVar.key}+ </div>+ {#if envVar.value}+ <div class="text-foreground min-w-0 font-mono text-sm break-words select-all">{envVar.value}</div>+ {:else}+ <div class="text-muted-foreground text-xs italic">{m.common_no_default_value()}</div>+ {/if}+ </Card.Content>+ </Card.Root>+ {/each}+ </Card.Content>+ </Card.Root>+ {/if}++ {#if data.templateData.envContent}+ <Card.Root class="flex h-full min-h-0 min-w-0 flex-1 flex-col">+ <Card.Header icon={FileTextIcon} class="flex-shrink-0">+ <div class="flex flex-col space-y-1.5">+ <Card.Title>+ <h2>{m.environment_file()}</h2>+ </Card.Title>+ <Card.Description>{m.templates_raw_env_config()}</Card.Description>+ </div>+ </Card.Header>+ <Card.Content class="relative z-0 flex min-h-0 min-w-0 flex-1 flex-col overflow-visible p-0">+ <div class="absolute inset-0 min-h-0 w-full min-w-0 rounded-b-xl">+ <CodeEditor bind:value={data.templateData.envContent} language="env" readOnly={true} fontSize="13px" />+ </div>+ </Card.Content>+ </Card.Root>+ {/if}+ </div></div></div>- </div>+ {/if}</div>diff --git a/frontend/src/routes/(app)/customize/templates/[id]/+page.ts b/frontend/src/routes/(app)/customize/templates/[id]/+page.tsindex 8fa40013d..290990d75 100644--- a/frontend/src/routes/(app)/customize/templates/[id]/+page.ts+++ b/frontend/src/routes/(app)/customize/templates/[id]/+page.ts@@ -2,6 +2,7 @@ import { templateService } from '$lib/services/template-service';import { queryKeys } from '$lib/query/query-keys';import { error } from '@sveltejs/kit';import type { Template, TemplateContentData } from '$lib/types/template.type';+import type { Variable } from '$lib/types/variable.type';import type { PageLoad } from './$types';export const load: PageLoad = async ({@@ -10,11 +11,12 @@ export const load: PageLoad = async ({}): Promise<{templateData: TemplateContentData;allTemplates: Template[];+ globalVariables: Variable[];}> => {const { queryClient } = await parent();try {- const [templateData, allTemplates] = await Promise.all([+ const [templateData, allTemplates, globalVariables] = await Promise.all([queryClient.fetchQuery({queryKey: queryKeys.templates.content(params.id),queryFn: () => templateService.getTemplateContent(params.id)@@ -22,12 +24,19 @@ export const load: PageLoad = async ({queryClient.fetchQuery({queryKey: queryKeys.templates.allTemplates(),queryFn: () => templateService.getAllTemplates()- })+ }),+ queryClient+ .fetchQuery({+ queryKey: queryKeys.templates.globalVariables(),+ queryFn: () => templateService.getGlobalVariables()+ })+ .catch(() => [] as Variable[])]);return {templateData,- allTemplates+ allTemplates,+ globalVariables};} catch (err) {console.error('Failed to load template:', err);diff --git a/frontend/src/routes/(app)/customize/templates/create/+page.svelte b/frontend/src/routes/(app)/customize/templates/create/+page.sveltenew file mode 100644index 000000000..9d8e4a7e4--- /dev/null+++ b/frontend/src/routes/(app)/customize/templates/create/+page.svelte@@ -0,0 +1,187 @@+<script lang="ts">+ import { goto } from '$app/navigation';+ import { ArcaneButton } from '$lib/components/arcane-button/index.js';+ import FormInput from '$lib/components/form/form-input.svelte';+ import { ArrowLeftIcon } from '$lib/icons';+ import { m } from '$lib/paraglide/messages';+ import { templateService } from '$lib/services/template-service';+ import { handleApiResultWithCallbacks } from '$lib/utils/api.util';+ import { createForm, preventDefault } from '$lib/utils/form.utils';+ import { tryCatch } from '$lib/utils/try-catch';+ import { toast } from 'svelte-sonner';+ import { z } from 'zod/v4';+ import CodePanel from '../../../projects/components/CodePanel.svelte';+ import EditableName from '../../../projects/components/EditableName.svelte';++ let { data } = $props();++ let saving = $state(false);+ let composeHasErrors = $state(false);+ let envHasErrors = $state(false);+ let composeValidationReady = $state(false);+ let envValidationReady = $state(false);+ let nameInputRef = $state<HTMLInputElement | null>(null);++ const globalVariableMap = $derived.by(() =>+ Object.fromEntries((data.globalVariables ?? []).map((item) => [item.key, item.value]))+ );++ const formSchema = z.object({+ name: z.string().min(1, m.templates_template_name_required()),+ description: z.string().optional().default(''),+ composeContent: z.string().min(1, m.templates_content_required()),+ envContent: z.string().optional().default('')+ });++ const initialValues = {+ name: '',+ description: '',+ composeContent: '',+ envContent: ''+ };++ const { inputs, ...form } = createForm<typeof formSchema>(formSchema, initialValues);++ const hasEditorErrors = $derived(!composeValidationReady || !envValidationReady || composeHasErrors || envHasErrors);+ const canCreate = $derived(!!$inputs.name.value && !!$inputs.composeContent.value && !hasEditorErrors && !saving);++ async function handleCreate() {+ if (hasEditorErrors) {+ toast.error(m.templates_validation_error());+ return;+ }++ const validated = form.validate();+ if (!validated) {+ toast.error(m.templates_validation_error());+ return;+ }++ handleApiResultWithCallbacks({+ result: await tryCatch(+ templateService.createTemplate({+ name: validated.name,+ description: validated.description,+ content: validated.composeContent,+ envContent: validated.envContent+ })+ ),+ message: m.templates_create_template_failed(),+ setLoadingState: (value) => (saving = value),+ onSuccess: async (created) => {+ toast.success(m.templates_create_template_success({ name: validated.name }));+ await goto(`/customize/templates/${created.id}`);+ }+ });+ }+</script>++<div class="bg-background flex h-full min-h-0 flex-col">+ <div class="bg-background/95 supports-[backdrop-filter]:bg-background/80 sticky top-0 z-10 mb-2 border-b backdrop-blur">+ <div class="mx-auto flex h-16 max-w-full items-center justify-between gap-4 px-6">+ <div class="flex min-w-0 items-center gap-4">+ <ArcaneButton+ action="base"+ tone="ghost"+ size="sm"+ class="gap-2 bg-transparent"+ icon={ArrowLeftIcon}+ customLabel={m.common_back()}+ onclick={() => goto('/customize/templates')}+ />+ <div class="bg-border hidden h-4 w-px sm:block"></div>+ <div class="hidden min-w-0 items-center gap-3 sm:flex">+ <EditableName+ bind:value={$inputs.name.value}+ bind:ref={nameInputRef}+ variant="inline"+ error={$inputs.name.error ?? undefined}+ originalValue=""+ placeholder={m.templates_template_name_placeholder()}+ canEdit={!saving}+ class="hidden sm:block"+ />+ </div>+ </div>++ <div class="flex items-center gap-2">+ <ArcaneButton action="cancel" onclick={() => goto('/customize/templates')} disabled={saving} />+ <ArcaneButton+ action="create"+ customLabel={m.templates_create_template()}+ onclick={handleCreate}+ disabled={!canCreate}+ loading={saving}+ loadingLabel={m.common_action_creating()}+ />+ </div>+ </div>+ </div>++ <div class="flex min-h-0 flex-1 overflow-hidden">+ <div class="mx-auto flex h-full w-full max-w-full min-w-0 flex-col px-2 pb-6 sm:px-6 sm:pb-6">+ <form class="flex min-h-0 flex-1 flex-col gap-4" onsubmit={preventDefault(handleCreate)}>+ <div class="block flex-shrink-0 py-4 sm:hidden">+ <EditableName+ bind:value={$inputs.name.value}+ bind:ref={nameInputRef}+ variant="block"+ error={$inputs.name.error ?? undefined}+ originalValue=""+ placeholder={m.templates_template_name_placeholder()}+ canEdit={!saving}+ />+ </div>++ <div class="flex-shrink-0 px-1 pt-1">+ <div class="max-w-2xl">+ <FormInput+ input={$inputs.description}+ label={m.templates_template_description_label()}+ placeholder={m.templates_template_description_placeholder()}+ disabled={saving}+ />+ </div>+ </div>++ <div class="flex min-h-0 flex-1 flex-col gap-4 lg:grid lg:grid-cols-5 lg:grid-rows-1 lg:items-stretch">+ <div class="flex min-h-0 flex-1 flex-col lg:col-span-3">+ <CodePanel+ title="compose.yaml"+ language="yaml"+ bind:value={$inputs.composeContent.value}+ error={$inputs.composeContent.error ?? undefined}+ readOnly={saving}+ bind:hasErrors={composeHasErrors}+ bind:validationReady={composeValidationReady}+ fileId="templates:create:compose"+ editorContext={{+ envContent: $inputs.envContent.value,+ composeContents: [$inputs.composeContent.value],+ globalVariables: globalVariableMap+ }}+ />+ </div>++ <div class="flex min-h-0 flex-1 flex-col lg:col-span-2">+ <CodePanel+ title=".env"+ language="env"+ bind:value={$inputs.envContent.value}+ error={$inputs.envContent.error ?? undefined}+ readOnly={saving}+ bind:hasErrors={envHasErrors}+ bind:validationReady={envValidationReady}+ fileId="templates:create:env"+ editorContext={{+ envContent: $inputs.envContent.value,+ composeContents: [$inputs.composeContent.value],+ globalVariables: globalVariableMap+ }}+ />+ </div>+ </div>+ </form>+ </div>+ </div>+</div>diff --git a/frontend/src/routes/(app)/customize/templates/create/+page.ts b/frontend/src/routes/(app)/customize/templates/create/+page.tsnew file mode 100644index 000000000..aa6c468aa--- /dev/null+++ b/frontend/src/routes/(app)/customize/templates/create/+page.ts@@ -0,0 +1,17 @@+import { templateService } from '$lib/services/template-service';+import { queryKeys } from '$lib/query/query-keys';+import type { Variable } from '$lib/types/variable.type';+import type { PageLoad } from './$types';++export const load: PageLoad = async ({ parent }): Promise<{ globalVariables: Variable[] }> => {+ const { queryClient } = await parent();++ const globalVariables = await queryClient+ .fetchQuery({+ queryKey: queryKeys.templates.globalVariables(),+ queryFn: () => templateService.getGlobalVariables()+ })+ .catch(() => [] as Variable[]);++ return { globalVariables };+};