Files
gh-christianlouis-dmarq/backend/app/templates/setup.html
T
2026-05-23 11:37:10 +02:00

310 lines
16 KiB
HTML

<!DOCTYPE html>
<html lang="en" data-theme="dmarqlight">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setup - {{ app_name }}</title>
<link rel="icon" type="image/x-icon" href="/static/img/favicon.ico">
<link rel="icon" type="image/png" sizes="32x32" href="/static/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/static/img/favicon-16x16.png">
<link rel="apple-touch-icon" sizes="180x180" href="/static/img/apple-touch-icon.png">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&family=Open+Sans:wght@400;500;600&display=swap" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/daisyui@4.12.24/dist/full.css" rel="stylesheet" type="text/css"/>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<style>[x-cloak] { display: none !important; }</style>
</head>
<body class="min-h-screen bg-base-200 font-sans antialiased">
<div class="min-h-screen" x-data="setupWizard()" x-init="init()" x-cloak>
<header class="border-b border-base-300 bg-base-100">
<div class="mx-auto flex max-w-6xl items-center justify-between px-4 py-4">
<a href="/" class="inline-flex items-center gap-3">
<img src="/static/img/monogram_light.png" alt="{{ app_name }} logo" class="h-10 w-10">
<span class="font-heading text-2xl font-bold text-primary">{{ app_name }}</span>
</a>
<a x-show="complete" href="/login" class="btn btn-primary btn-sm">Sign in</a>
</div>
</header>
<main class="mx-auto grid max-w-6xl grid-cols-1 gap-6 px-4 py-8 lg:grid-cols-[minmax(0,1fr)_22rem]">
<section class="min-w-0 space-y-6">
<div>
<h1 class="text-3xl font-semibold text-base-content">First-run setup</h1>
<p class="mt-2 max-w-2xl text-sm leading-6 text-base-content/70">
Save the basic settings DMARQ needs before the dashboard is used.
</p>
</div>
<div class="card bg-base-100 shadow">
<div class="card-body gap-6">
<ol class="grid gap-3 sm:grid-cols-3" aria-label="Setup progress">
<template x-for="step in steps" :key="step.id">
<li class="flex items-center gap-3 rounded-lg border border-base-300 p-3"
:class="stepClass(step.id)">
<span class="flex h-8 w-8 shrink-0 items-center justify-center rounded-full text-sm font-semibold"
:class="stepBadgeClass(step.id)"
x-text="step.id"></span>
<span class="min-w-0">
<span class="block text-sm font-semibold" x-text="step.title"></span>
<span class="block truncate text-xs text-base-content/60" x-text="step.detail"></span>
</span>
</li>
</template>
</ol>
<div x-show="statusLoading" class="flex items-center gap-3 rounded-lg bg-base-200 p-4">
<span class="loading loading-spinner loading-sm"></span>
<span class="text-sm text-base-content/70">Checking setup status...</span>
</div>
<div x-show="error" role="alert" class="alert alert-error">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v4m0 4h.01M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/>
</svg>
<span x-text="error"></span>
</div>
<form x-show="!statusLoading && currentStep === 1" @submit.prevent="submitAdmin" class="space-y-5">
<div>
<h2 class="text-xl font-semibold">Admin contact</h2>
<p class="mt-1 text-sm text-base-content/60">This contact is saved with the setup record.</p>
</div>
<div class="grid gap-4 sm:grid-cols-2">
<label class="form-control">
<span class="label-text font-medium">Email</span>
<input x-model.trim="admin.email" type="email" required autocomplete="email" class="input input-bordered">
</label>
<label class="form-control">
<span class="label-text font-medium">Username</span>
<input x-model.trim="admin.username" type="text" required autocomplete="username" class="input input-bordered">
</label>
<label class="form-control">
<span class="label-text font-medium">Password</span>
<input x-model="admin.password" type="password" required autocomplete="new-password" class="input input-bordered">
</label>
<label class="form-control">
<span class="label-text font-medium">Confirm password</span>
<input x-model="admin.confirmPassword" type="password" required autocomplete="new-password" class="input input-bordered">
</label>
</div>
<div class="flex justify-end">
<button type="submit" class="btn btn-primary" :disabled="saving">
<span x-show="saving" class="loading loading-spinner loading-xs"></span>
Continue
</button>
</div>
</form>
<form x-show="!statusLoading && currentStep === 2" @submit.prevent="submitSystem" class="space-y-5">
<div>
<h2 class="text-xl font-semibold">System settings</h2>
<p class="mt-1 text-sm text-base-content/60">These values are stored in the application settings.</p>
</div>
<div class="grid gap-4 sm:grid-cols-2">
<label class="form-control">
<span class="label-text font-medium">Application name</span>
<input x-model.trim="system.app_name" type="text" required class="input input-bordered">
</label>
<label class="form-control">
<span class="label-text font-medium">Base URL</span>
<input x-model.trim="system.base_url" type="url" required class="input input-bordered">
</label>
</div>
<div class="flex justify-between gap-3">
<button type="button" class="btn btn-ghost" @click="currentStep = 1" :disabled="saving">Back</button>
<button type="submit" class="btn btn-primary" :disabled="saving">
<span x-show="saving" class="loading loading-spinner loading-xs"></span>
Finish setup
</button>
</div>
</form>
<div x-show="!statusLoading && complete" class="space-y-5">
<div role="alert" class="alert alert-success">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m5 13 4 4L19 7"/>
</svg>
<div>
<p class="font-semibold">Setup is complete.</p>
<p class="text-sm" x-text="message || 'DMARQ is ready for sign-in and report ingestion.'"></p>
</div>
</div>
<div class="flex flex-wrap gap-3">
<a href="/login" class="btn btn-primary">Sign in</a>
<a href="/" class="btn btn-outline">Open dashboard</a>
</div>
</div>
</div>
</div>
</section>
<aside class="min-w-0 space-y-6">
<div class="card bg-base-100 shadow">
<div class="card-body">
<h2 class="card-title text-lg">Authentication</h2>
{% if logto_configured %}
<div role="alert" class="alert alert-success py-3 text-sm">
<span>Logto is configured.</span>
</div>
{% else %}
<p class="text-sm leading-6 text-base-content/70">
Configure Logto after setup to enable user sign-in.
</p>
<div class="mockup-code mt-2 text-xs">
<pre><code>LOGTO_ENDPOINT=https://tenant.logto.app</code></pre>
<pre><code>LOGTO_APP_ID=...</code></pre>
<pre><code>LOGTO_APP_SECRET=...</code></pre>
</div>
{% endif %}
</div>
</div>
<div class="card bg-base-100 shadow">
<div class="card-body">
<h2 class="card-title text-lg">Setup checklist</h2>
<ul class="space-y-3 text-sm text-base-content/70">
<li class="flex gap-2">
<span class="mt-1 h-2 w-2 rounded-full bg-primary"></span>
<span>
<a href="/domains" class="link link-primary font-medium">Add monitored domains</a>
<span class="ml-1" x-text="`(${totalDomains} configured)`"></span>
</span>
</li>
<li class="flex gap-2">
<span class="mt-1 h-2 w-2 rounded-full bg-secondary"></span>
<span>
<a href="/mail-sources" class="link link-primary font-medium">Connect a mailbox</a>
<span class="ml-1" x-text="`(${enabledMailSources}/${totalMailSources} enabled)`"></span>
</span>
</li>
<li class="flex gap-2">
<span class="mt-1 h-2 w-2 rounded-full bg-accent"></span>
<span>
<a href="/operations" class="link link-primary font-medium">Check system health</a>
</span>
</li>
</ul>
</div>
</div>
</aside>
</main>
</div>
<script>
function setupWizard() {
return {
statusLoading: true,
saving: false,
currentStep: 1,
complete: false,
error: '',
message: '',
totalDomains: 0,
totalMailSources: 0,
enabledMailSources: 0,
steps: [
{ id: 1, title: 'Admin', detail: 'Contact details' },
{ id: 2, title: 'System', detail: 'Name and URL' },
{ id: 3, title: 'Ready', detail: 'Start using DMARQ' },
],
admin: {
email: '',
username: '',
password: '',
confirmPassword: '',
},
system: {
app_name: {{ app_name | tojson }},
base_url: window.location.origin,
},
async init() {
this.applyTheme();
try {
const response = await fetch('/api/v1/setup/status');
if (!response.ok) {
throw new Error('Could not load setup status.');
}
const status = await response.json();
this.system.app_name = status.app_name || this.system.app_name;
this.complete = Boolean(status.is_setup_complete);
this.currentStep = this.complete ? 3 : 1;
this.totalDomains = status.total_domains || 0;
this.totalMailSources = status.total_mail_sources || 0;
this.enabledMailSources = status.enabled_mail_sources || 0;
} catch (err) {
this.error = err.message || 'Could not load setup status.';
} finally {
this.statusLoading = false;
}
},
applyTheme() {
if (localStorage.getItem('darkMode') === 'true') {
document.documentElement.setAttribute('data-theme', 'dmarqdark');
}
},
stepClass(stepId) {
if (this.complete && stepId === 3) return 'border-success bg-success/10';
if (stepId === this.currentStep) return 'border-primary bg-primary/10';
if (stepId < this.currentStep) return 'border-success bg-success/10';
return 'border-base-300 bg-base-100';
},
stepBadgeClass(stepId) {
if (this.complete && stepId === 3) return 'bg-success text-success-content';
if (stepId === this.currentStep) return 'bg-primary text-primary-content';
if (stepId < this.currentStep) return 'bg-success text-success-content';
return 'bg-base-200 text-base-content/70';
},
async submitAdmin() {
this.error = '';
if (this.admin.password !== this.admin.confirmPassword) {
this.error = 'Passwords do not match.';
return;
}
await this.save('/api/v1/setup/admin', {
email: this.admin.email,
username: this.admin.username,
password: this.admin.password,
}, () => {
this.currentStep = 2;
this.admin.password = '';
this.admin.confirmPassword = '';
});
},
async submitSystem() {
this.error = '';
await this.save('/api/v1/setup/system', this.system, () => {
this.complete = true;
this.currentStep = 3;
this.message = 'Your setup settings have been saved.';
});
},
async save(url, payload, onSuccess) {
this.saving = true;
try {
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
if (!response.ok) {
const data = await response.json().catch(() => ({}));
throw new Error(data.detail || 'Setup could not be saved.');
}
onSuccess();
} catch (err) {
this.error = err.message || 'Setup could not be saved.';
} finally {
this.saving = false;
}
},
};
}
</script>
</body>
</html>