Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
feat: add event details dialog
Kyle Mendelld14609c4535d
diff --git a/backend/internal/services/updater_service.go b/backend/internal/services/updater_service.goindex 0ead8f956..cb236325d 100644--- a/backend/internal/services/updater_service.go+++ b/backend/internal/services/updater_service.go@@ -59,16 +59,12 @@ func NewUpdaterService(// ApplyPending pulls images and restarts impacted containers/stacks for all image_updates with has_update = true.// - For tag updates: repo:latestVersion// - For digest updates: keep tag ref (repo:tag), pulling refreshes digest; recreate with same ref.++//nolint:gocognitfunc (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*dto.UpdaterRunResult, error) {start := time.Now()out := &dto.UpdaterRunResult{Items: []dto.UpdaterItem{}}- // enabled := s.settingsService.GetBoolSetting(ctx, "autoUpdate", false)- // if !enabled {- // out.Duration = time.Since(start).String()- // return out, nil- // }-var records []models.ImageUpdateRecordif err := s.db.WithContext(ctx).Where("has_update = ?", true).Find(&records).Error; err != nil {return nil, fmt.Errorf("query pending image updates: %w", err)@@ -120,6 +116,14 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*dto.Upreturn out, nil}+ // Log run start+ s.logAutoUpdate(ctx, models.EventSeverityInfo, models.JSON{+ "phase": "start",+ "dryRun": dryRun,+ "planned": len(plans),+ "time": time.Now().UTC().Format(time.RFC3339),+ })+// Build maps for fast matching lateroldRefToNewRef := map[string]string{}oldIDToNewRef := map[string]string{} // sha256 -> newRef@@ -147,6 +151,14 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*dto.Upout.Skipped++out.Items = append(out.Items, item)_ = s.recordRun(ctx, item)++ s.logAutoUpdate(ctx, s.severityFromStatus(item.Status), models.JSON{+ "phase": "image_pull",+ "imageOld": p.oldRef,+ "imageNew": p.newRef,+ "status": item.Status,+ "dryRun": true,+ })continue}@@ -161,6 +173,14 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*dto.Up}out.Items = append(out.Items, item)_ = s.recordRun(ctx, item)++ s.logAutoUpdate(ctx, s.severityFromStatus(item.Status), models.JSON{+ "phase": "image_pull",+ "imageOld": p.oldRef,+ "imageNew": p.newRef,+ "status": item.Status,+ "error": item.Error,+ })}// Restart containers using old image IDs (skip stack-managed)@@ -191,6 +211,16 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*dto.Upout.Skipped++}_ = s.recordRun(ctx, item)++ s.logAutoUpdate(ctx, s.severityFromStatus(item.Status), models.JSON{+ "phase": "container",+ "containerId": r.ResourceID,+ "container": r.ResourceName,+ "status": r.Status,+ "oldImageMain": r.OldImages["main"],+ "newImageMain": r.NewImages["main"],+ "error": r.Error,+ })}// Redeploy impacted stacks (only running ones)@@ -206,7 +236,19 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*dto.Up}}- out.Duration = time.Since(start).String()+ // Log run complete+ duration := time.Since(start).String()+ out.Duration = duration+ s.logAutoUpdate(ctx, models.EventSeverityInfo, models.JSON{+ "phase": "complete",+ "checked": out.Checked,+ "updated": out.Updated,+ "skipped": out.Skipped,+ "failed": out.Failed,+ "duration": duration,+ "time": time.Now().UTC().Format(time.RFC3339),+ })+return out, nil}@@ -323,7 +365,6 @@ func (s *UpdaterService) stripDigest(ref string) string {return ref}-// collectUsedImages builds a set of normalized image refs used by running containers and running stacks.func (s *UpdaterService) collectUsedImages(ctx context.Context) (map[string]struct{}, error) {out := map[string]struct{}{}@@ -475,7 +516,6 @@ func (s *UpdaterService) resolveLocalImageIDsForRef(ctx context.Context, ref strreturn ids, nil}-// Containers: match by old image ID. Fallback to tag match if needed.func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldIDToNewRef map[string]string, oldRefToNewRef map[string]string) ([]dto.AutoUpdateResourceResult, error) {dcli, err := s.dockerService.CreateConnection(ctx)if err != nil {@@ -548,7 +588,6 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldIDreturn results, nil}-// Stacks: impacted if any container in the stack runs an image ID in oldIDToNewRef.func (s *UpdaterService) redeployStacksUsingOldIDs(ctx context.Context, oldIDToNewRef map[string]string, out *dto.UpdaterRunResult) error {stacks, err := s.stackService.ListStacks(ctx)if err != nil {@@ -628,11 +667,19 @@ func (s *UpdaterService) redeployStacksUsingOldIDs(ctx context.Context, oldIDToN}out.Items = append(out.Items, item)_ = s.recordRun(ctx, item)++ // Emit auto-update stack event+ s.logAutoUpdate(ctx, s.severityFromStatus(item.Status), models.JSON{+ "phase": "stack",+ "stackId": st.ID,+ "stackName": st.Name,+ "status": item.Status,+ "error": item.Error,+ })}return nil}-// getStackContainers returns the union of containers matching compose or swarm stack labels (OR semantics).func (s *UpdaterService) getStackContainers(ctx context.Context, dcli *client.Client, stackName string) ([]container.Summary, error) {byID := map[string]container.Summary{}@@ -667,3 +714,70 @@ func (s *UpdaterService) getStackContainers(ctx context.Context, dcli *client.Cl}return out, nil}++func (s *UpdaterService) logAutoUpdate(ctx context.Context, sev models.EventSeverity, metadata models.JSON) {+ phase, _ := metadata["phase"].(string)++ title := "Auto-update"+ switch phase {+ case "start":+ title = "Auto-update run started"+ case "image_pull":+ img := fmt.Sprint(metadata["imageNew"])+ if img == "" {+ img = fmt.Sprint(metadata["imageOld"])+ }+ if img != "" {+ title = fmt.Sprintf("Auto-update: image pull %s", img)+ } else {+ title = "Auto-update: image pull"+ }+ case "container":+ name := fmt.Sprint(metadata["container"])+ if name == "" {+ name = fmt.Sprint(metadata["containerId"])+ }+ if name != "" {+ title = fmt.Sprintf("Auto-update: container %s", name)+ } else {+ title = "Auto-update: container"+ }+ case "stack":+ name := fmt.Sprint(metadata["stackName"])+ if name == "" {+ name = fmt.Sprint(metadata["stackId"])+ }+ if name != "" {+ title = fmt.Sprintf("Auto-update: stack %s", name)+ } else {+ title = "Auto-update: stack"+ }+ case "complete":+ title = "Auto-update run completed"+ }++ resourceType := "system"+ resourceName := "auto_updater"+ environmentID := "0"++ _, _ = s.eventService.CreateEvent(ctx, CreateEventRequest{+ Type: models.EventTypeSystemAutoUpdate,+ Severity: sev,+ Title: title,+ ResourceType: &resourceType,+ ResourceName: &resourceName,+ EnvironmentID: &environmentID,+ Metadata: metadata,+ })+}++func (s *UpdaterService) severityFromStatus(status string) models.EventSeverity {+ switch status {+ case "failed":+ return models.EventSeverityError+ case "updated":+ return models.EventSeveritySuccess+ default:+ return models.EventSeverityInfo+ }+}diff --git a/frontend/src/lib/components/dialogs/event-details-dialog.svelte b/frontend/src/lib/components/dialogs/event-details-dialog.sveltenew file mode 100644index 000000000..194ba25ed--- /dev/null+++ b/frontend/src/lib/components/dialogs/event-details-dialog.svelte@@ -0,0 +1,215 @@+<script lang="ts">+ import * as Dialog from '$lib/components/ui/dialog/index.js';+ import { Button } from '$lib/components/ui/button/index.js';+ import { Badge } from '$lib/components/ui/badge';+ import CopyIcon from '@lucide/svelte/icons/copy';+ import InfoIcon from '@lucide/svelte/icons/info';+ import TriangleAlertIcon from '@lucide/svelte/icons/triangle-alert';+ import CheckCircle2Icon from '@lucide/svelte/icons/check-circle-2';+ import XCircleIcon from '@lucide/svelte/icons/x-circle';+ import UserIcon from '@lucide/svelte/icons/user';+ import ClockIcon from '@lucide/svelte/icons/clock';+ import ServerIcon from '@lucide/svelte/icons/server';+ import TagIcon from '@lucide/svelte/icons/tag';+ import type { Event } from '$lib/types/event.type';+ import { toast } from 'svelte-sonner';++ let {+ open = $bindable(),+ event+ }: {+ open: boolean;+ event: Event | null;+ } = $props();++ function formatDate(ts?: string) {+ if (!ts) return '-';+ try {+ return new Date(ts).toLocaleString();+ } catch {+ return ts;+ }+ }++ async function copy(text?: string) {+ if (!text) return;+ try {+ await navigator.clipboard.writeText(text);+ toggleToast('Copied to clipboard');+ } catch {+ toggleToast('Failed to copy', true);+ }+ }+ function toggleToast(msg: string, isErr = false) {+ isErr ? toast.error(msg) : toast.success(msg);+ }++ const hasMetadata = $derived(!!event?.metadata && Object.keys(event.metadata ?? {}).length > 0);+ const jsonPretty = $derived(() => JSON.stringify(event ?? {}, null, 2));+ const metadataPretty = $derived(() => JSON.stringify(event?.metadata ?? {}, null, 2));++ function sevColor(sev?: string) {+ switch (sev) {+ case 'success':+ return 'text-emerald-600 dark:text-emerald-400';+ case 'warning':+ return 'text-amber-600 dark:text-amber-400';+ case 'error':+ return 'text-red-600 dark:text-red-400';+ default:+ return 'text-blue-600 dark:text-blue-400';+ }+ }+ function sevBadge(sev?: string) {+ switch (sev) {+ case 'success':+ return 'bg-emerald-500/15 text-emerald-600 border-emerald-500/30 dark:text-emerald-300';+ case 'warning':+ return 'bg-amber-500/15 text-amber-700 border-amber-500/30 dark:text-amber-300';+ case 'error':+ return 'bg-red-500/15 text-red-600 border-red-500/30 dark:text-red-300';+ default:+ return 'bg-blue-500/15 text-blue-700 border-blue-500/30 dark:text-blue-300';+ }+ }+</script>++<Dialog.Root bind:open>+ <Dialog.Content class="bg-card flex max-h-[90vh] flex-col rounded-xl border shadow-xl sm:max-w-[980px]">+ <!-- Header -->+ <Dialog.Header class="flex-shrink-0 border-b p-4">+ <div class="flex items-start gap-3">+ <div class="mt-0.5">+ {#if event?.severity === 'success'}+ <CheckCircle2Icon class={sevColor(event?.severity) + ' size-6'} />+ {:else if event?.severity === 'warning'}+ <TriangleAlertIcon class={sevColor(event?.severity) + ' size-6'} />+ {:else if event?.severity === 'error'}+ <XCircleIcon class={sevColor(event?.severity) + ' size-6'} />+ {:else}+ <InfoIcon class={sevColor(event?.severity) + ' size-6'} />+ {/if}+ </div>+ <div class="min-w-0 flex-1">+ <Dialog.Title class="text-xl font-semibold leading-tight">+ {event?.title || 'Event Details'}+ </Dialog.Title>+ {#if event?.description}+ <Dialog.Description class="text-muted-foreground mt-1 text-sm">+ {event.description}+ </Dialog.Description>+ {/if}+ <div class="mt-3 flex flex-wrap items-center gap-2">+ <Badge class={'border ' + sevBadge(event?.severity)}>+ {event?.severity ?? 'info'}+ </Badge>+ <Badge variant="outline" class="gap-1">+ <TagIcon class="size-3" />+ {event?.type ?? '-'}+ </Badge>+ {#if event?.environmentId}+ <Badge variant="outline" class="gap-1">+ <ServerIcon class="size-3" />+ env: {event.environmentId}+ </Badge>+ {/if}+ {#if event?.timestamp}+ <span class="text-muted-foreground inline-flex items-center gap-1 text-xs">+ <ClockIcon class="size-3" />+ {formatDate(event.timestamp)}+ </span>+ {/if}+ </div>+ </div>+ </div>+ </Dialog.Header>++ <div class="min-h-0 flex-1 space-y-4 overflow-y-auto p-4">+ <div class="grid gap-4 md:grid-cols-2 lg:grid-cols-3">+ <div class="rounded-lg border p-3">+ <div class="text-muted-foreground text-xs">Resource ID</div>+ <div class="mt-1 flex items-center justify-between gap-2">+ <div class="break-all text-sm">{event?.resourceType || '-'}</div>+ <Button variant="ghost" size="icon" class="size-7" onclick={() => copy(event?.resourceType)} title="Copy resource id">+ <CopyIcon class="size-4" />+ </Button>+ </div>+ </div>++ <div class="rounded-lg border p-3">+ <div class="text-muted-foreground text-xs">Resource Name</div>+ <div class="mt-1 flex items-center justify-between gap-2">+ <div class="break-all text-sm">{event?.resourceName || '-'}</div>+ <Button+ variant="ghost"+ size="icon"+ class="size-7"+ onclick={() => copy(event?.resourceName)}+ title="Copy resource name"+ >+ <CopyIcon class="size-4" />+ </Button>+ </div>+ </div>++ <div class="rounded-lg border p-3">+ <div class="text-muted-foreground text-xs">User</div>+ <div class="mt-1 flex items-center gap-2 text-sm">+ <UserIcon class="text-muted-foreground size-4" />+ {event?.username || '-'}+ </div>+ </div>+ </div>++ <div class="rounded-lg border">+ <div class="flex items-center justify-between border-b px-3 py-2">+ <h3 class="text-sm font-medium">Metadata</h3>+ <Button+ variant="outline"+ size="sm"+ onclick={() => copy(metadataPretty())}+ disabled={!hasMetadata}+ title="Copy metadata JSON"+ >+ <CopyIcon class="mr-2 size-3" />+ Copy JSON+ </Button>+ </div>+ {#if hasMetadata}+ <pre class="bg-muted/40 max-h-[40vh] overflow-auto p-3 text-xs leading-relaxed">+<code class="font-mono">{metadataPretty()}</code>+</pre>+ {:else}+ <div class="text-muted-foreground p-3 text-xs">No metadata provided.</div>+ {/if}+ </div>++ <div class="rounded-lg border">+ <div class="flex items-center justify-between border-b px-3 py-2">+ <h3 class="text-sm font-medium">Raw Event</h3>+ <Button variant="outline" size="sm" onclick={() => copy(jsonPretty())} title="Copy full event JSON">+ <CopyIcon class="mr-2 size-3" />+ Copy JSON+ </Button>+ </div>+ <pre class="bg-muted/40 max-h-[40vh] overflow-auto p-3 text-xs leading-relaxed">+<code class="font-mono">{jsonPretty()}</code>+</pre>+ </div>+ </div>++ <Dialog.Footer class="flex flex-shrink-0 items-center justify-end gap-2 border-t p-3">+ <Button variant="outline" onclick={() => (open = false)}>Close</Button>+ </Dialog.Footer>+ </Dialog.Content>+</Dialog.Root>++<style>+ /* Lock background scroll while dialog is open; no animations/effects */+ :global(html:has([data-slot='dialog-overlay'][data-state='open'])) {+ overflow: hidden;+ }+ :global(body:has([data-slot='dialog-overlay'][data-state='open'])) {+ overflow: hidden;+ }+</style>diff --git a/frontend/src/routes/events/event-table.svelte b/frontend/src/routes/events/event-table.svelteindex df792507a..c15d7670c 100644--- a/frontend/src/routes/events/event-table.svelte+++ b/frontend/src/routes/events/event-table.svelte@@ -16,6 +16,8 @@import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';import type { Event } from '$lib/types/event.type';import type { ColumnSpec } from '$lib/components/arcane-table';+ import EventDetailsDialog from '$lib/components/dialogs/event-details-dialog.svelte';+ import InfoIcon from '@lucide/svelte/icons/info';let {events = $bindable(),@@ -28,6 +30,8 @@} = $props();let isLoading = $state({ removing: false });+ let detailsOpen = $state(false);+ let detailsEvent = $state<Event | null>(null);function getSeverityBadgeVariant(severity: string) {switch (severity) {@@ -76,6 +80,11 @@});}+ function openDetails(e: Event) {+ detailsEvent = e;+ detailsOpen = true;+ }+const columns = [{accessorKey: 'severity',@@ -154,6 +163,10 @@</DropdownMenu.Trigger><DropdownMenu.Content align="end"><DropdownMenu.Group>+ <DropdownMenu.Item onclick={() => openDetails(item)}>+ <InfoIcon class="size-4" />+ View Details+ </DropdownMenu.Item><DropdownMenu.Itemvariant="destructive"onclick={() => handleDeleteEvent(item.id, item.title)}@@ -182,3 +195,5 @@</Card.Content></Card.Root></div>++<EventDetailsDialog bind:open={detailsOpen} event={detailsEvent} />