feat(docker-watcher): phase 9 - SvelteKit dashboard & project views
SvelteKit project with Svelte 5, TypeScript, Tailwind CSS v4. Dashboard with project cards, project detail with stage/instance management, deploy history, instance controls. Shared API client and reusable components (StatusBadge, InstanceCard, ProjectCard, ConfirmDialog). Add Phase 14 (Volumes & Environment) to plan.
This commit is contained in:
@@ -0,0 +1,278 @@
|
||||
<script lang="ts">
|
||||
import { getSettings, updateSettings, getWebhookUrl, regenerateWebhookUrl } from '$lib/api';
|
||||
import type { Settings } from '$lib/types';
|
||||
import FormField from '$lib/components/FormField.svelte';
|
||||
import { toasts } from '$lib/stores/toast';
|
||||
|
||||
let loading = $state(true);
|
||||
let saving = $state(false);
|
||||
let webhookUrl = $state('');
|
||||
let regenerating = $state(false);
|
||||
|
||||
// Settings fields
|
||||
let domain = $state('');
|
||||
let serverIp = $state('');
|
||||
let network = $state('');
|
||||
let subdomainPattern = $state('');
|
||||
let pollingInterval = $state('');
|
||||
let notificationUrl = $state('');
|
||||
|
||||
let errors = $state<Record<string, string>>({});
|
||||
|
||||
function validateDomain(value: string): string {
|
||||
if (!value.trim()) return 'Domain is required';
|
||||
if (!/^[a-zA-Z0-9][a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/.test(value.trim())) {
|
||||
return 'Invalid domain format';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function validateIp(value: string): string {
|
||||
if (!value.trim()) return '';
|
||||
if (!/^(\d{1,3}\.){3}\d{1,3}$/.test(value.trim())) {
|
||||
return 'Invalid IP address format';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function validatePollingInterval(value: string): string {
|
||||
if (!value.trim()) return '';
|
||||
const num = parseInt(value, 10);
|
||||
if (isNaN(num) || num < 10 || num > 86400) {
|
||||
return 'Polling interval must be between 10 and 86400 seconds';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function validateUrl(value: string): string {
|
||||
if (!value.trim()) return '';
|
||||
try {
|
||||
new URL(value.trim());
|
||||
return '';
|
||||
} catch {
|
||||
return 'Invalid URL format';
|
||||
}
|
||||
}
|
||||
|
||||
function validateAll(): boolean {
|
||||
const newErrors: Record<string, string> = {};
|
||||
const domainErr = validateDomain(domain);
|
||||
if (domainErr) newErrors.domain = domainErr;
|
||||
const ipErr = validateIp(serverIp);
|
||||
if (ipErr) newErrors.serverIp = ipErr;
|
||||
const intervalErr = validatePollingInterval(pollingInterval);
|
||||
if (intervalErr) newErrors.pollingInterval = intervalErr;
|
||||
const urlErr = validateUrl(notificationUrl);
|
||||
if (urlErr) newErrors.notificationUrl = urlErr;
|
||||
errors = newErrors;
|
||||
return Object.keys(newErrors).length === 0;
|
||||
}
|
||||
|
||||
async function loadSettings() {
|
||||
loading = true;
|
||||
try {
|
||||
const settings = await getSettings();
|
||||
domain = settings.domain ?? '';
|
||||
serverIp = settings.server_ip ?? '';
|
||||
network = settings.network ?? '';
|
||||
subdomainPattern = settings.subdomain_pattern ?? '';
|
||||
pollingInterval = settings.polling_interval ?? '';
|
||||
notificationUrl = settings.notification_url ?? '';
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Failed to load settings';
|
||||
toasts.error(message);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadWebhookUrlValue() {
|
||||
try {
|
||||
const result = await getWebhookUrl();
|
||||
webhookUrl = result.url;
|
||||
} catch {
|
||||
// Webhook URL may not be configured yet
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (!validateAll()) return;
|
||||
|
||||
saving = true;
|
||||
try {
|
||||
const payload: Partial<Settings> = {
|
||||
domain: domain.trim(),
|
||||
server_ip: serverIp.trim(),
|
||||
network: network.trim(),
|
||||
subdomain_pattern: subdomainPattern.trim(),
|
||||
polling_interval: pollingInterval.trim(),
|
||||
notification_url: notificationUrl.trim()
|
||||
};
|
||||
await updateSettings(payload);
|
||||
toasts.success('Settings saved successfully');
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Failed to save settings';
|
||||
toasts.error(message);
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRegenerateWebhook() {
|
||||
regenerating = true;
|
||||
try {
|
||||
const result = await regenerateWebhookUrl();
|
||||
webhookUrl = result.url;
|
||||
toasts.success('Webhook URL regenerated');
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Failed to regenerate webhook URL';
|
||||
toasts.error(message);
|
||||
} finally {
|
||||
regenerating = false;
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
loadSettings();
|
||||
loadWebhookUrlValue();
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>General Settings - Docker Watcher</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="space-y-6">
|
||||
{#if loading}
|
||||
<div class="flex items-center justify-center py-12">
|
||||
<svg class="h-8 w-8 animate-spin text-blue-600" viewBox="0 0 24 24" fill="none">
|
||||
<circle
|
||||
class="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
stroke-width="4"
|
||||
></circle>
|
||||
<path
|
||||
class="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
||||
></path>
|
||||
</svg>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Global settings form -->
|
||||
<div class="rounded-lg border border-gray-200 bg-white p-6 shadow-sm">
|
||||
<h2 class="mb-4 text-lg font-semibold text-gray-800">Global Configuration</h2>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<FormField
|
||||
label="Domain"
|
||||
name="domain"
|
||||
bind:value={domain}
|
||||
placeholder="example.com"
|
||||
required
|
||||
error={errors.domain ?? ''}
|
||||
helpText="Base domain for subdomain routing"
|
||||
/>
|
||||
|
||||
<FormField
|
||||
label="Server IP"
|
||||
name="serverIp"
|
||||
bind:value={serverIp}
|
||||
placeholder="93.84.96.191"
|
||||
error={errors.serverIp ?? ''}
|
||||
helpText="Public IP address of the server"
|
||||
/>
|
||||
|
||||
<FormField
|
||||
label="Docker Network"
|
||||
name="network"
|
||||
bind:value={network}
|
||||
placeholder="staging-net"
|
||||
helpText="Docker network for deployed containers"
|
||||
/>
|
||||
|
||||
<FormField
|
||||
label="Subdomain Pattern"
|
||||
name="subdomainPattern"
|
||||
bind:value={subdomainPattern}
|
||||
placeholder="stage-{stage}-{project}"
|
||||
helpText="Pattern for auto-generated subdomains"
|
||||
/>
|
||||
|
||||
<FormField
|
||||
label="Polling Interval (seconds)"
|
||||
name="pollingInterval"
|
||||
type="number"
|
||||
bind:value={pollingInterval}
|
||||
placeholder="60"
|
||||
error={errors.pollingInterval ?? ''}
|
||||
helpText="How often to check registries for new tags (10-86400)"
|
||||
/>
|
||||
|
||||
<FormField
|
||||
label="Notification URL"
|
||||
name="notificationUrl"
|
||||
bind:value={notificationUrl}
|
||||
placeholder="https://notify.example.com/webhook"
|
||||
error={errors.notificationUrl ?? ''}
|
||||
helpText="Webhook URL for deploy notifications"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="mt-6">
|
||||
<button
|
||||
onclick={handleSave}
|
||||
disabled={saving}
|
||||
class="rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{saving ? 'Saving...' : 'Save Settings'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Webhook URL section -->
|
||||
<div class="rounded-lg border border-gray-200 bg-white p-6 shadow-sm">
|
||||
<h2 class="mb-4 text-lg font-semibold text-gray-800">Webhook URL</h2>
|
||||
<p class="mb-3 text-sm text-gray-500">
|
||||
This secret URL receives image push notifications from your CI pipeline.
|
||||
</p>
|
||||
|
||||
{#if webhookUrl}
|
||||
<div class="flex items-center gap-3">
|
||||
<code
|
||||
class="flex-1 rounded-md border border-gray-200 bg-gray-50 px-3 py-2 text-sm font-mono text-gray-700 break-all"
|
||||
>
|
||||
{webhookUrl}
|
||||
</code>
|
||||
<button
|
||||
onclick={() => {
|
||||
navigator.clipboard.writeText(webhookUrl);
|
||||
toasts.info('Webhook URL copied to clipboard');
|
||||
}}
|
||||
class="rounded-md border border-gray-300 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50"
|
||||
>
|
||||
Copy
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-sm text-gray-400 italic">No webhook URL configured</p>
|
||||
{/if}
|
||||
|
||||
<div class="mt-4">
|
||||
<button
|
||||
onclick={handleRegenerateWebhook}
|
||||
disabled={regenerating}
|
||||
class="rounded-md border border-red-300 px-4 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 disabled:opacity-50"
|
||||
>
|
||||
{regenerating ? 'Regenerating...' : 'Regenerate URL'}
|
||||
</button>
|
||||
<p class="mt-1 text-xs text-gray-500">
|
||||
Warning: regenerating will invalidate the current URL. Update your CI pipelines.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,238 @@
|
||||
<script lang="ts">
|
||||
import { getSettings, updateSettings } from '$lib/api';
|
||||
import FormField from '$lib/components/FormField.svelte';
|
||||
import { toasts } from '$lib/stores/toast';
|
||||
|
||||
let loading = $state(true);
|
||||
let saving = $state(false);
|
||||
|
||||
// NPM credentials
|
||||
let npmUrl = $state('');
|
||||
let npmEmail = $state('');
|
||||
let npmPassword = $state('');
|
||||
let npmHasCredentials = $state(false);
|
||||
let editingNpm = $state(false);
|
||||
|
||||
let errors = $state<Record<string, string>>({});
|
||||
|
||||
function validateNpmForm(): boolean {
|
||||
const newErrors: Record<string, string> = {};
|
||||
if (!npmUrl.trim()) {
|
||||
newErrors.npmUrl = 'NPM URL is required';
|
||||
} else {
|
||||
try {
|
||||
new URL(npmUrl.trim());
|
||||
} catch {
|
||||
newErrors.npmUrl = 'Invalid URL format';
|
||||
}
|
||||
}
|
||||
if (!npmEmail.trim()) {
|
||||
newErrors.npmEmail = 'Email is required';
|
||||
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(npmEmail.trim())) {
|
||||
newErrors.npmEmail = 'Invalid email format';
|
||||
}
|
||||
if (editingNpm && !npmPassword.trim()) {
|
||||
newErrors.npmPassword = 'Password is required when updating credentials';
|
||||
}
|
||||
errors = newErrors;
|
||||
return Object.keys(newErrors).length === 0;
|
||||
}
|
||||
|
||||
async function loadCredentials() {
|
||||
loading = true;
|
||||
try {
|
||||
const settings = await getSettings();
|
||||
npmUrl = settings.npm_url ?? '';
|
||||
npmEmail = settings.npm_email ?? '';
|
||||
// If npm_password is present (even masked), credentials exist
|
||||
npmHasCredentials = !!(settings.npm_url && settings.npm_email);
|
||||
npmPassword = '';
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Failed to load credentials';
|
||||
toasts.error(message);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSaveNpm() {
|
||||
if (!validateNpmForm()) return;
|
||||
|
||||
saving = true;
|
||||
try {
|
||||
const payload: Record<string, string> = {
|
||||
npm_url: npmUrl.trim(),
|
||||
npm_email: npmEmail.trim()
|
||||
};
|
||||
if (npmPassword.trim()) {
|
||||
payload.npm_password = npmPassword.trim();
|
||||
}
|
||||
await updateSettings(payload);
|
||||
npmHasCredentials = true;
|
||||
editingNpm = false;
|
||||
npmPassword = '';
|
||||
toasts.success('NPM credentials saved');
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Failed to save NPM credentials';
|
||||
toasts.error(message);
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
loadCredentials();
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Credentials - Docker Watcher</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<h2 class="text-lg font-semibold text-gray-800">Credentials</h2>
|
||||
<p class="text-sm text-gray-500">
|
||||
Manage credentials for Nginx Proxy Manager and registry tokens. All values are encrypted at
|
||||
rest.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
<div class="flex items-center justify-center py-12">
|
||||
<svg class="h-8 w-8 animate-spin text-blue-600" viewBox="0 0 24 24" fill="none">
|
||||
<circle
|
||||
class="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
stroke-width="4"
|
||||
></circle>
|
||||
<path
|
||||
class="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
||||
></path>
|
||||
</svg>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- NPM Credentials -->
|
||||
<div class="rounded-lg border border-gray-200 bg-white p-6 shadow-sm">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<div>
|
||||
<h3 class="text-sm font-semibold text-gray-800">Nginx Proxy Manager</h3>
|
||||
<p class="text-xs text-gray-500">Credentials for managing proxy hosts via NPM API</p>
|
||||
</div>
|
||||
{#if npmHasCredentials && !editingNpm}
|
||||
<span class="rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700">
|
||||
Configured
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if !editingNpm && npmHasCredentials}
|
||||
<!-- Masked display -->
|
||||
<div class="space-y-3">
|
||||
<div class="flex items-center justify-between rounded-md bg-gray-50 px-3 py-2">
|
||||
<div>
|
||||
<p class="text-xs font-medium text-gray-500">URL</p>
|
||||
<p class="text-sm text-gray-700">{npmUrl || 'Not set'}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between rounded-md bg-gray-50 px-3 py-2">
|
||||
<div>
|
||||
<p class="text-xs font-medium text-gray-500">Email</p>
|
||||
<p class="text-sm text-gray-700">{npmEmail || 'Not set'}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between rounded-md bg-gray-50 px-3 py-2">
|
||||
<div>
|
||||
<p class="text-xs font-medium text-gray-500">Password</p>
|
||||
<p class="text-sm font-mono text-gray-700">--------</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onclick={() => {
|
||||
editingNpm = true;
|
||||
}}
|
||||
class="mt-2 rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50"
|
||||
>
|
||||
Change Credentials
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Edit form -->
|
||||
<div class="space-y-4">
|
||||
<FormField
|
||||
label="NPM URL"
|
||||
name="npmUrl"
|
||||
bind:value={npmUrl}
|
||||
placeholder="http://npm:81"
|
||||
required
|
||||
error={errors.npmUrl ?? ''}
|
||||
helpText="Nginx Proxy Manager API URL"
|
||||
/>
|
||||
|
||||
<FormField
|
||||
label="Email"
|
||||
name="npmEmail"
|
||||
type="email"
|
||||
bind:value={npmEmail}
|
||||
placeholder="admin@example.com"
|
||||
required
|
||||
error={errors.npmEmail ?? ''}
|
||||
helpText="NPM admin email"
|
||||
/>
|
||||
|
||||
<FormField
|
||||
label="Password"
|
||||
name="npmPassword"
|
||||
type="password"
|
||||
bind:value={npmPassword}
|
||||
placeholder={npmHasCredentials ? '(enter new password)' : 'npm-password'}
|
||||
required={editingNpm}
|
||||
error={errors.npmPassword ?? ''}
|
||||
helpText={npmHasCredentials
|
||||
? 'Enter the new password to replace the existing one'
|
||||
: 'NPM admin password (will be encrypted)'}
|
||||
/>
|
||||
|
||||
<div class="flex gap-3">
|
||||
<button
|
||||
onclick={handleSaveNpm}
|
||||
disabled={saving}
|
||||
class="rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:opacity-50"
|
||||
>
|
||||
{saving ? 'Saving...' : 'Save'}
|
||||
</button>
|
||||
{#if npmHasCredentials}
|
||||
<button
|
||||
onclick={() => {
|
||||
editingNpm = false;
|
||||
npmPassword = '';
|
||||
errors = {};
|
||||
}}
|
||||
class="rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Registry Tokens info -->
|
||||
<div class="rounded-lg border border-gray-200 bg-white p-6 shadow-sm">
|
||||
<h3 class="text-sm font-semibold text-gray-800">Registry Tokens</h3>
|
||||
<p class="mt-1 text-sm text-gray-500">
|
||||
Registry authentication tokens are managed per-registry in the
|
||||
<a href="/settings/registries" class="text-blue-600 hover:text-blue-700 underline"
|
||||
>Registries</a
|
||||
>
|
||||
section. Each registry stores its token encrypted in the database.
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,315 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
listRegistries,
|
||||
createRegistry,
|
||||
updateRegistry,
|
||||
deleteRegistry,
|
||||
testRegistry
|
||||
} from '$lib/api';
|
||||
import type { Registry } from '$lib/types';
|
||||
import FormField from '$lib/components/FormField.svelte';
|
||||
import { toasts } from '$lib/stores/toast';
|
||||
|
||||
let registries = $state<Registry[]>([]);
|
||||
let loading = $state(true);
|
||||
|
||||
// Form state
|
||||
let showForm = $state(false);
|
||||
let editingId = $state<string | null>(null);
|
||||
let formName = $state('');
|
||||
let formUrl = $state('');
|
||||
let formType = $state('gitea');
|
||||
let formToken = $state('');
|
||||
let formSaving = $state(false);
|
||||
let testingId = $state<string | null>(null);
|
||||
|
||||
let errors = $state<Record<string, string>>({});
|
||||
|
||||
function validateForm(): boolean {
|
||||
const newErrors: Record<string, string> = {};
|
||||
if (!formName.trim()) newErrors.name = 'Name is required';
|
||||
if (!formUrl.trim()) {
|
||||
newErrors.url = 'URL is required';
|
||||
} else {
|
||||
try {
|
||||
new URL(formUrl.trim());
|
||||
} catch {
|
||||
newErrors.url = 'Invalid URL format';
|
||||
}
|
||||
}
|
||||
if (!formToken.trim() && !editingId) {
|
||||
newErrors.token = 'Token is required for new registries';
|
||||
}
|
||||
errors = newErrors;
|
||||
return Object.keys(newErrors).length === 0;
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
showForm = false;
|
||||
editingId = null;
|
||||
formName = '';
|
||||
formUrl = '';
|
||||
formType = 'gitea';
|
||||
formToken = '';
|
||||
errors = {};
|
||||
}
|
||||
|
||||
function startEdit(registry: Registry) {
|
||||
editingId = registry.id;
|
||||
formName = registry.name;
|
||||
formUrl = registry.url;
|
||||
formType = registry.type;
|
||||
formToken = '';
|
||||
showForm = true;
|
||||
errors = {};
|
||||
}
|
||||
|
||||
async function loadRegistryList() {
|
||||
loading = true;
|
||||
try {
|
||||
registries = await listRegistries();
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Failed to load registries';
|
||||
toasts.error(message);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (!validateForm()) return;
|
||||
|
||||
formSaving = true;
|
||||
try {
|
||||
const payload: Partial<Registry> = {
|
||||
name: formName.trim(),
|
||||
url: formUrl.trim(),
|
||||
type: formType
|
||||
};
|
||||
if (formToken.trim()) {
|
||||
payload.token = formToken.trim();
|
||||
}
|
||||
|
||||
if (editingId) {
|
||||
await updateRegistry(editingId, payload);
|
||||
toasts.success('Registry updated');
|
||||
} else {
|
||||
await createRegistry(payload);
|
||||
toasts.success('Registry added');
|
||||
}
|
||||
resetForm();
|
||||
await loadRegistryList();
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Failed to save registry';
|
||||
toasts.error(message);
|
||||
} finally {
|
||||
formSaving = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(registry: Registry) {
|
||||
if (!confirm(`Delete registry "${registry.name}"? This cannot be undone.`)) return;
|
||||
|
||||
try {
|
||||
await deleteRegistry(registry.id);
|
||||
toasts.success(`Registry "${registry.name}" deleted`);
|
||||
await loadRegistryList();
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Failed to delete registry';
|
||||
toasts.error(message);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTestConnection(registry: Registry) {
|
||||
testingId = registry.id;
|
||||
try {
|
||||
await testRegistry(registry.id);
|
||||
toasts.success(`Connection to "${registry.name}" successful`);
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Connection test failed';
|
||||
toasts.error(message);
|
||||
} finally {
|
||||
testingId = null;
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
loadRegistryList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Registries - Docker Watcher</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="space-y-6">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h2 class="text-lg font-semibold text-gray-800">Container Registries</h2>
|
||||
<p class="text-sm text-gray-500">Manage your container registries for image detection.</p>
|
||||
</div>
|
||||
{#if !showForm}
|
||||
<button
|
||||
onclick={() => {
|
||||
resetForm();
|
||||
showForm = true;
|
||||
}}
|
||||
class="rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700"
|
||||
>
|
||||
Add Registry
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Add/Edit Form -->
|
||||
{#if showForm}
|
||||
<div class="rounded-lg border border-blue-200 bg-blue-50/50 p-6">
|
||||
<h3 class="mb-4 text-sm font-semibold text-gray-800">
|
||||
{editingId ? 'Edit Registry' : 'Add New Registry'}
|
||||
</h3>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<FormField
|
||||
label="Name"
|
||||
name="registryName"
|
||||
bind:value={formName}
|
||||
placeholder="gitea"
|
||||
required
|
||||
error={errors.name ?? ''}
|
||||
helpText="A friendly name for this registry"
|
||||
/>
|
||||
|
||||
<FormField
|
||||
label="URL"
|
||||
name="registryUrl"
|
||||
bind:value={formUrl}
|
||||
placeholder="https://git.example.com"
|
||||
required
|
||||
error={errors.url ?? ''}
|
||||
helpText="Registry base URL"
|
||||
/>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="registryType" class="text-sm font-medium text-gray-700">Type</label>
|
||||
<select
|
||||
id="registryType"
|
||||
bind:value={formType}
|
||||
class="rounded-md border border-gray-300 bg-white px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
<option value="gitea">Gitea</option>
|
||||
<option value="github">GitHub</option>
|
||||
<option value="docker_hub">Docker Hub</option>
|
||||
<option value="custom">Custom</option>
|
||||
</select>
|
||||
<p class="text-xs text-gray-500">Registry type for API compatibility</p>
|
||||
</div>
|
||||
|
||||
<FormField
|
||||
label="Token"
|
||||
name="registryToken"
|
||||
type="password"
|
||||
bind:value={formToken}
|
||||
placeholder={editingId ? '(leave empty to keep current)' : 'registry-access-token'}
|
||||
required={!editingId}
|
||||
error={errors.token ?? ''}
|
||||
helpText={editingId
|
||||
? 'Leave empty to keep the existing token'
|
||||
: 'API token for authentication'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex gap-3">
|
||||
<button
|
||||
onclick={handleSave}
|
||||
disabled={formSaving}
|
||||
class="rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:opacity-50"
|
||||
>
|
||||
{formSaving ? 'Saving...' : editingId ? 'Update' : 'Add Registry'}
|
||||
</button>
|
||||
<button
|
||||
onclick={resetForm}
|
||||
disabled={formSaving}
|
||||
class="rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Registry List -->
|
||||
{#if loading}
|
||||
<div class="flex items-center justify-center py-12">
|
||||
<svg class="h-8 w-8 animate-spin text-blue-600" viewBox="0 0 24 24" fill="none">
|
||||
<circle
|
||||
class="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
stroke-width="4"
|
||||
></circle>
|
||||
<path
|
||||
class="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
||||
></path>
|
||||
</svg>
|
||||
</div>
|
||||
{:else if registries.length === 0}
|
||||
<div class="rounded-lg border border-dashed border-gray-300 p-8 text-center">
|
||||
<p class="text-sm text-gray-500">No registries configured yet.</p>
|
||||
{#if !showForm}
|
||||
<button
|
||||
onclick={() => {
|
||||
showForm = true;
|
||||
}}
|
||||
class="mt-2 text-sm font-medium text-blue-600 hover:text-blue-700"
|
||||
>
|
||||
Add your first registry
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="space-y-3">
|
||||
{#each registries as registry (registry.id)}
|
||||
<div
|
||||
class="flex items-center justify-between rounded-lg border border-gray-200 bg-white p-4 shadow-sm"
|
||||
>
|
||||
<div>
|
||||
<div class="flex items-center gap-2">
|
||||
<h3 class="text-sm font-semibold text-gray-800">{registry.name}</h3>
|
||||
<span
|
||||
class="rounded-full bg-gray-100 px-2 py-0.5 text-xs font-medium text-gray-600"
|
||||
>
|
||||
{registry.type}
|
||||
</span>
|
||||
</div>
|
||||
<p class="mt-1 text-sm text-gray-500">{registry.url}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
onclick={() => handleTestConnection(registry)}
|
||||
disabled={testingId === registry.id}
|
||||
class="rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:opacity-50"
|
||||
>
|
||||
{testingId === registry.id ? 'Testing...' : 'Test'}
|
||||
</button>
|
||||
<button
|
||||
onclick={() => startEdit(registry)}
|
||||
class="rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-50"
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
<button
|
||||
onclick={() => handleDelete(registry)}
|
||||
class="rounded-md border border-red-300 px-3 py-1.5 text-xs font-medium text-red-600 transition-colors hover:bg-red-50"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
Reference in New Issue
Block a user