Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
<script lang="ts">
import { createMutation } from '@tanstack/svelte-query';
import { toast } from 'svelte-sonner';
import { Button } from '#lib/components/ui/button/index.js';
import { Input } from '#lib/components/ui/input/index.js';
import { Label } from '#lib/components/ui/label/index.js';
import { ResponsiveDialog } from '#lib/components/ui/responsive-dialog/index.js';
import { m } from '#lib/paraglide/messages.js';
import { jobScheduleService } from '#lib/services/job-schedule-service.js';
import type { JobStatus } from '#lib/types/settings.js';
let {
job,
environmentId = '0',
open = $bindable(false),
onUpdate
}: {
job: JobStatus;
environmentId?: string;
open?: boolean;
onUpdate?: () => void;
} = $props();
let scheduleValue = $state('');
let error = $state<string | null>(null);
const saveMutation = createMutation(() => ({
mutationFn: (update: Record<string, string>) => jobScheduleService.updateJobSchedules(update, environmentId),
onSuccess: () => {
toast.success(m.jobs_schedule_updated());
onUpdate?.();
},
onError: (err) => {
toast.error(err instanceof Error ? err.message : m.jobs_schedule_update_failed());
}
}));
const isLoading = $derived(saveMutation.isPending);
const cronExamples = [
{ label: m.jobs_cron_example_every_15min(), value: '0 */15 * * * *' },
{ label: m.jobs_cron_example_hourly(), value: '0 0 * * * *' },
{ label: m.jobs_cron_example_every_6hours(), value: '0 0 */6 * * *' },
{ label: m.jobs_cron_example_daily(), value: '0 0 0 * * *' }
];
function validateCron(value: string): boolean {
if (!value.trim()) {
error = m.jobs_cron_required();
return false;
}
const parts = value.trim().split(/\s+/);
if (parts.length !== 6) {
error = m.jobs_cron_invalid();
return false;
}
error = null;
return true;
}
function save() {
if (!validateCron(scheduleValue)) {
return;
}
if (!job.settingsKey) {
toast.error(m.jobs_schedule_update_unavailable());
return;
}
const update = { [job.settingsKey]: scheduleValue };
saveMutation.mutate(update);
}
function useCronExample(value: string) {
scheduleValue = value;
error = null;
}
function handleOpenChange(isOpen: boolean) {
if (isOpen) {
scheduleValue = job.schedule;
error = null;
}
}
handleOpenChange(open);
</script>
<ResponsiveDialog
bind:open
onOpenChange={handleOpenChange}
title={m.jobs_edit_schedule()}
description={job.name}
contentClass="sm:max-w-125"
>
<div class="space-y-4 py-4">
<div class="space-y-2">
<Label for="schedule">{m.jobs_cron_expression()}</Label>
<Input id="schedule" bind:value={scheduleValue} placeholder="0 */15 * * * *" aria-invalid={!!error} />
{#if error}
<p class="text-sm text-destructive">{error}</p>
{:else}
<p class="text-sm text-muted-foreground">{m.jobs_cron_expression_help()}</p>
{/if}
</div>
<div class="space-y-2">
<Label>{m.examples()}</Label>
<div class="grid grid-cols-2 gap-3 pt-2">
{#each cronExamples as example (example.value)}
<Button
variant="outline"
onclick={() => useCronExample(example.value)}
class="min-h-12 items-start justify-start whitespace-normal"
>
<div class="text-left">
<div class="text-xs leading-4 font-medium">{example.label}</div>
<div class="font-mono text-xs leading-4 text-muted-foreground">{example.value}</div>
</div>
</Button>
{/each}
</div>
</div>
</div>
{#snippet footer()}
<Button variant="outline" onclick={() => (open = false)} disabled={isLoading}>
{m.common_cancel()}
</Button>
<Button onclick={save} disabled={isLoading}>
{isLoading ? m.common_saving() : m.common_save()}
</Button>
{/snippet}
</ResponsiveDialog>