@canonical/summon-application 0.46.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -1
- package/dist/esm/application/react/templates/vite-plugin-ds-icons.ts +16 -2
- package/dist/esm/application/svelte/index.js +191 -0
- package/dist/esm/application/svelte/index.js.map +1 -0
- package/dist/esm/application/svelte/templates/.storybook/main.ts.ejs +2 -0
- package/dist/esm/application/svelte/templates/.storybook/preview.ts.ejs +3 -0
- package/dist/esm/application/svelte/templates/README.md.ejs +45 -0
- package/dist/esm/application/svelte/templates/gitignore.ejs +8 -0
- package/dist/esm/application/svelte/templates/package.json.ejs +40 -0
- package/dist/esm/application/svelte/templates/scripts/copy-icons.js.ejs +9 -0
- package/dist/esm/application/svelte/templates/src/app.d.ts.ejs +6 -0
- package/dist/esm/application/svelte/templates/src/app.html.ejs +11 -0
- package/dist/esm/application/svelte/templates/src/hooks.server.ts.ejs +13 -0
- package/dist/esm/application/svelte/templates/src/lib/ContactExample.stories.svelte.ejs +11 -0
- package/dist/esm/application/svelte/templates/src/lib/ContactExample.svelte.ejs +19 -0
- package/dist/esm/application/svelte/templates/src/lib/DashboardNavigation.svelte.ejs +17 -0
- package/dist/esm/application/svelte/templates/src/lib/ProjectDanger.svelte.ejs +18 -0
- package/dist/esm/application/svelte/templates/src/lib/Welcome.stories.svelte.ejs +5 -0
- package/dist/esm/application/svelte/templates/src/lib/catalog.ts.ejs +5 -0
- package/dist/esm/application/svelte/templates/src/lib/contact.ts.ejs +19 -0
- package/dist/esm/application/svelte/templates/src/lib/i18n.ts.ejs +351 -0
- package/dist/esm/application/svelte/templates/src/lib/instances.ts.ejs +16 -0
- package/dist/esm/application/svelte/templates/src/lib/resolveReturnTo.ts.ejs +11 -0
- package/dist/esm/application/svelte/templates/src/lib/settings.ts.ejs +28 -0
- package/dist/esm/application/svelte/templates/src/routes/+error.svelte.ejs +9 -0
- package/dist/esm/application/svelte/templates/src/routes/+layout.server.ts.ejs +2 -0
- package/dist/esm/application/svelte/templates/src/routes/+layout.svelte.ejs +85 -0
- package/dist/esm/application/svelte/templates/src/routes/+layout.ts.ejs +1 -0
- package/dist/esm/application/svelte/templates/src/routes/+page.svelte.ejs +9 -0
- package/dist/esm/application/svelte/templates/src/routes/account/+page.server.ts.ejs +13 -0
- package/dist/esm/application/svelte/templates/src/routes/account/+page.svelte.ejs +20 -0
- package/dist/esm/application/svelte/templates/src/routes/catalog/+page.svelte.ejs +12 -0
- package/dist/esm/application/svelte/templates/src/routes/catalog/[id]/+page.server.ts.ejs +8 -0
- package/dist/esm/application/svelte/templates/src/routes/catalog/[id]/+page.svelte.ejs +13 -0
- package/dist/esm/application/svelte/templates/src/routes/catalog/[id]/+page.ts.ejs +8 -0
- package/dist/esm/application/svelte/templates/src/routes/contact/+page.server.ts.ejs +11 -0
- package/dist/esm/application/svelte/templates/src/routes/contact/+page.svelte.ejs +85 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/+layout.svelte.ejs +15 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/+page.server.ts.ejs +5 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/+page.svelte.ejs +33 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/+page.server.ts.ejs +23 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/+page.svelte.ejs +101 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/remove/+page.server.ts.ejs +19 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/remove/+page.svelte.ejs +11 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/+page.server.ts.ejs +13 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/+page.svelte.ejs +52 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/confirm/+page.server.ts.ejs +2 -0
- package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/confirm/+page.svelte.ejs +13 -0
- package/dist/esm/application/svelte/templates/src/routes/home/+server.ts.ejs +2 -0
- package/dist/esm/application/svelte/templates/src/routes/language/+server.ts.ejs +12 -0
- package/dist/esm/application/svelte/templates/src/routes/login/+page.server.ts.ejs +8 -0
- package/dist/esm/application/svelte/templates/src/routes/login/+page.svelte.ejs +11 -0
- package/dist/esm/application/svelte/templates/src/routes/preferences/+server.ts.ejs +10 -0
- package/dist/esm/application/svelte/templates/src/routes/sitemap.xml/+server.ts.ejs +7 -0
- package/dist/esm/application/svelte/templates/src/styles.css.ejs +28 -0
- package/dist/esm/application/svelte/templates/svelte.config.js.ejs +7 -0
- package/dist/esm/application/svelte/templates/test/app.test.js.ejs +142 -0
- package/dist/esm/application/svelte/templates/test/contact.browser.test.js.ejs +279 -0
- package/dist/esm/application/svelte/templates/tsconfig.json.ejs +15 -0
- package/dist/esm/application/svelte/templates/vite.config.ts.ejs +4 -0
- package/dist/esm/domain/index.js +39 -5
- package/dist/esm/domain/index.js.map +1 -1
- package/dist/esm/domain/templates/Page.svelte.ejs +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/page/index.js +44 -7
- package/dist/esm/page/index.js.map +1 -1
- package/dist/esm/page/templates/Page.svelte.ejs +2 -0
- package/dist/esm/shared/versions.js +1 -1
- package/dist/esm/wrapper/index.js +38 -5
- package/dist/esm/wrapper/index.js.map +1 -1
- package/dist/esm/wrapper/templates/Layout.svelte.ejs +5 -0
- package/dist/types/application/svelte/index.d.ts +12 -0
- package/dist/types/application/svelte/index.d.ts.map +1 -0
- package/dist/types/domain/index.d.ts +2 -1
- package/dist/types/domain/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/page/index.d.ts +1 -0
- package/dist/types/page/index.d.ts.map +1 -1
- package/dist/types/shared/versions.d.ts +1 -1
- package/dist/types/wrapper/index.d.ts +2 -1
- package/dist/types/wrapper/index.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { fields, <%- spa ? 'decode, validate, ' : '' %>type Errors, type Values, type FieldName } from "$lib/contact";
|
|
3
|
+
<% if (intl) { %> import { getLocaleSource, getTranslator } from "$lib/i18n";
|
|
4
|
+
const locale = getLocaleSource();
|
|
5
|
+
let t = $derived(getTranslator($locale));
|
|
6
|
+
<% } else { %> const messages: Record<string, string> = { contact: "Contact", contactDemo: "Demo: no message is delivered.", spaContactDemo: "Client-only demo: no message is sent or stored.", sent: "Your message was received.", sentOlder: "Your earlier message was received; your current draft has not been sent.", invalidOlder: "Your earlier submission was invalid; your current draft has not been sent.", failed: "The result could not be confirmed. Please try again.", email: "Email", message: "Message", emailError: "Enter a valid email address.", messageError: "Enter a message.", tooLong: "Enter no more than 4000 characters.", sending: "Sending…", send: "Send", spaValidated: "The draft is valid. Nothing was sent." };
|
|
7
|
+
const t = (key: string) => messages[key] ?? key;
|
|
8
|
+
<% } %><% if (!spa) { %> import { enhance } from "$app/forms";
|
|
9
|
+
import type { SubmitFunction } from "@sveltejs/kit";
|
|
10
|
+
import { onDestroy } from "svelte";
|
|
11
|
+
import type { PageProps } from "./$types";
|
|
12
|
+
let { form }: PageProps = $props();
|
|
13
|
+
// svelte-ignore state_referenced_locally
|
|
14
|
+
let values = $state<Values>({ email: form?.values?.email ?? "", message: form?.values?.message ?? "" });
|
|
15
|
+
let pending = $state(false);
|
|
16
|
+
let notice = $state<"sentOlder" | "invalidOlder" | "failed" | "">("");
|
|
17
|
+
let edited = $state(false);
|
|
18
|
+
let editedFields = $state<Partial<Record<FieldName, boolean>>>({});
|
|
19
|
+
let enhancedResult = $state<{ success?: boolean; errors?: Errors } | undefined>();
|
|
20
|
+
let errors = $derived.by(() => {
|
|
21
|
+
const source = enhancedResult ? enhancedResult.errors : form?.errors;
|
|
22
|
+
return Object.fromEntries(Object.entries(source ?? {}).filter(([name]) => !editedFields[name as FieldName])) as Errors;
|
|
23
|
+
});
|
|
24
|
+
let revision = 0;
|
|
25
|
+
let generation = 0;
|
|
26
|
+
let active: AbortController | undefined;
|
|
27
|
+
onDestroy(() => { generation++; active?.abort(); });
|
|
28
|
+
function onEdit(event: Event) {
|
|
29
|
+
const target = event.target;
|
|
30
|
+
if (!(target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement)) return;
|
|
31
|
+
if (target.name !== "email" && target.name !== "message") return;
|
|
32
|
+
revision++; edited = true; editedFields[target.name] = true;
|
|
33
|
+
}
|
|
34
|
+
const submit: SubmitFunction<{ success: boolean }, { values: Values; errors: Errors }> = ({ cancel, controller, formData, formElement, submitter }) => {
|
|
35
|
+
if (pending) { cancel(); return; }
|
|
36
|
+
pending = true; notice = ""; active = controller;
|
|
37
|
+
const started = revision;
|
|
38
|
+
const currentGeneration = ++generation;
|
|
39
|
+
const captured = JSON.stringify([...formData.entries()]);
|
|
40
|
+
return ({ result }) => {
|
|
41
|
+
if (currentGeneration !== generation) return;
|
|
42
|
+
active = undefined; pending = false;
|
|
43
|
+
if (!formElement.isConnected) return;
|
|
44
|
+
const current = JSON.stringify([...new FormData(formElement, submitter).entries()]);
|
|
45
|
+
if (result.type === "error" || result.type === "redirect") { notice = "failed"; return; }
|
|
46
|
+
if (started !== revision || captured !== current) { notice = result.type === "success" ? "sentOlder" : "invalidOlder"; return; }
|
|
47
|
+
edited = false;
|
|
48
|
+
editedFields = {};
|
|
49
|
+
enhancedResult = result.type === "success" ? { success: true } : { errors: result.data?.errors };
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
<% } else { %> let errors = $state<Errors>({});
|
|
53
|
+
let submitted = $state(false);
|
|
54
|
+
function onEdit(event: Event) {
|
|
55
|
+
const target = event.target;
|
|
56
|
+
if (!(target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement)) return;
|
|
57
|
+
if (target.name !== "email" && target.name !== "message") return;
|
|
58
|
+
delete errors[target.name]; submitted = false;
|
|
59
|
+
}
|
|
60
|
+
function submit(event: SubmitEvent) {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
errors = validate(decode(new FormData(event.currentTarget as HTMLFormElement)));
|
|
63
|
+
submitted = !Object.keys(errors).length;
|
|
64
|
+
}
|
|
65
|
+
<% } %></script>
|
|
66
|
+
<svelte:head><title>{t("contact")} | <%= name %></title></svelte:head>
|
|
67
|
+
<h1>{t("contact")}</h1><p>{t(<%- spa ? '"spaContactDemo"' : '"contactDemo"' %>)}</p>
|
|
68
|
+
<% if (!spa) { %>{#if (enhancedResult?.success || (!enhancedResult && form?.success)) && !notice && !edited}<p role="status">{t("sent")}</p>{/if}
|
|
69
|
+
{#if notice}<p role="status">{t(notice)}</p>{/if}
|
|
70
|
+
<form method="POST" novalidate use:enhance={submit} oninput={onEdit} onchange={onEdit}>
|
|
71
|
+
<% } else { %>{#if submitted}<p role="status">{t("spaValidated")}</p>{/if}
|
|
72
|
+
<form onsubmit={submit} oninput={onEdit} onchange={onEdit} novalidate>
|
|
73
|
+
<% } %> {#each fields as field (field.name)}
|
|
74
|
+
<div class="field">
|
|
75
|
+
<label for={field.name}>{t(field.label)}</label>
|
|
76
|
+
{#if field.inputType === "textarea"}
|
|
77
|
+
<textarea id={field.name} name={field.name} required maxlength="4000" <% if (!spa) { %>bind:value={values[field.name]} <% } %>aria-invalid={errors?.[field.name] ? "true" : undefined} aria-describedby={errors?.[field.name] ? `${field.name}-error` : undefined}></textarea>
|
|
78
|
+
{:else}
|
|
79
|
+
<input id={field.name} name={field.name} type={field.inputType} required maxlength="4000" <% if (!spa) { %>bind:value={values[field.name]} <% } %>aria-invalid={errors?.[field.name] ? "true" : undefined} aria-describedby={errors?.[field.name] ? `${field.name}-error` : undefined} />
|
|
80
|
+
{/if}
|
|
81
|
+
{#if errors?.[field.name]}<p id={`${field.name}-error`}>{t(errors[field.name]!)}</p>{/if}
|
|
82
|
+
</div>
|
|
83
|
+
{/each}
|
|
84
|
+
<button type="submit"<% if (!spa) { %> disabled={pending}<% } %>>{t(<%- spa ? '"send"' : 'pending ? "sending" : "send"' %>)}</button>
|
|
85
|
+
</form>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { page } from "$app/state";
|
|
3
|
+
import { Breadcrumbs } from "@canonical/svelte-ds-global";
|
|
4
|
+
import type { LayoutProps } from "./$types";
|
|
5
|
+
let { children }: LayoutProps = $props();
|
|
6
|
+
<% if (intl) { %> import { getLocaleSource, getTranslator } from "$lib/i18n";
|
|
7
|
+
const locale = getLocaleSource(); let t = $derived(getTranslator($locale));
|
|
8
|
+
<% } else { %> const labels: Record<string, string> = { dashboard: "Dashboard", instances: "Instances", settings: "Settings", confirmRemove: "Confirm removal", confirmProject: "Confirm project deletion" };
|
|
9
|
+
const t = (key: string) => labels[key] ?? key;
|
|
10
|
+
<% } %> let path = $derived(page.url.pathname);
|
|
11
|
+
let crumb = $derived(path.endsWith("/remove") ? "confirmRemove" : path.endsWith("/settings/confirm") ? "confirmProject" : path.split("/").at(-1) ?? "dashboard");
|
|
12
|
+
let crumbs = $derived([{ label: t("dashboard"), url: "/dashboard" }, ...(path.endsWith("/remove") ? [{ label: t("instances"), url: "/dashboard/instances" }] : path.endsWith("/settings/confirm") ? [{ label: t("settings"), url: "/dashboard/settings" }] : []), { key: "current", label: t(crumb), current: true }]);
|
|
13
|
+
</script>
|
|
14
|
+
{#if path !== "/dashboard"}<Breadcrumbs items={crumbs} />{/if}
|
|
15
|
+
{@render children()}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<% if (forms) { %>import { readSettings } from "$lib/settings";
|
|
2
|
+
import { readInstances } from "$lib/instances";
|
|
3
|
+
<% } %>
|
|
4
|
+
import type { PageServerLoad } from "./$types";
|
|
5
|
+
export const load: PageServerLoad = ({ cookies }) => ({ name: <%- forms ? 'readSettings(cookies.get("demo-settings")).name' : '"Demo"' %>, count: <%- forms ? 'readInstances(cookies.get("demo-instances")).length' : '0' %> });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
<% if (!spa) { %> import type { PageProps } from "./$types";
|
|
3
|
+
let { data }: PageProps = $props();
|
|
4
|
+
<% } else if (forms) { %> import { onMount } from "svelte";
|
|
5
|
+
import { readSettings } from "$lib/settings";
|
|
6
|
+
import { readInstances } from "$lib/instances";
|
|
7
|
+
let name = $state("Demo"); let count = $state(0);
|
|
8
|
+
onMount(() => { name = readSettings(localStorage.getItem("demo-settings") ?? undefined).name; count = readInstances(localStorage.getItem("demo-instances") ?? undefined).length; });
|
|
9
|
+
<% } else { %> const name = "Demo", count = 0;
|
|
10
|
+
<% } %><% if (intl) { %> import { getLocaleSource, getTranslator } from "$lib/i18n";
|
|
11
|
+
const locale = getLocaleSource(); let t = $derived(getTranslator($locale));
|
|
12
|
+
<% } %> let storage = $derived(new Intl.NumberFormat(<%- intl ? '$locale' : '"en"' %>, { style: "unit", unit: "terabyte", maximumFractionDigits: 1 }));
|
|
13
|
+
let relative = $derived(new Intl.RelativeTimeFormat(<%- intl ? '$locale' : '"en"' %>, { numeric: "auto" }));
|
|
14
|
+
const events = [{ key: "activityStart", value: -2, unit: "minute" }, { key: "activitySnapshot", value: -14, unit: "minute" }, { key: "activityWarning", value: -1, unit: "hour" }, { key: "activityProfile", value: -1, unit: "day" }, { key: "activityFailed", value: -2, unit: "day" }] as const;
|
|
15
|
+
<% if (!intl) { %> const activities: Record<string, string> = { activityStart: "Alice started web-01", activitySnapshot: "Scheduler created a snapshot", activityWarning: "Monitor reported a disk warning", activityProfile: "Bob updated profile gpu", activityFailed: "Monitor reported cache-01 failed to start" };
|
|
16
|
+
<% } %></script>
|
|
17
|
+
<svelte:head><title><%- intl ? '{t("dashboard")}' : 'Dashboard' %> | <%= name %></title></svelte:head>
|
|
18
|
+
<h1><%- intl ? '{t("dashboard")}' : 'Dashboard' %></h1>
|
|
19
|
+
<p><%- intl ? `{t("welcomeName", { name: ${spa ? 'name' : 'data.name'} })}` : `Welcome, {${spa ? 'name' : 'data.name'}}.` %></p>
|
|
20
|
+
<p><%- intl ? '{t("demo")}' : 'This is a demonstration dashboard.' %></p>
|
|
21
|
+
<% if (forms) { %><p><a href="/dashboard/instances?create=1"><%- intl ? '{t("createInstance")}' : 'Create demo instance' %></a></p>
|
|
22
|
+
<% } %>
|
|
23
|
+
<div class="dashboard-overview"><div><section aria-labelledby="dashboard-resources"><h2 id="dashboard-resources"><%- intl ? '{t("overview")}' : 'Overview' %></h2>
|
|
24
|
+
<ul class="instance-cards"><li><article class="instance-card"><h3><%- intl ? '{t("instances")}' : 'Instances' %></h3><p>{new Intl.NumberFormat(<%- intl ? '$locale' : '"en"' %>).format(<%- spa ? 'count' : 'data.count' %>)}</p><a href="/dashboard/instances"><%- intl ? '{t("instances")}' : 'Instances' %></a></article></li>
|
|
25
|
+
<li><article class="instance-card"><h3><%- intl ? '{t("settings")}' : 'Settings' %></h3><a href="/dashboard/settings"><%- intl ? '{t("settings")}' : 'Settings' %></a></article></li>
|
|
26
|
+
<li><article class="instance-card"><h3><%- intl ? '{t("catalog")}' : 'Catalog' %></h3><a href="/catalog"><%- intl ? '{t("catalog")}' : 'Browse the catalog' %></a></article></li></ul></section>
|
|
27
|
+
<section aria-labelledby="sample-status"><h2 id="sample-status"><%- intl ? '{t("sampleStatus")}' : 'Sample status' %></h2><p><%- intl ? '{t("sampleData")}' : 'Illustrative data; not the instances saved in this browser.' %></p>
|
|
28
|
+
<ul class="instance-cards"><% if (intl) { %>{#each [{ label: "running", value: 128 }, { label: "stopped", value: 4 }, { label: "alerts", value: 2 }] as item}<li><article class="instance-card"><h3>{t(item.label)}</h3><p>{new Intl.NumberFormat($locale).format(item.value)}</p></article></li>{/each}<% } else { %>{#each [{ label: "Running", value: 128 }, { label: "Stopped", value: 4 }, { label: "Alerts", value: 2 }] as item}<li><article class="instance-card"><h3>{item.label}</h3><p>{item.value}</p></article></li>{/each}<% } %><li><article class="instance-card"><h3><%- intl ? '{t("sampleStorage")}' : 'Storage' %></h3><p>{storage.format(2.4)}</p><p><%- intl ? '{t("storageOf", { total: storage.format(4) })}' : 'of {storage.format(4)} used' %></p></article></li></ul>
|
|
29
|
+
</section>
|
|
30
|
+
<section aria-labelledby="releases-title"><h2 id="releases-title"><%- intl ? '{t("releases")}' : 'Releases' %></h2>
|
|
31
|
+
<ul class="instance-cards">{#each [{ name: "Ubuntu 24.04 LTS", code: "noble" }, { name: "Ubuntu 22.04 LTS", code: "jammy" }, { name: "Ubuntu 20.04 LTS", code: "focal" }] as release}<li><article class="instance-card"><h3>{release.name}</h3><p><%- intl ? '{t("releaseInfo")}' : 'Available release' %></p><p><a href="https://ubuntu.com/about/release-cycle"><%- intl ? '{t("releaseNotes")}' : 'Release notes' %></a></p><% if (forms) { %><a href={`/dashboard/instances?create=1&release=${release.code}`}><%- intl ? '{t("launch")}' : 'Create an instance' %></a><% } %></article></li>{/each}</ul>
|
|
32
|
+
</section>
|
|
33
|
+
</div><aside class="activity-panel" aria-labelledby="activity-title"><h2 id="activity-title"><%- intl ? '{t("activity")}' : 'Sample activity' %></h2><ol>{#each events as event (event.key)}<li><p><%- intl ? '{t(event.key)}' : '{activities[event.key]}' %></p><p>{relative.format(event.value, event.unit)}</p></li>{/each}</ol></aside></div>
|
package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/+page.server.ts.ejs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { fail, redirect } from "@sveltejs/kit";
|
|
2
|
+
import { readInstances, releases, isValidInstance } from "$lib/instances";
|
|
3
|
+
import type { Actions, PageServerLoad } from "./$types";
|
|
4
|
+
|
|
5
|
+
export const load: PageServerLoad = ({ cookies, url }) => {
|
|
6
|
+
const instances = readInstances(cookies.get("demo-instances"));
|
|
7
|
+
return { instances, selected: instances.find((instance) => instance.name === url.searchParams.get("selected")), create: url.searchParams.get("create") === "1", release: releases.find((item) => item === url.searchParams.get("release")) ?? "noble" };
|
|
8
|
+
};
|
|
9
|
+
export const actions: Actions = {
|
|
10
|
+
create: async ({ request, cookies, url }) => {
|
|
11
|
+
const data = await request.formData();
|
|
12
|
+
const name = data.get("name"), release = data.get("release"), cloudInit = data.get("cloudInit");
|
|
13
|
+
const values = { name: typeof name === "string" ? name : "", release: typeof release === "string" ? release : "", pro: data.get("pro") === "on", cloudInit: typeof cloudInit === "string" ? cloudInit : "" };
|
|
14
|
+
const instances = readInstances(cookies.get("demo-instances"));
|
|
15
|
+
if (!isValidInstance(values)) return fail(400, { values, issue: "instanceInvalid" });
|
|
16
|
+
if (instances.some((instance) => instance.name === values.name)) return fail(400, { values, issue: "instanceDuplicate" });
|
|
17
|
+
if (instances.length >= 10) return fail(400, { values, issue: "instanceLimit" });
|
|
18
|
+
const payload = JSON.stringify([...instances, values]);
|
|
19
|
+
if (encodeURIComponent(payload).length > 3000) return fail(400, { values, issue: "instanceLimit" });
|
|
20
|
+
cookies.set("demo-instances", payload, { path: "/", sameSite: "lax", httpOnly: true, secure: url.protocol === "https:", maxAge: 86400 });
|
|
21
|
+
redirect(303, `/dashboard/instances?selected=${encodeURIComponent(values.name)}`);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
<% if (intl) { %> import { getLocaleSource, getTranslator } from "$lib/i18n";
|
|
3
|
+
const locale = getLocaleSource(); let t = $derived(getTranslator($locale));
|
|
4
|
+
<% } else { %> const messages: Record<string, string> = { instances: "Instances", instancesDemo: "Demo instances are stored only in this browser's cookie; they are not provisioned.", sampleInstancesDemo: "These are sample instances only.", instanceEmpty: "No demo instances yet.", createInstance: "Create demo instance", instanceName: "Instance name", release: "Release", instanceStatus: "Status", demoStatus: "Demo only", instanceAddress: "Address", instanceMemory: "Memory", enablePro: "Enable Pro", cloudInit: "Cloud-init", yes: "Yes", no: "No", removeInstance: "Remove demo instance", instanceInvalid: "Use a lowercase name with letters, numbers or hyphens (maximum 40) and choose a valid release.", instanceDuplicate: "That instance name already exists.", instanceLimit: "The demo can contain at most 10 instances.", compute: "Compute", storage: "Storage", sample: "Sample" };
|
|
5
|
+
const t = (key: string) => messages[key] ?? key;
|
|
6
|
+
<% } %><% if (forms && !spa) { %> import type { PageProps } from "./$types";
|
|
7
|
+
let { data, form }: PageProps = $props();
|
|
8
|
+
let confirming = $state(false);
|
|
9
|
+
let removeLink = $state<HTMLAnchorElement>();
|
|
10
|
+
<% } %><% if (forms) { %> import { Modal } from "@canonical/svelte-ds-global";
|
|
11
|
+
import { onMount } from "svelte";
|
|
12
|
+
let panel = $state<HTMLDetailsElement>();
|
|
13
|
+
let enhanced = $state(false);
|
|
14
|
+
onMount(() => { enhanced = true; });
|
|
15
|
+
function closePanel() { if (panel) { const restore = panel.contains(document.activeElement); panel.open = false; if (restore) panel.querySelector("summary")?.focus(); } }
|
|
16
|
+
function openPanel() { if (enhanced && panel && !panel.open) requestAnimationFrame(() => { if (panel?.open && panel.querySelector("summary") === document.activeElement) panel.querySelector<HTMLInputElement>("#instance-name")?.focus(); }); }
|
|
17
|
+
function handleGlobalKeydown(event: KeyboardEvent) { if (event.key === "Escape" && panel?.open && panel.contains(event.target as Node)) { event.preventDefault(); closePanel(); } }
|
|
18
|
+
<% } %><% if (forms && spa) { %> import { page } from "$app/state";
|
|
19
|
+
import { readInstances, releases, isValidInstance, type Instance } from "$lib/instances";
|
|
20
|
+
let requestedCreate = $derived(page.url.searchParams.get("create") === "1");
|
|
21
|
+
let requestedRelease = $derived(releases.find((item) => item === page.url.searchParams.get("release")) ?? "noble");
|
|
22
|
+
let instances = $state<Instance[]>([]);
|
|
23
|
+
let selected = $state<string | undefined>();
|
|
24
|
+
let issue = $state("");
|
|
25
|
+
let confirm = $state(false);
|
|
26
|
+
let opener = $state<HTMLButtonElement>();
|
|
27
|
+
onMount(() => { instances = readInstances(localStorage.getItem("demo-instances") ?? undefined); });
|
|
28
|
+
function create(event: SubmitEvent) {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
const data = new FormData(event.currentTarget as HTMLFormElement);
|
|
31
|
+
const values = { name: String(data.get("name") ?? ""), release: String(data.get("release") ?? ""), pro: data.has("pro"), cloudInit: String(data.get("cloudInit") ?? "") };
|
|
32
|
+
issue = !isValidInstance(values) ? "instanceInvalid" : instances.some((item) => item.name === values.name) ? "instanceDuplicate" : instances.length >= 10 ? "instanceLimit" : "";
|
|
33
|
+
if (issue || !isValidInstance(values)) return;
|
|
34
|
+
const next = [...instances, values];
|
|
35
|
+
if (encodeURIComponent(JSON.stringify(next)).length > 3000) { issue = "instanceLimit"; return; }
|
|
36
|
+
localStorage.setItem("demo-instances", JSON.stringify(next)); instances = next; selected = values.name; closePanel();
|
|
37
|
+
}
|
|
38
|
+
function openDialog() { confirm = true; }
|
|
39
|
+
function closeDialog() { confirm = false; }
|
|
40
|
+
function remove() {
|
|
41
|
+
instances = instances.filter((item) => item.name !== selected);
|
|
42
|
+
localStorage.setItem("demo-instances", JSON.stringify(instances)); selected = undefined;
|
|
43
|
+
confirm = false; document.getElementById("instance-create-toggle")?.focus();
|
|
44
|
+
}
|
|
45
|
+
<% } %></script>
|
|
46
|
+
<% if (forms) { %><svelte:window onkeydown={handleGlobalKeydown} />
|
|
47
|
+
<% } %>
|
|
48
|
+
<svelte:head><title>{t("instances")} | <%= name %></title></svelte:head>
|
|
49
|
+
<h1>{t("instances")}</h1>
|
|
50
|
+
<p><%- forms && spa ? (intl ? '{t("spaInstancesDemo")}' : 'Demo instances are stored only in this browser; they are not provisioned.') : forms ? '{t("instancesDemo")}' : '{t("sampleInstancesDemo")}' %></p>
|
|
51
|
+
<% if (forms && !spa) { %><div class="instance-layout"><div>{#if data.instances.length}
|
|
52
|
+
<ul class="instance-cards">{#each data.instances as instance (instance.name)}<li><article class="instance-card"><h2><a href={`/dashboard/instances?selected=${encodeURIComponent(instance.name)}`} aria-current={data.selected?.name === instance.name ? "true" : undefined}>{instance.name}</a></h2><p>{t("release")}: {instance.release}</p></article></li>{/each}</ul>
|
|
53
|
+
{:else}<p>{t("instanceEmpty")}</p>{/if}
|
|
54
|
+
{#if data.selected}
|
|
55
|
+
<section aria-labelledby="instance-details"><h2 id="instance-details">{data.selected.name}</h2>
|
|
56
|
+
<dl><dt>{t("instanceStatus")}</dt><dd>{t("demoStatus")}</dd><dt>{t("release")}</dt><dd>{data.selected.release}</dd><dt>{t("instanceAddress")}</dt><dd>—</dd><dt>{t("instanceMemory")}</dt><dd>—</dd><dt>{t("enablePro")}</dt><dd>{t(data.selected.pro ? "yes" : "no")}</dd><dt>{t("cloudInit")}</dt><dd><pre>{data.selected.cloudInit || "—"}</pre></dd></dl>
|
|
57
|
+
<a bind:this={removeLink} href={`/dashboard/instances/remove?name=${encodeURIComponent(data.selected.name)}`} onclick={(event) => { if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; event.preventDefault(); confirming = true; }}>{t("removeInstance")}</a>
|
|
58
|
+
</section>
|
|
59
|
+
<Modal bind:open={confirming} onclose={() => removeLink?.focus()}>
|
|
60
|
+
<Modal.Header closeButton={false}><h2><%- intl ? '{t("confirmRemove")}' : 'Confirm removal' %></h2></Modal.Header>
|
|
61
|
+
<Modal.Content><p><%- intl ? '{t("confirmRemoveBody", { name: data.selected.name })}' : 'Remove demo instance {data.selected.name}?' %></p></Modal.Content>
|
|
62
|
+
<Modal.Footer><button type="button" onclick={() => confirming = false}><%- intl ? '{t("cancel")}' : 'Cancel' %></button><form method="POST" action={`/dashboard/instances/remove?name=${encodeURIComponent(data.selected.name)}`}><input type="hidden" name="name" value={data.selected.name} /><button type="submit">{t("removeInstance")}</button></form></Modal.Footer>
|
|
63
|
+
</Modal>
|
|
64
|
+
{:else}<p><%- intl ? '{t("selectInstance")}' : 'Select an instance to view its details.' %></p>
|
|
65
|
+
{/if}
|
|
66
|
+
</div><aside class:enhanced class="instance-panel" aria-label={t("createInstance")}><details bind:this={panel} open={!!form?.issue || data.create}><summary id="instance-create-toggle" onclick={openPanel}>{t("createInstance")}</summary><div class="instance-panel-content">
|
|
67
|
+
{#if enhanced}<button type="button" onclick={closePanel}><%- intl ? '{t("cancel")}' : 'Cancel' %></button>{/if}
|
|
68
|
+
{#if form?.issue}<p role="alert">{t(form.issue)}</p>{/if}
|
|
69
|
+
<form method="POST" action="?/create" novalidate>
|
|
70
|
+
<div class="field"><label for="instance-name">{t("instanceName")}</label><input id="instance-name" name="name" value={form?.values?.name ?? ""} maxlength="40" required /></div>
|
|
71
|
+
<div class="field"><label for="instance-release">{t("release")}</label><select id="instance-release" name="release" value={form?.values?.release ?? data.release}><option value="noble">Ubuntu 24.04 LTS</option><option value="jammy">Ubuntu 22.04 LTS</option><option value="focal">Ubuntu 20.04 LTS</option></select></div>
|
|
72
|
+
<label><input type="checkbox" name="pro" checked={form?.values?.pro ?? false} /> {t("enablePro")}</label>
|
|
73
|
+
<div class="field"><label for="instance-cloud">{t("cloudInit")}</label><textarea id="instance-cloud" name="cloudInit" maxlength="1000">{form?.values?.cloudInit ?? ""}</textarea></div>
|
|
74
|
+
<button type="submit">{t("createInstance")}</button>
|
|
75
|
+
</form>
|
|
76
|
+
</div></details></aside></div>
|
|
77
|
+
<% } else if (forms && spa) { %><div class="instance-layout"><div>{#if instances.length}<ul class="instance-cards">{#each instances as instance (instance.name)}<li><article class="instance-card"><h2><button type="button" aria-pressed={selected === instance.name} onclick={() => selected = instance.name}>{instance.name}</button></h2><p>{t("release")}: {instance.release}</p></article></li>{/each}</ul>{:else}<p>{t("instanceEmpty")}</p>{/if}
|
|
78
|
+
{#each instances.filter((item) => item.name === selected) as instance (instance.name)}
|
|
79
|
+
<section aria-labelledby="instance-details"><h2 id="instance-details">{instance.name}</h2><dl><dt>{t("instanceStatus")}</dt><dd>{t("demoStatus")}</dd><dt>{t("release")}</dt><dd>{instance.release}</dd><dt>{t("instanceAddress")}</dt><dd>—</dd><dt>{t("instanceMemory")}</dt><dd>—</dd><dt>{t("enablePro")}</dt><dd>{t(instance.pro ? "yes" : "no")}</dd><dt>{t("cloudInit")}</dt><dd><pre>{instance.cloudInit || "—"}</pre></dd></dl>
|
|
80
|
+
<button type="button" bind:this={opener} onclick={openDialog}>{t("removeInstance")}</button>
|
|
81
|
+
</section>
|
|
82
|
+
{/each}
|
|
83
|
+
{#if !selected}<p><%- intl ? '{t("selectInstance")}' : 'Select an instance to view its details.' %></p>{/if}
|
|
84
|
+
<Modal bind:open={confirm} onclose={() => { if (selected) opener?.focus(); }}>
|
|
85
|
+
<Modal.Header closeButton={false}><h2><%- intl ? '{t("confirmRemove")}' : 'Confirm removal' %></h2></Modal.Header>
|
|
86
|
+
<Modal.Content><p><%- intl ? '{t("confirmRemoveBody", { name: selected ?? "" })}' : 'Remove demo instance {selected}?' %></p></Modal.Content>
|
|
87
|
+
<Modal.Footer><button type="button" onclick={closeDialog}><%- intl ? '{t("cancel")}' : 'Cancel' %></button><button type="button" onclick={remove}>{t("removeInstance")}</button></Modal.Footer>
|
|
88
|
+
</Modal>
|
|
89
|
+
</div><aside class:enhanced class="instance-panel" aria-label={t("createInstance")}><details bind:this={panel} open={requestedCreate}><summary id="instance-create-toggle" onclick={openPanel}>{t("createInstance")}</summary><div class="instance-panel-content">
|
|
90
|
+
{#if enhanced}<button type="button" onclick={closePanel}><%- intl ? '{t("cancel")}' : 'Cancel' %></button>{/if}
|
|
91
|
+
{#if issue}<p role="alert">{t(issue)}</p>{/if}
|
|
92
|
+
<form onsubmit={create} novalidate>
|
|
93
|
+
<div class="field"><label for="instance-name">{t("instanceName")}</label><input id="instance-name" name="name" maxlength="40" required /></div>
|
|
94
|
+
<div class="field"><label for="instance-release">{t("release")}</label><select id="instance-release" name="release" value={requestedRelease}><option value="noble">Ubuntu 24.04 LTS</option><option value="jammy">Ubuntu 22.04 LTS</option><option value="focal">Ubuntu 20.04 LTS</option></select></div>
|
|
95
|
+
<label><input type="checkbox" name="pro" /> {t("enablePro")}</label>
|
|
96
|
+
<div class="field"><label for="instance-cloud">{t("cloudInit")}</label><textarea id="instance-cloud" name="cloudInit" maxlength="1000"></textarea></div>
|
|
97
|
+
<button type="submit">{t("createInstance")}</button>
|
|
98
|
+
</form>
|
|
99
|
+
</div></details></aside></div>
|
|
100
|
+
<% } else { %><ul><li>{t("compute")} — {t("sample")}</li><li>{t("storage")} — {t("sample")}</li></ul>
|
|
101
|
+
<% } %>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { error, redirect } from "@sveltejs/kit";
|
|
2
|
+
import { readInstances } from "$lib/instances";
|
|
3
|
+
import type { Actions, PageServerLoad } from "./$types";
|
|
4
|
+
export const load: PageServerLoad = ({ url, cookies }) => {
|
|
5
|
+
const instance = readInstances(cookies.get("demo-instances")).find((item) => item.name === url.searchParams.get("name"));
|
|
6
|
+
if (!instance) error(404, "Instance not found");
|
|
7
|
+
return { instance };
|
|
8
|
+
};
|
|
9
|
+
export const actions: Actions = {
|
|
10
|
+
default: async ({ request, cookies, url }) => {
|
|
11
|
+
const data = await request.formData();
|
|
12
|
+
const names = data.getAll("name");
|
|
13
|
+
const name = names.length === 1 ? names[0] : null;
|
|
14
|
+
const instances = readInstances(cookies.get("demo-instances"));
|
|
15
|
+
if (typeof name !== "string" || !instances.some((item) => item.name === name)) error(404, "Instance not found");
|
|
16
|
+
cookies.set("demo-instances", JSON.stringify(instances.filter((item) => item.name !== name)), { path: "/", sameSite: "lax", httpOnly: true, secure: url.protocol === "https:", maxAge: 86400 });
|
|
17
|
+
redirect(303, "/dashboard/instances");
|
|
18
|
+
},
|
|
19
|
+
};
|
package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/remove/+page.svelte.ejs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { PageProps } from "./$types";
|
|
3
|
+
let { data }: PageProps = $props();
|
|
4
|
+
<% if (intl) { %> import { getLocaleSource, getTranslator } from "$lib/i18n";
|
|
5
|
+
const locale = getLocaleSource(); let t = $derived(getTranslator($locale));
|
|
6
|
+
<% } %></script>
|
|
7
|
+
<svelte:head><title><%- intl ? '{t("confirmRemove")}' : 'Confirm removal' %> | <%= name %></title></svelte:head>
|
|
8
|
+
<h1><%- intl ? '{t("confirmRemove")}' : 'Confirm removal' %></h1>
|
|
9
|
+
<p><%- intl ? '{t("confirmRemoveBody", { name: data.instance.name })}' : 'Remove demo instance {data.instance.name}?' %></p>
|
|
10
|
+
<form method="POST"><input type="hidden" name="name" value={data.instance.name} /><button type="submit"><%- intl ? '{t("removeInstance")}' : 'Remove demo instance' %></button></form>
|
|
11
|
+
<a href={`/dashboard/instances?selected=${encodeURIComponent(data.instance.name)}`}><%- intl ? '{t("cancel")}' : 'Cancel' %></a>
|
package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/+page.server.ts.ejs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { fail } from "@sveltejs/kit";
|
|
2
|
+
import { decodeSettings, readSettings, validateSettings } from "$lib/settings";
|
|
3
|
+
import type { Actions, PageServerLoad } from "./$types";
|
|
4
|
+
export const load: PageServerLoad = ({ cookies }) => ({ settings: readSettings(cookies.get("demo-settings")) });
|
|
5
|
+
export const actions: Actions = {
|
|
6
|
+
default: async ({ request, cookies, url }) => {
|
|
7
|
+
const values = decodeSettings(await request.formData());
|
|
8
|
+
const errors = validateSettings(values);
|
|
9
|
+
if (Object.keys(errors).length) return fail(400, { values, errors });
|
|
10
|
+
cookies.set("demo-settings", JSON.stringify(values), { path: "/", sameSite: "lax", httpOnly: true, secure: url.protocol === "https:", maxAge: 31536000 });
|
|
11
|
+
return { values, saved: true };
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import ProjectDanger from "$lib/ProjectDanger.svelte";
|
|
3
|
+
<% if (forms) { %> import { settingsFields<% if (spa) { %>, decodeSettings, readSettings, validateSettings, defaults, type Settings<% } %> } from "$lib/settings";
|
|
4
|
+
<% if (!spa) { %> import type { PageProps } from "./$types";
|
|
5
|
+
let { data, form }: PageProps = $props();
|
|
6
|
+
let values = $derived(form?.values ?? data.settings);
|
|
7
|
+
let errors = $derived(form && "errors" in form ? form.errors : {});
|
|
8
|
+
<% } else { %> import { onMount } from "svelte";
|
|
9
|
+
let values = $state<Settings>({ ...defaults });
|
|
10
|
+
let errors = $state<{ name?: string; bridge?: string; maxInstances?: string }>({});
|
|
11
|
+
let saved = $state(false);
|
|
12
|
+
onMount(() => { values = readSettings(localStorage.getItem("demo-settings") ?? undefined); });
|
|
13
|
+
function submit(event: SubmitEvent) {
|
|
14
|
+
event.preventDefault();
|
|
15
|
+
const next = decodeSettings(new FormData(event.currentTarget as HTMLFormElement));
|
|
16
|
+
errors = validateSettings(next);
|
|
17
|
+
saved = !Object.keys(errors).length;
|
|
18
|
+
if (saved) { localStorage.setItem("demo-settings", JSON.stringify(next)); values = next; }
|
|
19
|
+
}
|
|
20
|
+
<% } %><% } %><% if (intl) { %> import { getLocaleSource, getTranslator } from "$lib/i18n";
|
|
21
|
+
const locale = getLocaleSource(); let t = $derived(getTranslator($locale));
|
|
22
|
+
<% } else { %> const messages: Record<string, string> = { settings: "Settings", settingsDemo: "These settings are stored locally for this demonstration.", saved: "Settings saved.", displayName: "Display name", nameError: "Enter a display name.", nameTooLong: "Enter no more than 60 characters.", bridge: "Bridge", bridgeError: "Choose a valid bridge.", ipv6: "Enable IPv6", snapshots: "Enable snapshots", maxInstances: "Instance limit", maximumError: "Enter a number from 1 to 100.", save: "Save", demo: "This is a demonstration dashboard." };
|
|
23
|
+
const t = (key: string) => messages[key] ?? key;
|
|
24
|
+
<% } %></script>
|
|
25
|
+
<svelte:head><title>{t("settings")} | <%= name %></title></svelte:head>
|
|
26
|
+
<h1>{t("settings")}</h1>
|
|
27
|
+
<% if (forms) { %><p>{t("settingsDemo")}</p>
|
|
28
|
+
{#if <%- spa ? 'saved' : 'form?.saved' %>}<p role="status">{t("saved")}</p>{/if}
|
|
29
|
+
{#if errors && Object.keys(errors).length}<section aria-labelledby="settings-errors"><h2 id="settings-errors"><%- intl ? '{t("reviewErrors")}' : 'Review errors' %></h2><ul>{#each Object.entries(errors) as [name, message]}<li><a href={`#${name}`}>{t(message)}</a></li>{/each}</ul></section>{/if}
|
|
30
|
+
<form <%- spa ? 'onsubmit={submit}' : 'method="POST"' %> novalidate>
|
|
31
|
+
{#each settingsFields as field (field.name)}
|
|
32
|
+
<div class="field">
|
|
33
|
+
<label for={field.name}>{t(field.label)}</label>
|
|
34
|
+
{#if field.inputType === "switch"}
|
|
35
|
+
<input id={field.name} name={field.name} type="checkbox" role="switch" checked={values[field.name]} />
|
|
36
|
+
{:else if field.inputType === "select"}
|
|
37
|
+
<select id={field.name} name={field.name} value={values[field.name]} aria-invalid={errors?.bridge ? "true" : undefined} aria-describedby={errors?.bridge ? "bridge-error" : undefined}>{#each field.options as option}<option value={option.value}>{option.label}</option>{/each}</select>
|
|
38
|
+
{#if errors?.bridge}<p id="bridge-error">{t(errors.bridge)}</p>{/if}
|
|
39
|
+
{:else if field.inputType === "number"}
|
|
40
|
+
<input id={field.name} name={field.name} type="number" value={values[field.name]} min="1" max="100" step="1" required aria-invalid={errors?.maxInstances ? "true" : undefined} aria-describedby={errors?.maxInstances ? "maxInstances-error" : undefined} />
|
|
41
|
+
{#if errors?.maxInstances}<p id="maxInstances-error">{t(errors.maxInstances)}</p>{/if}
|
|
42
|
+
{:else}
|
|
43
|
+
<input id={field.name} name={field.name} type="text" value={values[field.name]} maxlength="60" required aria-invalid={errors?.name ? "true" : undefined} aria-describedby={errors?.name ? "name-error" : undefined} />
|
|
44
|
+
{#if errors?.name}<p id="name-error">{t(errors.name)}</p>{/if}
|
|
45
|
+
{/if}
|
|
46
|
+
</div>
|
|
47
|
+
{/each}
|
|
48
|
+
<button type="submit">{t("save")}</button>
|
|
49
|
+
</form>
|
|
50
|
+
<% } else { %><p>{t("demo")}</p>
|
|
51
|
+
<% } %>
|
|
52
|
+
<ProjectDanger />
|
package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/confirm/+page.svelte.ejs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
<% if (!spa) { %> import type { PageProps } from "./$types";
|
|
3
|
+
let { form }: PageProps = $props();
|
|
4
|
+
<% } else { %> let confirmed = $state(false);
|
|
5
|
+
<% } %><% if (intl) { %> import { getLocaleSource, getTranslator } from "$lib/i18n";
|
|
6
|
+
const locale = getLocaleSource(); let t = $derived(getTranslator($locale));
|
|
7
|
+
<% } else { %> const messages: Record<string, string> = { confirmProject: "Confirm project deletion", deleteProjectBody: "This is a demonstration; no project will be deleted.", confirmedProject: "Demonstration confirmed; no project was deleted.", deleteProject: "Delete demo project", cancel: "Cancel" };
|
|
8
|
+
const t = (key: string) => messages[key] ?? key;
|
|
9
|
+
<% } %></script>
|
|
10
|
+
<svelte:head><title>{t("confirmProject")} | <%= name %></title></svelte:head>
|
|
11
|
+
<h1>{t("confirmProject")}</h1><p>{t("deleteProjectBody")}</p>
|
|
12
|
+
{#if <%- spa ? 'confirmed' : 'form?.confirmed' %>}<p role="status">{t("confirmedProject")}</p>{:else}<form <%- spa ? 'onsubmit={(event) => { event.preventDefault(); confirmed = true; }}' : 'method="POST"' %>><button type="submit">{t("deleteProject")}</button></form>{/if}
|
|
13
|
+
<a href="/dashboard/settings">{t("cancel")}</a>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { redirect } from "@sveltejs/kit";
|
|
2
|
+
import { config } from "$lib/i18n";
|
|
3
|
+
import { resolveReturnTo } from "$lib/resolveReturnTo";
|
|
4
|
+
import type { RequestHandler } from "./$types";
|
|
5
|
+
|
|
6
|
+
export const POST: RequestHandler = async ({ request, cookies, url }) => {
|
|
7
|
+
const locale = (await request.formData()).get("locale");
|
|
8
|
+
if (typeof locale === "string" && config.locales.includes(locale)) {
|
|
9
|
+
cookies.set("locale", locale, { path: "/", sameSite: "lax", secure: url.protocol === "https:", maxAge: 31536000 });
|
|
10
|
+
}
|
|
11
|
+
redirect(303, resolveReturnTo(request.headers.get("referer"), url));
|
|
12
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { redirect } from "@sveltejs/kit";
|
|
2
|
+
import type { Actions } from "./$types";
|
|
3
|
+
export const actions: Actions = {
|
|
4
|
+
default: ({ cookies, url }) => {
|
|
5
|
+
cookies.set("demo-session", "yes", { path: "/", httpOnly: true, sameSite: "lax", secure: url.protocol === "https:" });
|
|
6
|
+
redirect(303, "/account");
|
|
7
|
+
},
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
<% if (spa) { %> import { goto } from "$app/navigation";
|
|
3
|
+
function enter() { sessionStorage.setItem("demo-session", "yes"); void goto("/account"); }
|
|
4
|
+
<% } %><% if (intl) { %> import { getLocaleSource, getTranslator } from "$lib/i18n";
|
|
5
|
+
const locale = getLocaleSource(); let t = $derived(getTranslator($locale));
|
|
6
|
+
<% } %>
|
|
7
|
+
</script>
|
|
8
|
+
<svelte:head><title><%- intl ? '{t("login")}' : 'Login' %> | <%= name %></title></svelte:head>
|
|
9
|
+
<h1><%- intl ? '{t("login")}' : 'Login' %></h1>
|
|
10
|
+
<p><%- intl ? '{t("demoWarning")}' : 'This demonstration does not authenticate users or protect real data.' %></p>
|
|
11
|
+
<% if (spa) { %><button type="button" onclick={enter}><%- intl ? '{t("enterAccount")}' : 'Enter demo account' %></button><% } else { %><form method="POST"><button type="submit"><%- intl ? '{t("enterAccount")}' : 'Enter demo account' %></button></form><% } %>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { redirect } from "@sveltejs/kit";
|
|
2
|
+
import { resolveReturnTo } from "$lib/resolveReturnTo";
|
|
3
|
+
import type { RequestHandler } from "./$types";
|
|
4
|
+
|
|
5
|
+
export const POST: RequestHandler = async ({ request, cookies, url }) => {
|
|
6
|
+
const theme = (await request.formData()).get("theme");
|
|
7
|
+
if (theme === "light" || theme === "dark") cookies.set("theme", theme, { path: "/", sameSite: "lax", httpOnly: true, secure: url.protocol === "https:", maxAge: 31536000 });
|
|
8
|
+
else cookies.delete("theme", { path: "/" });
|
|
9
|
+
redirect(303, resolveReturnTo(request.headers.get("referer"), url));
|
|
10
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RequestHandler } from "./$types";
|
|
2
|
+
export const GET: RequestHandler = ({ url }) => {
|
|
3
|
+
const escape = (value: string) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
4
|
+
const paths = ["/", "/catalog", "/catalog/compute", "/catalog/storage"<% if (forms) { %>, "/contact"<% } %><% if (appShell) { %>, "/account"<% } %>];
|
|
5
|
+
const entries = paths.map((path) => `<url><loc>${escape(new URL(path, url.origin).href)}</loc></url>`).join("");
|
|
6
|
+
return new Response(`<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${entries}</urlset>`, { headers: { "content-type": "application/xml; charset=utf-8" } });
|
|
7
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
@import url("@canonical/styles/fonts");
|
|
2
|
+
@import url("@canonical/styles");
|
|
3
|
+
|
|
4
|
+
@layer app {
|
|
5
|
+
.navigation-menu { padding: 1rem; }
|
|
6
|
+
.navigation-menu ul { list-style: none; padding: 0; }
|
|
7
|
+
.navigation-menu li { margin-block-end: 0.75rem; }
|
|
8
|
+
main { grid-column: 1 / -1; min-inline-size: 0; padding: 1rem; }
|
|
9
|
+
header { display: flex; flex-wrap: wrap; gap: 1rem; padding: 1rem; }
|
|
10
|
+
.field { display: grid; gap: 0.25rem; margin-block: 1rem; max-inline-size: 40rem; }
|
|
11
|
+
.dashboard-navigation { padding: 1rem; }
|
|
12
|
+
.dashboard-navigation summary, .instance-panel summary { cursor: pointer; font-weight: 600; }
|
|
13
|
+
.dashboard-navigation .navigation-heading { font-size: 1rem; margin-block: 1rem 0.5rem; }
|
|
14
|
+
.nav-unavailable { color: var(--color-text-muted, GrayText); font-size: 0.875em; }
|
|
15
|
+
.dashboard-nav a[aria-current="page"] { font-weight: 700; }
|
|
16
|
+
.dashboard-nav { list-style: none; padding: 0; }
|
|
17
|
+
.dashboard-nav li { margin-block: 0.75rem; }
|
|
18
|
+
.instance-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(16rem, 24rem); gap: 1.5rem; align-items: start; }
|
|
19
|
+
.dashboard-overview { display: grid; grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem); gap: 1.5rem; align-items: start; }
|
|
20
|
+
.activity-panel { border: 1px solid var(--color-border, currentColor); padding: 1rem; }
|
|
21
|
+
.instance-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem; list-style: none; padding: 0; }
|
|
22
|
+
.instance-card, .instance-panel { border: 1px solid var(--color-border, currentColor); padding: 1rem; min-inline-size: 0; }
|
|
23
|
+
.instance-panel.enhanced .instance-panel-content { position: fixed; z-index: 20; inset-block: 0; inset-inline-end: 0; width: min(28rem, 100vw); overflow: auto; padding: 1.5rem; background: Canvas; color: CanvasText; box-shadow: 0 0 1rem #0005; }
|
|
24
|
+
.instance-layout pre { white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
25
|
+
.skip-link { position: absolute; transform: translateY(-200%); }
|
|
26
|
+
.skip-link:focus { transform: none; z-index: 1; background: Canvas; color: CanvasText; }
|
|
27
|
+
@media (max-width: 40rem) { .ds.application-layout, .instance-layout, .dashboard-overview { grid-template-columns: 1fr; } }
|
|
28
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import adapter from "@sveltejs/adapter-<%= spa ? 'static' : 'node' %>";
|
|
2
|
+
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
preprocess: vitePreprocess(),
|
|
6
|
+
kit: { adapter: adapter(<% if (spa) { %>{ fallback: "200.html" }<% } %>) },
|
|
7
|
+
};
|