aboutsummaryrefslogtreecommitdiffstats
path: root/code/app/src
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2023-02-25 13:15:44 +0100
committerivarlovlie <git@ivarlovlie.no>2023-02-25 13:15:44 +0100
commit900bb5e845c3ad44defbd427cae3d44a4a43321f (patch)
treedf3d96a93771884add571e82336c29fc3d9c7a1c /code/app/src
downloadgreatoffice-900bb5e845c3ad44defbd427cae3d44a4a43321f.tar.xz
greatoffice-900bb5e845c3ad44defbd427cae3d44a4a43321f.zip
feat: Initial commit
Diffstat (limited to 'code/app/src')
-rw-r--r--code/app/src/actions/pwKey.ts7
-rw-r--r--code/app/src/app.d.ts9
-rw-r--r--code/app/src/app.html14
-rw-r--r--code/app/src/app.pcss34
-rw-r--r--code/app/src/components/alert.svelte268
-rw-r--r--code/app/src/components/badge.svelte76
-rw-r--r--code/app/src/components/button.svelte116
-rw-r--r--code/app/src/components/checkbox.svelte29
-rw-r--r--code/app/src/components/combobox.svelte451
-rw-r--r--code/app/src/components/icons/adjustments.svelte14
-rw-r--r--code/app/src/components/icons/bars-3-center-left.svelte15
-rw-r--r--code/app/src/components/icons/calendar.svelte14
-rw-r--r--code/app/src/components/icons/check-circle.svelte13
-rw-r--r--code/app/src/components/icons/chevron-down.svelte7
-rw-r--r--code/app/src/components/icons/chevron-up-down.svelte13
-rw-r--r--code/app/src/components/icons/chevron-up.svelte7
-rw-r--r--code/app/src/components/icons/database.svelte14
-rw-r--r--code/app/src/components/icons/exclamation-circle.svelte13
-rw-r--r--code/app/src/components/icons/exclamation-triangle.svelte13
-rw-r--r--code/app/src/components/icons/folder-open.svelte14
-rw-r--r--code/app/src/components/icons/funnel.svelte7
-rw-r--r--code/app/src/components/icons/home.svelte14
-rw-r--r--code/app/src/components/icons/index.ts47
-rw-r--r--code/app/src/components/icons/information-circle.svelte13
-rw-r--r--code/app/src/components/icons/magnifying-glass.svelte13
-rw-r--r--code/app/src/components/icons/megaphone.svelte14
-rw-r--r--code/app/src/components/icons/menu.svelte14
-rw-r--r--code/app/src/components/icons/queue-list.svelte14
-rw-r--r--code/app/src/components/icons/spinner.svelte20
-rw-r--r--code/app/src/components/icons/x-circle.svelte13
-rw-r--r--code/app/src/components/icons/x-mark.svelte11
-rw-r--r--code/app/src/components/icons/x.svelte14
-rw-r--r--code/app/src/components/index.ts25
-rw-r--r--code/app/src/components/input.svelte112
-rw-r--r--code/app/src/components/locale-switcher.svelte56
-rw-r--r--code/app/src/components/notification.svelte119
-rw-r--r--code/app/src/components/project-status-badge.svelte25
-rw-r--r--code/app/src/components/switch.svelte125
-rw-r--r--code/app/src/components/textarea.svelte81
-rw-r--r--code/app/src/configuration/index.ts64
-rw-r--r--code/app/src/global.d.ts11
-rw-r--r--code/app/src/hooks.server.ts49
-rw-r--r--code/app/src/i18n/en/app/index.ts7
-rw-r--r--code/app/src/i18n/en/index.ts63
-rw-r--r--code/app/src/i18n/formatters.ts13
-rw-r--r--code/app/src/i18n/i18n-svelte.ts12
-rw-r--r--code/app/src/i18n/i18n-types.ts461
-rw-r--r--code/app/src/i18n/i18n-util.async.ts42
-rw-r--r--code/app/src/i18n/i18n-util.sync.ts35
-rw-r--r--code/app/src/i18n/i18n-util.ts45
-rw-r--r--code/app/src/i18n/nb/app/index.ts7
-rw-r--r--code/app/src/i18n/nb/index.ts51
-rw-r--r--code/app/src/models/base/Customer.ts21
-rw-r--r--code/app/src/models/base/CustomerContact.ts8
-rw-r--r--code/app/src/models/base/CustomerEvent.ts6
-rw-r--r--code/app/src/models/base/SessionData.ts5
-rw-r--r--code/app/src/models/base/Tenant.ts8
-rw-r--r--code/app/src/models/base/User.ts13
-rw-r--r--code/app/src/models/base/UserRole.ts5
-rw-r--r--code/app/src/models/internal/FormError.ts24
-rw-r--r--code/app/src/models/internal/IForm.ts15
-rw-r--r--code/app/src/models/internal/KnownProblem.ts10
-rw-r--r--code/app/src/models/projects/Project.ts13
-rw-r--r--code/app/src/models/projects/ProjectLabel.ts5
-rw-r--r--code/app/src/models/projects/ProjectMember.ts10
-rw-r--r--code/app/src/models/projects/ProjectMeta.ts7
-rw-r--r--code/app/src/models/projects/ProjectRole.ts7
-rw-r--r--code/app/src/models/projects/ProjectStatus.ts5
-rw-r--r--code/app/src/models/work/WorkCategory.ts5
-rw-r--r--code/app/src/models/work/WorkEntry.ts13
-rw-r--r--code/app/src/models/work/WorkEntryQueryResponse.ts27
-rw-r--r--code/app/src/models/work/WorkLabel.ts5
-rw-r--r--code/app/src/models/work/WorkQuery.ts17
-rw-r--r--code/app/src/routes/(api)/delete-cookie/+server.ts8
-rw-r--r--code/app/src/routes/(main)/(app)/+layout.svelte379
-rw-r--r--code/app/src/routes/(main)/(app)/home/+page.svelte1
-rw-r--r--code/app/src/routes/(main)/(app)/org/+page.svelte4
-rw-r--r--code/app/src/routes/(main)/(app)/profile/+page.svelte4
-rw-r--r--code/app/src/routes/(main)/(app)/projects/+page.svelte118
-rw-r--r--code/app/src/routes/(main)/(app)/projects/[id]/+page.svelte5
-rw-r--r--code/app/src/routes/(main)/(app)/projects/create/+page.svelte59
-rw-r--r--code/app/src/routes/(main)/(app)/settings/+page.svelte205
-rw-r--r--code/app/src/routes/(main)/(app)/tickets/+page.svelte4
-rw-r--r--code/app/src/routes/(main)/(app)/todo/+page.svelte4
-rw-r--r--code/app/src/routes/(main)/(app)/wiki/+page.svelte4
-rw-r--r--code/app/src/routes/(main)/(public)/+layout.svelte18
-rw-r--r--code/app/src/routes/(main)/(public)/portal/+page.svelte26
-rw-r--r--code/app/src/routes/(main)/(public)/portal/+page.ts9
-rw-r--r--code/app/src/routes/(main)/(public)/reset-password/+page.svelte81
-rw-r--r--code/app/src/routes/(main)/(public)/reset-password/+page.ts11
-rw-r--r--code/app/src/routes/(main)/(public)/reset-password/[id]/+page.server.ts11
-rw-r--r--code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte82
-rw-r--r--code/app/src/routes/(main)/(public)/reset-password/[id]/+page.ts11
-rw-r--r--code/app/src/routes/(main)/(public)/sign-in/+page.svelte155
-rw-r--r--code/app/src/routes/(main)/(public)/sign-in/+page.ts11
-rw-r--r--code/app/src/routes/(main)/(public)/sign-in/index.spec.js12
-rw-r--r--code/app/src/routes/(main)/(public)/sign-in/index.ts20
-rw-r--r--code/app/src/routes/(main)/(public)/sign-up/+page.svelte106
-rw-r--r--code/app/src/routes/(main)/(public)/sign-up/+page.ts11
-rw-r--r--code/app/src/routes/(main)/+layout.server.ts45
-rw-r--r--code/app/src/routes/(main)/+layout.svelte31
-rw-r--r--code/app/src/routes/(main)/+layout.ts10
-rw-r--r--code/app/src/routes/(main)/+page.svelte1
-rw-r--r--code/app/src/routes/book/+layout.svelte46
-rw-r--r--code/app/src/routes/book/+layout.ts3
-rw-r--r--code/app/src/routes/book/+page.svelte1
-rw-r--r--code/app/src/routes/book/alerts/+page.svelte70
-rw-r--r--code/app/src/routes/book/badges/+page.svelte19
-rw-r--r--code/app/src/routes/book/buttons/+page.svelte23
-rw-r--r--code/app/src/routes/book/inputs/+page.svelte75
-rw-r--r--code/app/src/routes/book/notifications/+page.svelte50
-rw-r--r--code/app/src/routes/book/toggles/+page.svelte27
-rw-r--r--code/app/src/services/abstractions/IAccountService.ts54
-rw-r--r--code/app/src/services/abstractions/IApiTokenService.ts34
-rw-r--r--code/app/src/services/abstractions/IPasswordResetService.ts21
-rw-r--r--code/app/src/services/abstractions/ISettingsService.ts3
-rw-r--r--code/app/src/services/account-service.ts124
-rw-r--r--code/app/src/services/api-tokens-service.ts22
-rw-r--r--code/app/src/services/password-reset-service.ts48
-rw-r--r--code/app/src/services/settings-service.ts10
-rw-r--r--code/app/src/utilities/_fetch.ts94
-rw-r--r--code/app/src/utilities/cache.ts38
-rw-r--r--code/app/src/utilities/colors.ts47
-rw-r--r--code/app/src/utilities/crypto-helpers.ts48
-rw-r--r--code/app/src/utilities/dom-helpers.ts105
-rw-r--r--code/app/src/utilities/global-state.ts22
-rw-r--r--code/app/src/utilities/logger.ts118
-rw-r--r--code/app/src/utilities/misc-helpers.ts77
-rw-r--r--code/app/src/utilities/persistent-store.ts111
-rw-r--r--code/app/src/utilities/storage-helpers.ts26
-rw-r--r--code/app/src/utilities/testing-helpers.ts7
-rw-r--r--code/app/src/utilities/validators.ts34
132 files changed, 5770 insertions, 0 deletions
diff --git a/code/app/src/actions/pwKey.ts b/code/app/src/actions/pwKey.ts
new file mode 100644
index 0000000..cf85685
--- /dev/null
+++ b/code/app/src/actions/pwKey.ts
@@ -0,0 +1,7 @@
+import { is_testing } from "$configuration";
+
+export default function pwKey(node: HTMLElement, value: string | undefined) {
+ if (!value) return;
+ if (!is_testing()) return;
+ node.setAttribute("pw-key", value);
+} \ No newline at end of file
diff --git a/code/app/src/app.d.ts b/code/app/src/app.d.ts
new file mode 100644
index 0000000..31b276e
--- /dev/null
+++ b/code/app/src/app.d.ts
@@ -0,0 +1,9 @@
+// See https://kit.svelte.dev/docs/types#app
+// for information about these interfaces
+// and what to do when importing types
+declare namespace App {
+ interface Locals { }
+ interface Platform { }
+ interface PrivateEnv { }
+ interface PublicEnv { }
+} \ No newline at end of file
diff --git a/code/app/src/app.html b/code/app/src/app.html
new file mode 100644
index 0000000..308b223
--- /dev/null
+++ b/code/app/src/app.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html class="h-full bg-white" lang="en">
+
+<head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width" />
+ %sveltekit.head%
+</head>
+
+<body class="h-full">
+ <div>%sveltekit.body%</div>
+</body>
+
+</html> \ No newline at end of file
diff --git a/code/app/src/app.pcss b/code/app/src/app.pcss
new file mode 100644
index 0000000..5450db4
--- /dev/null
+++ b/code/app/src/app.pcss
@@ -0,0 +1,34 @@
+/* Write your global styles here, in PostCSS syntax */
+@tailwind base;
+@tailwind components;
+@tailwind utilities;
+
+pre {
+ font-family: monospace !important;
+}
+
+*:focus-visible {
+ outline: 1px auto;
+}
+
+.c-disabled {
+ cursor: not-allowed !important;
+ filter: opacity(.45);
+ pointer-events: none !important;
+}
+
+.c-disabled.loading {
+ cursor: wait !important;
+}
+
+.link {
+ @apply text-blue-600 hover:text-blue-700 transition duration-300 ease-in-out mb-4 cursor-pointer;
+
+ &.danger {
+ @apply text-red-600 hover:text-red-700;
+ }
+
+ &.active {
+ @apply underline
+ }
+}
diff --git a/code/app/src/components/alert.svelte b/code/app/src/components/alert.svelte
new file mode 100644
index 0000000..16d8340
--- /dev/null
+++ b/code/app/src/components/alert.svelte
@@ -0,0 +1,268 @@
+<script lang="ts">
+ import {random_string} from "$utilities/misc-helpers";
+ import {createEventDispatcher} from "svelte";
+ import {onMount} from "svelte";
+ import pwKey from "$actions/pwKey";
+ import {Temporal} from "temporal-polyfill";
+ import {ExclamationTriangleIcon, CheckCircleIcon, InformationCircleIcon, XCircleIcon, XMarkIcon} from "./icons";
+
+ const dispatch = createEventDispatcher();
+ const noCooldownSetting = "no-cooldown";
+
+ let iconComponent: any;
+ let colorClassPart = "";
+
+ /**
+ * An optional id for this alert, a default is set if not specified.
+ * This value is necessary for closeable cooldown to work.
+ */
+ // if no unique id is supplied, cooldown will not work between page loads.
+ // Therefore we are disabling it with noCooldownSetting in the fallback id.
+ export let id = "alert--" + noCooldownSetting + "--" + random_string(4);
+ /**
+ * The title to communicate, value is optional
+ */
+ export let title = "";
+ /**
+ * The message to communicate, value is optional
+ */
+ export let message = "";
+ /**
+ * Changes the alerts color and icon.
+ */
+ export let type: "info" | "success" | "warning" | "error" = "info";
+ /**
+ * If true the alert can be removed from the DOM by clicking on a X icon on the upper right hand courner
+ */
+ export let closeable = false;
+ /**
+ * The amount of seconds that should go by before this alert is shown again, only works when a unique id is set.
+ * Set to ~ if it should only be shown once per client (State stored in localestorage).
+ **/
+ export let closeableCooldown = "-1";
+ /**
+ * The text that is displayed on the right link
+ */
+ export let rightLinkText = "";
+ /**
+ * An array of list items displayed under the message or title
+ */
+ export let listItems: Array<string> = [];
+ /**
+ * An array of {id:string;text:string;color?:string}, where id is dispatched back as an svelte event with this syntax act$id (ex: on:actcancel).
+ * Text is the button text
+ * Color is the optional tailwind color to used, the value is used in classes like bg-$color-50.
+ */
+ export let actions: Array<{ id: string; text: string; color?: string }> = [];
+ /**
+ * This value is set on a plain anchor tag without any svelte routing,
+ * listen to the on:rightLinkClick if you want to intercept the click without navigating
+ */
+ export let rightLinkHref = "javascript:void(0)";
+ $: cooldownEnabled =
+ id.indexOf(noCooldownSetting) === -1 && closeable && (closeableCooldown === "~" || parseInt(closeableCooldown) > 0);
+ /**
+ * Sets this alerts visibility state, when this is false it is removed from the dom using an {#if} block.
+ */
+ export let visible = closeableCooldown === "~" || parseInt(closeableCooldown) > 0 ? false : true;
+
+ export let _pwKey: string | undefined = undefined;
+
+ const cooldownStorageKey = "lastseen--" + id;
+
+ $: switch (type) {
+ case "info": {
+ colorClassPart = "blue";
+ iconComponent = InformationCircleIcon;
+ break;
+ }
+ case "warning": {
+ colorClassPart = "yellow";
+ iconComponent = ExclamationTriangleIcon;
+ break;
+ }
+ case "error": {
+ colorClassPart = "red";
+ iconComponent = XCircleIcon;
+ break;
+ }
+ case "success": {
+ colorClassPart = "green";
+ iconComponent = CheckCircleIcon;
+ break;
+ }
+ }
+
+ function close() {
+ visible = false;
+ if (cooldownEnabled) {
+ console.log("Cooldown enabled for " + id + ", " + closeableCooldown === "~" ? "with an endless cooldown" : "");
+ localStorage.setItem(cooldownStorageKey, String(Temporal.Now.instant().epochSeconds));
+ }
+ }
+
+ function rightLinkClicked() {
+ dispatch("rightLinkCliked");
+ }
+
+ function actionClicked(name: string) {
+ dispatch("act" + name);
+ }
+
+ // Manages the state of the alert if cooldown is enabled
+ function run_cooldown() {
+ if (!cooldownEnabled) {
+ console.log("Alert cooldown is not enabled for " + id);
+ return;
+ }
+ if (!localStorage.getItem(cooldownStorageKey)) {
+ console.log("Alert " + id + " has not been seen yet, displaying");
+ visible = true;
+ return;
+ }
+ // if (!visible) {
+ // console.log(
+ // "Alert " + id + " is not visible, stopping cooldown change"
+ // );
+ // return;
+ // }
+ if (closeableCooldown === "~") {
+ console.log("Alert " + id + " has an infinite cooldown, hiding");
+ visible = false;
+ return;
+ }
+
+ const lastSeen = Temporal.Instant.fromEpochSeconds(parseInt(localStorage.getItem(cooldownStorageKey) ?? "-1"));
+ if (Temporal.Instant.compare(Temporal.Now.instant(), lastSeen.add({seconds: parseInt(closeableCooldown)})) === 1) {
+ console.log(
+ "Alert " +
+ id +
+ " has a cooldown of " +
+ closeableCooldown +
+ " and was last seen " +
+ lastSeen.toLocaleString() +
+ " making it due for a showing",
+ );
+ visible = true;
+ } else {
+ visible = false;
+ }
+ }
+
+ onMount(() => {
+ if (cooldownEnabled) {
+ run_cooldown();
+ }
+
+ if (closeable && closeableCooldown && id.indexOf(noCooldownSetting) !== -1) {
+ // TODO: This prints twice before shutting up as it should, in this example look at the only alert with closeableCooldown in alertsbook.
+ // Looks like svelte mounts three times and that my id is only set on the third. Not sure it does at all after logging the id onMount.
+ console.error("Alert cooldown does not work without specifying a unique id, related id: " + id);
+ }
+ });
+</script>
+
+{#if visible}
+ <div class="rounded-md bg-{colorClassPart}-50 p-4 {$$restProps.class ?? ''}" use:pwKey={_pwKey}>
+ <div class="flex">
+ <div class="flex-shrink-0">
+ <svelte:component this={iconComponent} class="text-{colorClassPart}-400"/>
+ </div>
+ <div class="ml-3 text-sm w-full">
+ {#if !rightLinkText}
+ {#if title}
+ <h3 class="font-bold text-{colorClassPart}-800">
+ {title}
+ </h3>
+ {/if}
+ {#if message}
+ <div class="{title ? 'mt-2' : ''} text-{colorClassPart}-700 justify-start">
+ <p>
+ {@html message}
+ </p>
+ </div>
+ {/if}
+ {#if listItems?.length ?? 0}
+ <ul class="list-disc space-y-1 pl-5 text-{colorClassPart}-700">
+ {#each listItems as listItem}
+ <li>{listItem}</li>
+ {/each}
+ </ul>
+ {/if}
+ {:else}
+ <div class="flex-1 md:flex md:justify-between">
+ <div>
+ {#if title}
+ <h3 class="font-medium text-{colorClassPart}-800">
+ {title}
+ </h3>
+ {/if}
+ {#if message}
+ <div class="{title ? 'mt-2' : ''} text-{colorClassPart}-700 justify-start">
+ <p>
+ {@html message}
+ </p>
+ </div>
+ {/if}
+ {#if listItems?.length ?? 0}
+ <ul class="list-disc space-y-1 pl-5 text-{colorClassPart}-700">
+ {#each listItems as listItem}
+ <li>{listItem}</li>
+ {/each}
+ </ul>
+ {/if}
+ </div>
+ <p class="mt-3 text-sm md:mt-0 md:ml-6 flex items-end">
+ <a
+ href={rightLinkHref}
+ on:click={() => rightLinkClicked()}
+ class="whitespace-nowrap font-medium text-{colorClassPart}-700 hover:text-{colorClassPart}-600"
+ >
+ {rightLinkText}
+ <span aria-hidden="true"> &rarr;</span>
+ </a>
+ </p>
+ </div>
+ {/if}
+ {#if actions?.length ?? 0}
+ <div class="ml-2 mt-4">
+ <div class="-mx-2 -my-1.5 flex gap-1">
+ {#each actions as action}
+ {@const color = action?.color ?? colorClassPart}
+ <button
+ type="button"
+ on:click={() => actionClicked(action.id)}
+ class="rounded-md
+ bg-{color}-50
+ px-2 py-1.5 text-sm font-medium
+ text-{color}-800
+ hover:bg-{color}-100
+ focus:outline-none focus:ring-2
+ focus:ring-{color}-600
+ focus:ring-offset-2
+ focus:ring-offset-{color}-50"
+ >
+ {action.text}
+ </button>
+ {/each}
+ </div>
+ </div>
+ {/if}
+ </div>
+ {#if closeable}
+ <div class="ml-auto pl-3">
+ <div class="-mx-1.5 -my-1.5">
+ <button
+ type="button"
+ on:click={() => close()}
+ class="inline-flex rounded-md bg-{colorClassPart}-50 p-1.5 text-{colorClassPart}-500 hover:bg-{colorClassPart}-100 focus:outline-none focus:ring-2 focus:ring-{colorClassPart}-600 focus:ring-offset-2 focus:ring-offset-{colorClassPart}-50"
+ >
+ <span class="sr-only">Dismiss</span>
+ <XMarkIcon/>
+ </button>
+ </div>
+ </div>
+ {/if}
+ </div>
+ </div>
+{/if}
diff --git a/code/app/src/components/badge.svelte b/code/app/src/components/badge.svelte
new file mode 100644
index 0000000..f967c2d
--- /dev/null
+++ b/code/app/src/components/badge.svelte
@@ -0,0 +1,76 @@
+<script lang="ts">
+ import { createEventDispatcher } from "svelte";
+
+ export let id: string | undefined = undefined;
+ export let type: "default" | "red" | "yellow" | "green" | "blue" | "tame" = "default";
+ export let text: string;
+ export let size: "large" | "default" = "default";
+ export let withDot: boolean = false;
+ export let removable: boolean = false;
+ export let uppercase: boolean = false;
+ export let tabindex: string | undefined = undefined;
+
+ let colorName = "gray";
+ let sizeClass = "rounded px-2 py-0.5 text-xs";
+ let dotSizeClass = "mr-1.5 h-2 w-2";
+
+ const dispatch = createEventDispatcher();
+
+ function handle_remove(event) {
+ dispatch("remove", { event, id, text });
+ }
+
+ $: switch (type) {
+ case "red":
+ colorName = "red";
+ break;
+ case "yellow":
+ colorName = "yellow";
+ break;
+ case "blue":
+ colorName = "blue";
+ break;
+ case "green":
+ colorName = "teal";
+ break;
+ case "default":
+ case "tame":
+ default:
+ colorName = "gray";
+ break;
+ }
+
+ $: switch (size) {
+ case "large":
+ sizeClass = "rounded-md px-2.5 py-0.5 text-sm";
+ dotSizeClass = "-ml-0.5 mr-1.5 h-2 w-2";
+ break;
+ case "default":
+ default:
+ sizeClass = "rounded px-2 py-0.5 text-xs";
+ dotSizeClass = "mr-1.5 h-2 w-2";
+ break;
+ }
+</script>
+
+<span class="inline-flex items-center font-medium {uppercase ? 'uppercase' : ''} bg-{colorName}-100 text-{colorName}-800 {sizeClass}" {id}>
+ {#if withDot}
+ <svg class="{dotSizeClass} text-{colorName}-400" fill="currentColor" viewBox="0 0 8 8">
+ <circle cx="4" cy="4" r="3" />
+ </svg>
+ {/if}
+ {text}
+ {#if removable}
+ <button
+ on:click={handle_remove}
+ tabindex={parseInt(tabindex)}
+ type="button"
+ class="ml-0.5 inline-flex h-4 w-4 flex-shrink-0 items-center justify-center rounded-full text-{colorName}-400 hover:bg-{colorName}-200 hover:text-{colorName}-500 focus:bg-{colorName}-500 focus:outline-none"
+ >
+ <span class="sr-only">Remove badge</span>
+ <svg class="h-2 w-2" stroke="currentColor" fill="none" viewBox="0 0 8 8">
+ <path stroke-linecap="round" stroke-width="1.5" d="M1 1l6 6m0-6L1 7" />
+ </svg>
+ </button>
+ {/if}
+</span>
diff --git a/code/app/src/components/button.svelte b/code/app/src/components/button.svelte
new file mode 100644
index 0000000..1d6ac4b
--- /dev/null
+++ b/code/app/src/components/button.svelte
@@ -0,0 +1,116 @@
+<script context="module" lang="ts">
+ export type ButtonKind = "primary" | "secondary" | "white" | "reset";
+ export type ButtonSize = "sm" | "lg" | "md" | "xl";
+</script>
+
+<script lang="ts">
+ import pwKey from "$actions/pwKey";
+ import { SpinnerIcon } from "./icons";
+
+ export let kind = "primary" as ButtonKind;
+ export let size = "md" as ButtonSize;
+ export let type: "button" | "submit" | "reset" = "button";
+ export let id: string | undefined = undefined;
+ export let tabindex: string | undefined = undefined;
+ export let style: string | undefined = undefined;
+ export let title: string | undefined = undefined;
+ export let disabled: boolean | null = false;
+ export let href: string | undefined = undefined;
+ export let text: string;
+ export let loading = false;
+ export let fullWidth = false;
+ export let _pwKey: string | undefined = undefined;
+
+ let sizeClasses = "";
+ let kindClasses = "";
+ let spinnerTextClasses = "";
+ let spinnerMarginClasses = "";
+
+ $: shared_props = {
+ type: type,
+ id: id || null,
+ title: title || null,
+ disabled: disabled || loading || null,
+ tabindex: tabindex || null,
+ style: style || null,
+ } as any;
+
+ $: switch (size) {
+ case "sm":
+ sizeClasses = "px-2.5 py-1.5 text-xs";
+ spinnerMarginClasses = "mr-2";
+ break;
+ case "md":
+ sizeClasses = "px-3 py-2 text-sm";
+ spinnerMarginClasses = "mr-2";
+ break;
+ case "lg":
+ sizeClasses = "px-3 py-2 text-lg";
+ spinnerMarginClasses = "mr-2";
+ break;
+ case "xl":
+ sizeClasses = "px-6 py-3 text-xl";
+ spinnerMarginClasses = "mr-2";
+ break;
+ }
+
+ $: switch (kind) {
+ case "secondary":
+ kindClasses = "border-transparent text-teal-800 bg-teal-100 hover:bg-teal-200 focus:ring-teal-500";
+ spinnerTextClasses = "teal-800";
+ break;
+ case "primary":
+ kindClasses = "border-transparent text-teal-900 bg-teal-300 hover:bg-teal-400 focus:ring-teal-500";
+ spinnerTextClasses = "text-teal-900";
+ break;
+ case "white":
+ kindClasses = "border-gray-300 text-gray-700 bg-white hover:bg-gray-50 focus:ring-gray-400";
+ spinnerTextClasses = "text-gray-700";
+ break;
+ case "reset":
+ kindClasses = "reset outline-none ring-0 focus:ring-0 focus-visible:ring-0";
+ break;
+ }
+</script>
+
+{#if href}
+ <a
+ use:pwKey={_pwKey}
+ {...shared_props}
+ {href}
+ class="{sizeClasses} {kindClasses} {loading ? 'disabled:' : ''} {$$restProps.class ?? ''} {fullWidth
+ ? 'w-full justify-center'
+ : ''} disabled:cursor-not-allowed inline-flex items-center border font-bold rounded shadow-sm focus:outline-none focus:ring-2"
+ >
+ {#if loading}
+ <SpinnerIcon class={spinnerTextClasses + " " + spinnerMarginClasses} />
+ {/if}
+ {text}
+ </a>
+{:else}
+ <button
+ use:pwKey={_pwKey}
+ {...shared_props}
+ on:click
+ class="btn {sizeClasses} {kindClasses} {$$restProps.class ?? ''}
+ {fullWidth
+ ? 'w-full justify-center'
+ : ''} inline-flex items-center border font-bold rounded shadow-sm focus:outline-none focus:ring-2"
+ >
+ {#if loading}
+ <SpinnerIcon class={spinnerTextClasses + " " + spinnerMarginClasses} />
+ {/if}
+ {text}
+ </button>
+{/if}
+
+<style>
+ .reset {
+ border: 0px;
+ outline: none;
+ }
+
+ .reset:focus {
+ outline: none;
+ }
+</style>
diff --git a/code/app/src/components/checkbox.svelte b/code/app/src/components/checkbox.svelte
new file mode 100644
index 0000000..db72bee
--- /dev/null
+++ b/code/app/src/components/checkbox.svelte
@@ -0,0 +1,29 @@
+<script lang="ts">
+ import pwKey from "$actions/pwKey";
+ import {random_string} from "$utilities/misc-helpers";
+
+ export let label: string;
+ export let id: string | undefined = "input__" + random_string(4);
+ export let name: string | undefined = undefined;
+ export let disabled: boolean | null = null;
+ export let checked: boolean;
+ export let required: boolean | null = null;
+ export let _pwKey: string | undefined = undefined;
+</script>
+
+<div class="flex items-center">
+ <input
+ {name}
+ use:pwKey={_pwKey}
+ {disabled}
+ {id}
+ {required}
+ type="checkbox"
+ bind:checked
+ class="h-4 w-4 text-teal-600 focus:ring-teal-500 border-gray-300 rounded"
+ />
+ <label for={id} class="ml-2 block text-sm text-gray-900">
+ {@html required ? "<span class='text-red-500'>*</span>" : ""}
+ {label}
+ </label>
+</div>
diff --git a/code/app/src/components/combobox.svelte b/code/app/src/components/combobox.svelte
new file mode 100644
index 0000000..396c18a
--- /dev/null
+++ b/code/app/src/components/combobox.svelte
@@ -0,0 +1,451 @@
+<script lang="ts" context="module">
+ export type ComboboxOption = {
+ id: string;
+ name: string;
+ selected?: boolean;
+ };
+</script>
+
+<script lang="ts">
+ import { CheckCircleIcon, ChevronUpDownIcon, XIcon } from "./icons";
+ import { random_string } from "$utilities/misc-helpers";
+ import { go, highlight } from "fuzzysort";
+ import Badge from "./badge.svelte";
+ import Button from "./button.svelte";
+ import LL from "$i18n/i18n-svelte";
+ import { element_has_focus } from "$utilities/dom-helpers";
+
+ export let id = "combobox-" + random_string(3);
+ export let label: string | undefined = undefined;
+ export let errorText: string | undefined = undefined;
+ export let disabled: boolean | undefined = undefined;
+ export let required: boolean | undefined = undefined;
+ export let maxlength: number | undefined = undefined;
+ export let placeholder: string = $LL.combobox.search();
+ export let options: Array<ComboboxOption> | undefined = [];
+ export let createable = false;
+ export let loading = false;
+ export let multiple = false;
+ export let noResultsText: string = $LL.combobox.noRecordsFound();
+ export let on_create_async = async ({ name: string }) => {};
+
+ export const reset = () => methods.reset();
+ export const select = (id: string) => methods.select_entry(id);
+ export const deselect = (id: string) => methods.deselect_entry(id);
+
+ const INTERNAL_ID = "INTERNAL__" + id;
+
+ let optionsListId = id + "--options";
+ let searchInputNode;
+ let searchResults: Array<any> = [];
+ let searchValue = "";
+ let showCreationHint = false;
+ let showDropdown = false;
+ let inputHasFocus = false;
+ let lastKeydownCode = "";
+ let mouseIsOverDropdown = false;
+ let mouseIsOverComponent = false;
+
+ $: ariaErrorDescribedBy = id + "__" + "error";
+ $: colorName = errorText ? "red" : "teal";
+ $: attributes = {
+ "aria-describedby": errorText ? ariaErrorDescribedBy : null,
+ "aria-invalid": errorText ? "true" : null,
+ disabled: disabled || null,
+ required: required || null,
+ maxlength: maxlength || null,
+ id: id || null,
+ placeholder: placeholder || null,
+ } as any;
+ $: hasSelection = options.some((c) => c.selected === true);
+ $: if (searchValue.trim()) {
+ showCreationHint = createable && options.every((c) => search.normalise_value(c.name) !== search.normalise_value(searchValue));
+ } else {
+ showCreationHint = false;
+ options = methods.get_sorted_array(options);
+ }
+
+ function on_select(event) {
+ const node = event.target.closest("[data-id]");
+ if (!node) return;
+ methods.select_entry(node.dataset.id);
+ }
+
+ const search = {
+ normalise_value(value: string): string {
+ if (!value) {
+ return "";
+ }
+ return value.trim().toLowerCase();
+ },
+ do() {
+ const query = search.normalise_value(searchValue);
+
+ if (!query.trim()) {
+ searchResults = [];
+ return;
+ }
+
+ // @ts-ignore
+ searchResults = go(query, options, {
+ limit: 15,
+ allowTypo: true,
+ threshold: -10000,
+ key: "name",
+ });
+ showDropdown = true;
+ },
+ on_input_focus() {
+ showDropdown = true;
+ inputHasFocus = true;
+ },
+ on_input_click() {
+ showDropdown = true;
+ inputHasFocus = true;
+ },
+ on_input_focusout() {
+ inputHasFocus = false;
+ if (lastKeydownCode !== "Tab" && (mouseIsOverDropdown || lastKeydownCode === "ArrowDown")) {
+ return;
+ }
+ const selected = options.find((c) => c.selected === true);
+ if (selected && !multiple) {
+ searchValue = selected.name;
+ }
+ document.querySelector("#" + INTERNAL_ID + " ul li.focus")?.classList.remove("focus");
+ showDropdown = false;
+ },
+ on_input_wrapper_focus(event) {
+ if (event.code && event.code !== "Space" && event.code !== "Enter") return;
+ if (!element_has_focus(searchInputNode)) searchInputNode.focus();
+ showDropdown = true;
+ },
+ };
+
+ const methods = {
+ reset(focus_input = false) {
+ searchValue = "";
+ const copy = options;
+ for (const entry of copy) {
+ entry.selected = false;
+ }
+ options = methods.get_sorted_array(copy);
+ if (focus_input) {
+ searchInputNode?.focus();
+ showDropdown = true;
+ } else {
+ showDropdown = false;
+ }
+ },
+ async create_entry(name: string) {
+ if (!name || !createable || loading) {
+ console.log("Not sending creation event due to failed preconditions", { name, createable, loading });
+ return;
+ }
+ try {
+ await on_create_async({ name });
+ searchValue = "";
+ loading = false;
+ } catch (e) {
+ console.error(e);
+ }
+ },
+ select_entry(entryId: string) {
+ if (!entryId || loading) {
+ console.log("Not selecting entry due to failed preconditions", {
+ entryId,
+ loading,
+ });
+ return;
+ }
+
+ const copy = options;
+ for (const entry of options) {
+ if (entry.id === entryId) {
+ entry.selected = true;
+ if (multiple) {
+ searchValue = "";
+ } else {
+ searchValue = entry.name;
+ }
+ } else if (!multiple) {
+ entry.selected = false;
+ }
+ }
+ options = methods.get_sorted_array(copy);
+ searchInputNode?.focus();
+ searchResults = [];
+ },
+ deselect_entry(entryId: string) {
+ if (!entryId || loading) {
+ console.log("Not deselecting entry due to failed preconditions", {
+ entryId,
+ loading,
+ });
+ return;
+ }
+ console.log("Deselecting entry", entryId);
+
+ const copy = options;
+
+ for (const entry of copy) {
+ if (entry.id === entryId) {
+ entry.selected = false;
+ }
+ }
+
+ options = methods.get_sorted_array(copy);
+ searchInputNode?.focus();
+ },
+ get_sorted_array(options: Array<ComboboxOption>): Array<ComboboxOption> {
+ if (!options) {
+ return;
+ }
+ if (options.length < 1) {
+ return [];
+ }
+ if (searchValue) {
+ return options;
+ }
+
+ return options.sort((a, b) => search.normalise_value(a.name).localeCompare(search.normalise_value(b.name)));
+ },
+ };
+
+ const windowEvents = {
+ on_mousemove(event: any) {
+ if (!event.target) return;
+ mouseIsOverDropdown = event.target?.closest("#" + INTERNAL_ID + " .tongue") != null ?? false;
+ mouseIsOverComponent = event.target?.closest("#" + INTERNAL_ID) != null ?? false;
+ },
+ on_click() {
+ if (showDropdown && !mouseIsOverDropdown && !mouseIsOverComponent) {
+ showDropdown = false;
+ }
+ },
+ on_keydown(event: any) {
+ lastKeydownCode = event.code;
+ const enterPressed = event.code === "Enter";
+ const backspacePressed = event.code === "Backspace";
+ const arrowUpPressed = event.code === "ArrowUp";
+ const spacePressed = event.code === "Space";
+ const arrowDownPressed = event.code === "ArrowDown";
+ const searchInputHasFocus = element_has_focus(searchInputNode);
+ const focusedEntry = document.querySelector("#" + INTERNAL_ID + " ul li.focus") as HTMLLIElement;
+
+ if (showDropdown && (enterPressed || arrowDownPressed || arrowUpPressed)) {
+ event.preventDefault();
+ }
+
+ if (searchInputHasFocus && backspacePressed && !searchValue && options.length > 0) {
+ if (options.filter((c) => c.selected === true).at(-1)?.id ?? false) {
+ methods.deselect_entry(options.filter((c) => c.selected === true).at(-1)?.id ?? "");
+ }
+ return;
+ }
+
+ if (searchInputHasFocus && enterPressed && showCreationHint) {
+ methods.create_entry(searchValue.trim());
+ return;
+ }
+
+ if (searchInputHasFocus && !focusedEntry && arrowDownPressed) {
+ const firstEntry = document.querySelector("#" + INTERNAL_ID + " ul li:first-of-type");
+ if (firstEntry) {
+ firstEntry.classList.add("focus");
+ return;
+ }
+ }
+
+ if (focusedEntry && (arrowUpPressed || arrowDownPressed)) {
+ if (arrowDownPressed) {
+ if (focusedEntry.nextElementSibling) {
+ focusedEntry.nextElementSibling.classList.add("focus");
+ focusedEntry.nextElementSibling.scrollIntoView(false);
+ } else {
+ const firstLIEl = document.querySelector("#" + INTERNAL_ID + " ul li:first-of-type");
+ firstLIEl.classList.add("focus");
+ firstLIEl.scrollIntoView(false);
+ }
+ } else if (arrowUpPressed) {
+ if (focusedEntry.previousElementSibling) {
+ focusedEntry.previousElementSibling.classList.add("focus");
+ focusedEntry.previousElementSibling.scrollIntoView(false);
+ } else {
+ const lastLIEl = document.querySelector("#" + INTERNAL_ID + " ul li:last-of-type");
+ lastLIEl.classList.add("focus");
+ lastLIEl.scrollIntoView(false);
+ }
+ }
+ focusedEntry.classList.remove("focus");
+ return;
+ }
+
+ if (focusedEntry && (spacePressed || enterPressed)) {
+ methods.select_entry(focusedEntry.dataset.id);
+ return;
+ }
+
+ if (lastKeydownCode === "Tab" && !searchInputHasFocus) {
+ showDropdown = false;
+ }
+ },
+ on_touchend(event) {
+ windowEvents.on_mousemove(event);
+ },
+ };
+</script>
+
+<svelte:window
+ on:keydown={windowEvents.on_keydown}
+ on:mousemove={windowEvents.on_mousemove}
+ on:touchend={windowEvents.on_touchend}
+ on:click={windowEvents.on_click}
+/>
+
+<div id={INTERNAL_ID} class:cursor-wait={loading}>
+ {#if label}
+ <label for={id} class="block text-sm font-medium text-gray-700">
+ {label}
+ {@html required ? "<span class='text-red-500'>*</span>" : ""}
+ </label>
+ {/if}
+ <div class="relative {label ? 'mt-1' : ''}">
+ <div
+ on:click={search.on_input_wrapper_focus}
+ on:keypress={search.on_input_wrapper_focus}
+ class="cursor-text w-full flex rounded-md border bg-white py-2 pl-3 pr-12 sm:text-sm
+ {inputHasFocus ? `border-${colorName}-500 outline-none ring-1 ring-${colorName}-500` : 'shadow-sm border-gray-300'}"
+ >
+ {#if multiple === true && hasSelection}
+ <div class="flex gap-1 flex-wrap">
+ {#each options.filter((c) => c.selected === true) as option}
+ <Badge
+ id={option.id}
+ removable
+ tabindex="-1"
+ on:remove={(e) => methods.deselect_entry(e.detail.id)}
+ text={option.name}
+ />
+ {/each}
+ </div>
+ {/if}
+ <div>
+ <input
+ {...attributes}
+ type="text"
+ style="all: unset;"
+ role="combobox"
+ aria-controls={optionsListId}
+ aria-expanded={showDropdown}
+ bind:value={searchValue}
+ bind:this={searchInputNode}
+ on:input={() => search.do()}
+ on:click={search.on_input_click}
+ on:focus={search.on_input_focus}
+ on:blur={search.on_input_focusout}
+ autocomplete="off"
+ />
+ {#if hasSelection}
+ <button
+ type="button"
+ on:click={() => reset()}
+ title={$LL.reset()}
+ tabindex="-1"
+ class="text-gray-400 absolute cursor-pointer inset-y-0 right-0 flex items-center rounded-r-md px-2"
+ >
+ <XIcon />
+ </button>
+ {:else}
+ <span tabindex="-1" class="text-gray-400 absolute inset-y-0 right-0 flex items-center rounded-r-md px-2">
+ <ChevronUpDownIcon />
+ </span>
+ {/if}
+ </div>
+ </div>
+ {#if errorText}
+ <p class="mt-2 text-sm text-red-600" id={ariaErrorDescribedBy}>
+ {errorText}
+ </p>
+ {/if}
+ <div
+ class="tongue {showDropdown ? 'absolute' : 'hidden'}
+ z-10 mt-1 max-h-60 w-full overflow-auto rounded-md bg-white
+ text-base shadow-lg ring-1 ring-teal ring-opacity-5 focus:outline-none sm:text-sm"
+ >
+ <ul id={optionsListId} role="listbox" tabindex="-1">
+ {#if searchResults.length > 0}
+ {#each searchResults.filter((c) => !c.selected) as result}
+ <li
+ class="item"
+ data-id={result.obj.id}
+ aria-selected={result.obj.selected}
+ role="option"
+ on:click={on_select}
+ on:keypress={on_select}
+ tabindex="-1"
+ >
+ {@html highlight(result, '<span class="font-bold">', "</span>")}
+ </li>
+ {/each}
+ {:else if options.length > 0}
+ {#each options as option}
+ <!--
+ Combobox option, manage highlight styles based on mouseenter/mouseleave and keyboard navigation.
+ Active: "text-white bg-indigo-600", Not Active: "text-gray-900"
+ -->
+ <li
+ class="item"
+ aria-selected={option.selected}
+ role="option"
+ data-id={option.id}
+ on:click={on_select}
+ on:keypress={on_select}
+ tabindex="-1"
+ >
+ <span class="block truncate {option.selected ? 'text-semibold' : ''}">{option.name}</span>
+ {#if option.selected}
+ <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-{colorName}-600">
+ <CheckCircleIcon />
+ </span>
+ {/if}
+ </li>
+ {/each}
+ {:else}
+ <slot name="no-records">
+ <p class="px-2">{noResultsText}</p>
+ {#if createable && !searchValue}
+ <p class="px-2 text-gray-500">{$LL.combobox.createRecordHelpText()}</p>
+ {/if}
+ </slot>
+ {/if}
+ </ul>
+ {#if showCreationHint}
+ <div class="sticky bottom-0 w-full bg-white">
+ <Button
+ text={$LL.combobox.createRecordButtonText(searchValue.trim())}
+ title={$LL.combobox.createRecordButtonText(searchValue.trim())}
+ {loading}
+ kind="reset"
+ type="button"
+ on:click={() => methods.create_entry(searchValue.trim())}
+ />
+ </div>
+ {/if}
+ </div>
+ </div>
+</div>
+
+<style lang="postcss">
+ .focus {
+ @apply text-white bg-teal-300;
+ }
+
+ .item {
+ @apply relative cursor-pointer select-none py-2 pl-3 pr-9 text-gray-900;
+ }
+
+ .item[aria-selected="true"] {
+ @apply bg-teal-200;
+ }
+</style>
diff --git a/code/app/src/components/icons/adjustments.svelte b/code/app/src/components/icons/adjustments.svelte
new file mode 100644
index 0000000..83bda27
--- /dev/null
+++ b/code/app/src/components/icons/adjustments.svelte
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ class="h-6 w-6 {$$restProps.class ?? ''}"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ stroke-width="2"
+>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4"
+ />
+</svg>
diff --git a/code/app/src/components/icons/bars-3-center-left.svelte b/code/app/src/components/icons/bars-3-center-left.svelte
new file mode 100644
index 0000000..785ece3
--- /dev/null
+++ b/code/app/src/components/icons/bars-3-center-left.svelte
@@ -0,0 +1,15 @@
+<svg
+ class="h-6 w-6 {$$restProps.class ?? ''}"
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke-width="1.5"
+ stroke="currentColor"
+ aria-hidden="true"
+>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M3.75 6.75h16.5M3.75 12H12m-8.25 5.25h16.5"
+ />
+</svg>
diff --git a/code/app/src/components/icons/calendar.svelte b/code/app/src/components/icons/calendar.svelte
new file mode 100644
index 0000000..e0053ee
--- /dev/null
+++ b/code/app/src/components/icons/calendar.svelte
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke-width="1.5"
+ stroke="currentColor"
+ class="w-6 h-6 {$$restProps.class ?? ''}"
+>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 012.25-2.25h13.5A2.25 2.25 0 0121 7.5v11.25m-18 0A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75m-18 0v-7.5A2.25 2.25 0 015.25 9h13.5A2.25 2.25 0 0121 11.25v7.5m-9-6h.008v.008H12v-.008zM12 15h.008v.008H12V15zm0 2.25h.008v.008H12v-.008zM9.75 15h.008v.008H9.75V15zm0 2.25h.008v.008H9.75v-.008zM7.5 15h.008v.008H7.5V15zm0 2.25h.008v.008H7.5v-.008zm6.75-4.5h.008v.008h-.008v-.008zm0 2.25h.008v.008h-.008V15zm0 2.25h.008v.008h-.008v-.008zm2.25-4.5h.008v.008H16.5v-.008zm0 2.25h.008v.008H16.5V15z"
+ />
+</svg>
diff --git a/code/app/src/components/icons/check-circle.svelte b/code/app/src/components/icons/check-circle.svelte
new file mode 100644
index 0000000..e30778e
--- /dev/null
+++ b/code/app/src/components/icons/check-circle.svelte
@@ -0,0 +1,13 @@
+<svg
+ class="h-5 w-5 {$$restProps.class ?? ''}"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+>
+ <path
+ fill-rule="evenodd"
+ d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z"
+ clip-rule="evenodd"
+ />
+</svg>
diff --git a/code/app/src/components/icons/chevron-down.svelte b/code/app/src/components/icons/chevron-down.svelte
new file mode 100644
index 0000000..5b29ece
--- /dev/null
+++ b/code/app/src/components/icons/chevron-down.svelte
@@ -0,0 +1,7 @@
+<svg class="h-5 w-5 {$$restProps.class ?? ''}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
+ <path
+ fill-rule="evenodd"
+ d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z"
+ clip-rule="evenodd"
+ />
+</svg>
diff --git a/code/app/src/components/icons/chevron-up-down.svelte b/code/app/src/components/icons/chevron-up-down.svelte
new file mode 100644
index 0000000..c07aed5
--- /dev/null
+++ b/code/app/src/components/icons/chevron-up-down.svelte
@@ -0,0 +1,13 @@
+<svg
+ class="h-5 w-5 {$$restProps.class ?? ''}"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+>
+ <path
+ fill-rule="evenodd"
+ d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z"
+ clip-rule="evenodd"
+ />
+</svg>
diff --git a/code/app/src/components/icons/chevron-up.svelte b/code/app/src/components/icons/chevron-up.svelte
new file mode 100644
index 0000000..289e71d
--- /dev/null
+++ b/code/app/src/components/icons/chevron-up.svelte
@@ -0,0 +1,7 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5">
+ <path
+ fill-rule="evenodd"
+ d="M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832 6.29 12.77a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z"
+ clip-rule="evenodd"
+ />
+</svg>
diff --git a/code/app/src/components/icons/database.svelte b/code/app/src/components/icons/database.svelte
new file mode 100644
index 0000000..6ffdadb
--- /dev/null
+++ b/code/app/src/components/icons/database.svelte
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ class="h-6 w-6 {$$restProps.class ?? ''}"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ stroke-width="2"
+>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"
+ />
+</svg>
diff --git a/code/app/src/components/icons/exclamation-circle.svelte b/code/app/src/components/icons/exclamation-circle.svelte
new file mode 100644
index 0000000..2ce79b1
--- /dev/null
+++ b/code/app/src/components/icons/exclamation-circle.svelte
@@ -0,0 +1,13 @@
+<svg
+ class="h-5 w-5 {$$restProps.class ?? ''}"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+>
+ <path
+ fill-rule="evenodd"
+ d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z"
+ clip-rule="evenodd"
+ />
+</svg>
diff --git a/code/app/src/components/icons/exclamation-triangle.svelte b/code/app/src/components/icons/exclamation-triangle.svelte
new file mode 100644
index 0000000..8d807db
--- /dev/null
+++ b/code/app/src/components/icons/exclamation-triangle.svelte
@@ -0,0 +1,13 @@
+<svg
+ class="h-5 w-5 {$$restProps.class ?? ''}"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+>
+ <path
+ fill-rule="evenodd"
+ d="M8.485 3.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 3.495zM10 6a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 0110 6zm0 9a1 1 0 100-2 1 1 0 000 2z"
+ clip-rule="evenodd"
+ />
+</svg>
diff --git a/code/app/src/components/icons/folder-open.svelte b/code/app/src/components/icons/folder-open.svelte
new file mode 100644
index 0000000..409c8e2
--- /dev/null
+++ b/code/app/src/components/icons/folder-open.svelte
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke-width="1.5"
+ stroke="currentColor"
+ class="w-6 h-6 {$$restProps.class ?? ''}"
+>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M3.75 9.776c.112-.017.227-.026.344-.026h15.812c.117 0 .232.009.344.026m-16.5 0a2.25 2.25 0 00-1.883 2.542l.857 6a2.25 2.25 0 002.227 1.932H19.05a2.25 2.25 0 002.227-1.932l.857-6a2.25 2.25 0 00-1.883-2.542m-16.5 0V6A2.25 2.25 0 016 3.75h3.879a1.5 1.5 0 011.06.44l2.122 2.12a1.5 1.5 0 001.06.44H18A2.25 2.25 0 0120.25 9v.776"
+ />
+</svg>
diff --git a/code/app/src/components/icons/funnel.svelte b/code/app/src/components/icons/funnel.svelte
new file mode 100644
index 0000000..7e9daeb
--- /dev/null
+++ b/code/app/src/components/icons/funnel.svelte
@@ -0,0 +1,7 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5">
+ <path
+ fill-rule="evenodd"
+ d="M2.628 1.601C5.028 1.206 7.49 1 10 1s4.973.206 7.372.601a.75.75 0 01.628.74v2.288a2.25 2.25 0 01-.659 1.59l-4.682 4.683a2.25 2.25 0 00-.659 1.59v3.037c0 .684-.31 1.33-.844 1.757l-1.937 1.55A.75.75 0 018 18.25v-5.757a2.25 2.25 0 00-.659-1.591L2.659 6.22A2.25 2.25 0 012 4.629V2.34a.75.75 0 01.628-.74z"
+ clip-rule="evenodd"
+ />
+</svg>
diff --git a/code/app/src/components/icons/home.svelte b/code/app/src/components/icons/home.svelte
new file mode 100644
index 0000000..ee8305d
--- /dev/null
+++ b/code/app/src/components/icons/home.svelte
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ class="h-6 w-6 {$$restProps.class ?? ''}"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ stroke-width="2"
+>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"
+ />
+</svg>
diff --git a/code/app/src/components/icons/index.ts b/code/app/src/components/icons/index.ts
new file mode 100644
index 0000000..eb5b439
--- /dev/null
+++ b/code/app/src/components/icons/index.ts
@@ -0,0 +1,47 @@
+import XIcon from "./x.svelte";
+import MenuIcon from "./menu.svelte";
+import AdjustmentsIcon from "./adjustments.svelte";
+import DatabaseIcon from "./database.svelte";
+import HomeIcon from "./home.svelte";
+import InformationCircleIcon from "./information-circle.svelte";
+import ExclamationTriangleIcon from "./exclamation-triangle.svelte";
+import XCircleIcon from "./x-circle.svelte";
+import CheckCircleIcon from "./check-circle.svelte";
+import XMarkIcon from "./x-mark.svelte";
+import SpinnerIcon from "./spinner.svelte";
+import ExclamationCircleIcon from "./exclamation-circle.svelte";
+import ChevronUpDownIcon from "./chevron-up-down.svelte";
+import MagnifyingGlassIcon from "./magnifying-glass.svelte";
+import Bars3CenterLeftIcon from "./bars-3-center-left.svelte";
+import CalendarIcon from "./calendar.svelte";
+import FolderOpenIcon from "./folder-open.svelte";
+import MegaphoneIcon from "./megaphone.svelte";
+import QueueListIcon from "./queue-list.svelte";
+import ChevronDownIcon from "./chevron-down.svelte";
+import ChevronUpIcon from "./chevron-up.svelte";
+import FunnelIcon from "./funnel.svelte";
+
+export {
+ FunnelIcon,
+ ChevronDownIcon,
+ ChevronUpIcon,
+ QueueListIcon,
+ FolderOpenIcon,
+ MegaphoneIcon,
+ CalendarIcon,
+ Bars3CenterLeftIcon,
+ MagnifyingGlassIcon,
+ ChevronUpDownIcon,
+ XIcon,
+ MenuIcon,
+ HomeIcon,
+ DatabaseIcon,
+ AdjustmentsIcon,
+ InformationCircleIcon,
+ ExclamationTriangleIcon,
+ ExclamationCircleIcon,
+ XCircleIcon,
+ CheckCircleIcon,
+ XMarkIcon,
+ SpinnerIcon
+} \ No newline at end of file
diff --git a/code/app/src/components/icons/information-circle.svelte b/code/app/src/components/icons/information-circle.svelte
new file mode 100644
index 0000000..68dbc60
--- /dev/null
+++ b/code/app/src/components/icons/information-circle.svelte
@@ -0,0 +1,13 @@
+<svg
+ class="h-5 w-5 {$$restProps.class ?? ''}"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+>
+ <path
+ fill-rule="evenodd"
+ d="M19 10.5a8.5 8.5 0 11-17 0 8.5 8.5 0 0117 0zM8.25 9.75A.75.75 0 019 9h.253a1.75 1.75 0 011.709 2.13l-.46 2.066a.25.25 0 00.245.304H11a.75.75 0 010 1.5h-.253a1.75 1.75 0 01-1.709-2.13l.46-2.066a.25.25 0 00-.245-.304H9a.75.75 0 01-.75-.75zM10 7a1 1 0 100-2 1 1 0 000 2z"
+ clip-rule="evenodd"
+ />
+</svg>
diff --git a/code/app/src/components/icons/magnifying-glass.svelte b/code/app/src/components/icons/magnifying-glass.svelte
new file mode 100644
index 0000000..f8fdb6e
--- /dev/null
+++ b/code/app/src/components/icons/magnifying-glass.svelte
@@ -0,0 +1,13 @@
+<svg
+ class="h-5 w-5 {$$restProps.class ?? ''}"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+>
+ <path
+ fill-rule="evenodd"
+ d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z"
+ clip-rule="evenodd"
+ />
+</svg>
diff --git a/code/app/src/components/icons/megaphone.svelte b/code/app/src/components/icons/megaphone.svelte
new file mode 100644
index 0000000..7ada5f3
--- /dev/null
+++ b/code/app/src/components/icons/megaphone.svelte
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke-width="1.5"
+ stroke="currentColor"
+ class="w-6 h-6 {$$restProps.class ?? ''}"
+>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M10.34 15.84c-.688-.06-1.386-.09-2.09-.09H7.5a4.5 4.5 0 110-9h.75c.704 0 1.402-.03 2.09-.09m0 9.18c.253.962.584 1.892.985 2.783.247.55.06 1.21-.463 1.511l-.657.38c-.551.318-1.26.117-1.527-.461a20.845 20.845 0 01-1.44-4.282m3.102.069a18.03 18.03 0 01-.59-4.59c0-1.586.205-3.124.59-4.59m0 9.18a23.848 23.848 0 018.835 2.535M10.34 6.66a23.847 23.847 0 008.835-2.535m0 0A23.74 23.74 0 0018.795 3m.38 1.125a23.91 23.91 0 011.014 5.395m-1.014 8.855c-.118.38-.245.754-.38 1.125m.38-1.125a23.91 23.91 0 001.014-5.395m0-3.46c.495.413.811 1.035.811 1.73 0 .695-.316 1.317-.811 1.73m0-3.46a24.347 24.347 0 010 3.46"
+ />
+</svg>
diff --git a/code/app/src/components/icons/menu.svelte b/code/app/src/components/icons/menu.svelte
new file mode 100644
index 0000000..471d85f
--- /dev/null
+++ b/code/app/src/components/icons/menu.svelte
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ class="h-6 w-6 {$$restProps.class ?? ''}"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ stroke-width="2"
+>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M4 6h16M4 12h16M4 18h16"
+ />
+</svg>
diff --git a/code/app/src/components/icons/queue-list.svelte b/code/app/src/components/icons/queue-list.svelte
new file mode 100644
index 0000000..6148394
--- /dev/null
+++ b/code/app/src/components/icons/queue-list.svelte
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke-width="1.5"
+ stroke="currentColor"
+ class="w-6 h-6 {$$restProps.class ?? ''}"
+>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M3.75 12h16.5m-16.5 3.75h16.5M3.75 19.5h16.5M5.625 4.5h12.75a1.875 1.875 0 010 3.75H5.625a1.875 1.875 0 010-3.75z"
+ />
+</svg>
diff --git a/code/app/src/components/icons/spinner.svelte b/code/app/src/components/icons/spinner.svelte
new file mode 100644
index 0000000..80cc57c
--- /dev/null
+++ b/code/app/src/components/icons/spinner.svelte
@@ -0,0 +1,20 @@
+<svg
+ class="-ml-1 mr-3 h-5 w-5 animate-spin {$$restProps.class ?? ''}"
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+>
+ <circle
+ class="opacity-25"
+ cx="12"
+ cy="12"
+ r="10"
+ stroke="currentColor"
+ stroke-width="4"
+ />
+ <path
+ class="opacity-75"
+ fill="currentColor"
+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
+ />
+</svg>
diff --git a/code/app/src/components/icons/x-circle.svelte b/code/app/src/components/icons/x-circle.svelte
new file mode 100644
index 0000000..3793b5a
--- /dev/null
+++ b/code/app/src/components/icons/x-circle.svelte
@@ -0,0 +1,13 @@
+<svg
+ class="h-5 w-5 {$$restProps.class ?? ''}"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+>
+ <path
+ fill-rule="evenodd"
+ d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z"
+ clip-rule="evenodd"
+ />
+</svg>
diff --git a/code/app/src/components/icons/x-mark.svelte b/code/app/src/components/icons/x-mark.svelte
new file mode 100644
index 0000000..fd1c6a1
--- /dev/null
+++ b/code/app/src/components/icons/x-mark.svelte
@@ -0,0 +1,11 @@
+<svg
+ class="h-5 w-5 {$$restProps.class ?? ''}"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+>
+ <path
+ d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
+ />
+</svg>
diff --git a/code/app/src/components/icons/x.svelte b/code/app/src/components/icons/x.svelte
new file mode 100644
index 0000000..6125ab8
--- /dev/null
+++ b/code/app/src/components/icons/x.svelte
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ class="h-6 w-6 {$$restProps.class ?? ''}"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ stroke-width="2"
+>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M6 18L18 6M6 6l12 12"
+ />
+</svg>
diff --git a/code/app/src/components/index.ts b/code/app/src/components/index.ts
new file mode 100644
index 0000000..494bc0c
--- /dev/null
+++ b/code/app/src/components/index.ts
@@ -0,0 +1,25 @@
+import Alert from "./alert.svelte";
+import Button from "./button.svelte";
+import Checkbox from "./checkbox.svelte";
+import Input from "./input.svelte";
+import LocaleSwitcher from "./locale-switcher.svelte";
+import Switch from "./switch.svelte";
+import Badge from "./badge.svelte";
+import ProjectStatusBadge from "./project-status-badge.svelte";
+import TextArea from "./textarea.svelte";
+import Combobox from "./combobox.svelte";
+import Notification from "./notification.svelte";
+
+export {
+ Badge,
+ Combobox,
+ TextArea,
+ ProjectStatusBadge,
+ Alert,
+ Button,
+ Checkbox,
+ Input,
+ LocaleSwitcher,
+ Switch,
+ Notification,
+}; \ No newline at end of file
diff --git a/code/app/src/components/input.svelte b/code/app/src/components/input.svelte
new file mode 100644
index 0000000..f97c1f1
--- /dev/null
+++ b/code/app/src/components/input.svelte
@@ -0,0 +1,112 @@
+<script lang="ts">
+ import pwKey from "$actions/pwKey";
+ import {random_string} from "$utilities/misc-helpers";
+ import {ExclamationCircleIcon} from "./icons";
+
+ export let label: string | undefined = undefined;
+ export let type: string = "text";
+ export let autocomplete: string | undefined = undefined;
+ export let required: boolean | undefined = undefined;
+ export let id: string | undefined = "input__" + random_string(4);
+ export let name: string | undefined = undefined;
+ export let placeholder: string | undefined = undefined;
+ export let helpText: string | undefined = undefined;
+ export let errorText: string | undefined = undefined;
+ export let errors: Array<string> | undefined = undefined;
+ export let disabled = false;
+ export let hideLabel = false;
+ export let cornerHint: string | undefined = undefined;
+ export let icon: any = undefined;
+ export let addon: string | undefined = undefined;
+ export let value: string | undefined;
+ export let wrapperClass: string | undefined = undefined;
+ export let _pwKey: string | undefined = undefined;
+
+ $: ariaErrorDescribedBy = id + "__" + "error";
+ $: attributes = {
+ "aria-describedby": errorText || errors?.length ? ariaErrorDescribedBy : null,
+ "aria-invalid": errorText || errors?.length ? "true" : null,
+ disabled: disabled || null,
+ autocomplete: autocomplete || null,
+ required: required || null,
+ } as any;
+ $: hasBling = icon || addon || errorText;
+ const defaultColorClass = "border-gray-300 focus:border-teal-500 focus:ring-teal-500";
+ let colorClass = defaultColorClass;
+ $: if (errorText) {
+ colorClass = "placeholder-red-300 focus:border-red-500 focus:outline-none focus:ring-red-500 text-red-900 pr-10 border-red-300";
+ } else {
+ colorClass = defaultColorClass;
+ }
+
+ function typeAction(node: HTMLInputElement) {
+ node.type = type;
+ }
+</script>
+
+<div class={wrapperClass}>
+ {#if label && !cornerHint && !hideLabel}
+ <label for={id} class={hideLabel ? "sr-only" : "block text-sm font-medium text-gray-700"}>
+ {label}
+ {@html required ? "<span class='text-red-500'>*</span>" : ""}
+ </label>
+ {:else if cornerHint && !hideLabel}
+ <div class="flex justify-between">
+ {#if label}
+ <label for={id} class={hideLabel ? "sr-only" : "block text-sm font-medium text-gray-700"}>
+ {label}
+ {@html required ? "<span class='text-red-500'>*</span>" : ""}
+ </label>
+ {/if}
+ <span class="text-sm text-gray-500">
+ {cornerHint}
+ </span>
+ </div>
+ {/if}
+ <div class="{label ? 'mt-1' : ''} {hasBling ? 'relative rounded-md' : ''} {addon ? 'flex' : ''}">
+ {#if icon}
+ <div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
+ <svelte:component this={icon} class={errorText ? "text-red-500" : "text-gray-400"}/>
+ </div>
+ {:else if addon}
+ <div class="inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-3 text-gray-500 sm:text-sm">
+ <span class="text-gray-500 sm:text-sm">{addon}</span>
+ </div>
+ {/if}
+ <input
+ use:typeAction
+ use:pwKey={_pwKey}
+ {name}
+ {id}
+ {...attributes}
+ bind:value
+ class="block w-full rounded-md shadow-sm sm:text-sm
+ {colorClass}
+ {disabled ? 'disabled:cursor-not-allowed disabled:border-gray-200 disabled:bg-gray-50 disabled:text-gray-500' : ''}
+ {addon ? 'min-w-0 flex-1 rounded-none rounded-r-md' : ''}
+ {icon ? 'pl-10' : ''}"
+ {placeholder}
+ />
+ {#if errorText}
+ <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
+ <ExclamationCircleIcon class="text-red-500"/>
+ </div>
+ {/if}
+ </div>
+ {#if helpText && !errorText}
+ <p class="mt-2 text-sm text-gray-500">
+ {helpText}
+ </p>
+ {/if}
+ {#if errorText || errors?.length === 1}
+ <p class="mt-2 text-sm text-red-600" id={ariaErrorDescribedBy}>
+ {errorText ?? errors[0]}
+ </p>
+ {:else if errors && errors.length}
+ <ul class="mt-2 list-disc" id={ariaErrorDescribedBy}>
+ {#each errors as error}
+ <li class="text-sm text-red-600">{error}</li>
+ {/each}
+ </ul>
+ {/if}
+</div>
diff --git a/code/app/src/components/locale-switcher.svelte b/code/app/src/components/locale-switcher.svelte
new file mode 100644
index 0000000..fc03f39
--- /dev/null
+++ b/code/app/src/components/locale-switcher.svelte
@@ -0,0 +1,56 @@
+<script lang="ts">
+ import pwKey from "$actions/pwKey";
+ import {browser} from "$app/environment";
+ import {page} from "$app/stores";
+ import {CookieNames} from "$configuration";
+ import {setLocale, locale} from "$i18n/i18n-svelte";
+ import type {Locales} from "$i18n/i18n-types";
+ import {locales} from "$i18n/i18n-util";
+ import {loadLocaleAsync} from "$i18n/i18n-util.async";
+ import Cookies from "js-cookie";
+
+ export let _pwKey: string | undefined = undefined;
+ export let tabindex: number | undefined = undefined;
+ let currentLocale = Cookies.get(CookieNames.locale);
+
+ async function switch_locale(newLocale: Locales) {
+ if (!newLocale || $locale === newLocale) return;
+ await loadLocaleAsync(newLocale);
+ setLocale(newLocale);
+ document.querySelector("html")?.setAttribute("lang", newLocale);
+ Cookies.set(CookieNames.locale, newLocale);
+ currentLocale = newLocale;
+ console.log("Switched to: " + newLocale);
+ }
+
+ function on_change(event: Event) {
+ const target = event.target as HTMLSelectElement;
+ switch_locale(target.options[target.selectedIndex].value as Locales);
+ }
+
+ $: if (browser) {
+ switch_locale($page.params.lang as Locales);
+ }
+
+ function get_locale_name(iso: string) {
+ switch (iso) {
+ case "nb": {
+ return "Norsk Bokmål";
+ }
+ case "en": {
+ return "English";
+ }
+ }
+ }
+</script>
+
+<select
+ {tabindex}
+ use:pwKey={_pwKey}
+ on:change={on_change}
+ class="mt-1 mr-1 block border-none py-2 pl-3 pr-10 text-base rounded-md right-0 absolute focus:outline-none focus:ring-teal-500 sm:text-sm"
+>
+ {#each locales as aLocale}
+ <option value={aLocale} selected={aLocale === currentLocale}>{get_locale_name(aLocale)}</option>
+ {/each}
+</select>
diff --git a/code/app/src/components/notification.svelte b/code/app/src/components/notification.svelte
new file mode 100644
index 0000000..d78b3d3
--- /dev/null
+++ b/code/app/src/components/notification.svelte
@@ -0,0 +1,119 @@
+<script context="module" lang="ts">
+ export type NotificationType = "info" | "error" | "success" | "warning" | "subtle";
+</script>
+
+<script lang="ts">
+ import { Transition } from "@rgossiaux/svelte-headlessui";
+ import { onDestroy } from "svelte";
+ import { XMarkIcon, ExclamationCircleIcon, InformationCircleIcon, XCircleIcon, CheckCircleIcon } from "./icons";
+
+ export let title: string;
+ export let subtitle = "";
+ export let show = false;
+ export let type: NotificationType = "info";
+ export let hideAfterSeconds = -1;
+ export let nonClosable = false;
+
+ $: _show = show && title.length > 0;
+ let timeout;
+ let iconClass = "";
+ let icon = undefined;
+ let bgClass = "";
+ let ringClass = "";
+
+ onDestroy(() => {
+ clearTimeout(timeout);
+ });
+
+ $: if (hideAfterSeconds > 0) {
+ timeout = setTimeout(() => close(), hideAfterSeconds * 1000);
+ } else {
+ timeout = -1;
+ show = true;
+ }
+
+ $: switch (type) {
+ case "error":
+ iconClass = "text-red-400";
+ bgClass = "bg-red-50";
+ ringClass = "ring-1 ring-red-100";
+ icon = XCircleIcon;
+ break;
+ case "info":
+ iconClass = "text-blue-400";
+ bgClass = "bg-blue-50";
+ ringClass = "ring-1 ring-blue-100";
+ icon = InformationCircleIcon;
+ break;
+ case "success":
+ iconClass = "text-green-400";
+ bgClass = "bg-green-50";
+ ringClass = "ring-1 ring-green-100";
+ icon = CheckCircleIcon;
+ break;
+ case "warning":
+ iconClass = "text-yellow-400";
+ bgClass = "bg-yellow-50";
+ ringClass = "ring-1 ring-yellow-100";
+ icon = ExclamationCircleIcon;
+ break;
+ case "subtle":
+ icon = undefined;
+ bgClass = "bg-white";
+ ringClass = "ring-1 ring-gray-100";
+ break;
+ default:
+ icon = undefined;
+ bgClass = "bg-white";
+ ringClass = "";
+ break;
+ }
+
+ function close() {
+ show = false;
+ }
+</script>
+
+<div aria-live="assertive" class="pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:items-start sm:p-6">
+ <div class="flex w-full flex-col items-center space-y-4 sm:items-end">
+ <Transition
+ class="w-full flex justify-end"
+ show={_show}
+ enter="transform ease-out duration-300 transition"
+ enterFrom="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2"
+ enterTo="translate-y-0 opacity-100 sm:translate-x-0"
+ leave="transition ease-in duration-100"
+ leaveFrom="opacity-100"
+ leaveTo="opacity-0"
+ >
+ <div class="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg shadow-md {bgClass} {ringClass}">
+ <div class="p-4">
+ <div class="flex items-start">
+ {#if icon}
+ <div class="flex-shrink-0">
+ <svelte:component this={icon} class={iconClass} />
+ </div>
+ {/if}
+ <div class="ml-3 w-0 flex-1 pt-0.5">
+ <p class="text-sm font-medium text-gray-900">{title}</p>
+ {#if subtitle}
+ <p class="mt-1 text-sm text-gray-500">{subtitle}</p>
+ {/if}
+ </div>
+ {#if !nonClosable}
+ <div class="ml-4 flex flex-shrink-0">
+ <button
+ on:click={close}
+ type="button"
+ class="inline-flex rounded-md text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
+ >
+ <XMarkIcon />
+ </button>
+ </div>
+ {/if}
+ </div>
+ </div>
+ </div>
+ </Transition>
+ </div>
+</div>
diff --git a/code/app/src/components/project-status-badge.svelte b/code/app/src/components/project-status-badge.svelte
new file mode 100644
index 0000000..3e93935
--- /dev/null
+++ b/code/app/src/components/project-status-badge.svelte
@@ -0,0 +1,25 @@
+<script lang="ts">
+ import type {ProjectStatus} from "$models/projects/ProjectStatus";
+ import Badge from "./badge.svelte";
+
+ export let status: string | ProjectStatus;
+
+ let text = "";
+ let type = "default" as any;
+ $: switch (status) {
+ case "idl":
+ type = "tame";
+ text = "IDLE";
+ break;
+ case "exp":
+ type = "yellow";
+ text = "EXPIRED";
+ break;
+ case "act":
+ type = "green";
+ text = "ACTIVE";
+ break;
+ }
+</script>
+
+<Badge {text} {type} uppercase/>
diff --git a/code/app/src/components/switch.svelte b/code/app/src/components/switch.svelte
new file mode 100644
index 0000000..1b67f80
--- /dev/null
+++ b/code/app/src/components/switch.svelte
@@ -0,0 +1,125 @@
+<script context="module" lang="ts">
+ export type SwitchType = "short" | "icon" | "default";
+</script>
+
+<script lang="ts">
+ import pwKey from "$actions/pwKey";
+
+ export let enabled = false;
+ export let type: SwitchType = "default";
+ export let srText = "Use setting";
+ export let label: string | undefined = undefined;
+ export let description: string | undefined = undefined;
+ export let rightAlignedLabelDescription = false;
+ export let _pwKey: string | undefined = undefined;
+
+ $: colorClass = enabled ? "bg-teal-600 focus:ring-teal-500" : "bg-gray-200 focus:ring-teal-500";
+ $: translateClass = enabled ? "translate-x-5" : "translate-x-0";
+ $: hasLabelOrDescription = label || description;
+
+ function toggle() {
+ enabled = !enabled;
+ }
+</script>
+
+<div class="{hasLabelOrDescription ? 'flex items-center' : ''} {rightAlignedLabelDescription ? '' : 'justify-between'}">
+ {#if hasLabelOrDescription && !rightAlignedLabelDescription}
+ <span class="flex flex-grow flex-col">
+ {#if label}
+ <span class="text-sm font-medium text-gray-900">{label}</span>
+ {/if}
+ {#if description}
+ <span class="text-sm text-gray-500">{description}</span>
+ {/if}
+ </span>
+ {/if}
+ {#if type === "short"}
+ <button
+ type="button"
+ class="group relative inline-flex h-5 w-10 flex-shrink-0 cursor-pointer items-center justify-center rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2"
+ role="switch"
+ aria-checked={enabled}
+ use:pwKey={_pwKey}
+ on:click={toggle}
+ >
+ <span class="sr-only">{srText}</span>
+ <span aria-hidden="true" class="pointer-events-none absolute h-full w-full rounded-md"/>
+ <span
+ aria-hidden="true"
+ class="{colorClass} pointer-events-none absolute mx-auto h-4 w-9 rounded-full transition-colors duration-200 ease-in-out"
+ />
+ <span
+ aria-hidden="true"
+ class="{translateClass} pointer-events-none absolute left-0 inline-block h-5 w-5 transform rounded-full border border-gray-200 bg-white shadow ring-0 transition-transform duration-200 ease-in-out"
+ />
+ </button>
+ {:else if type === "icon"}
+ <button
+ type="button"
+ class="{colorClass} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-offset-2"
+ role="switch"
+ aria-checked={enabled}
+ use:pwKey={_pwKey}
+ on:click={toggle}
+ >
+ <span class="sr-only">{srText}</span>
+ <span
+ class="{translateClass} pointer-events-none relative inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"
+ >
+ <span
+ class="{enabled
+ ? 'opacity-0 ease-out duration-100'
+ : 'opacity-100 ease-in duration-200'} absolute inset-0 flex h-full w-full items-center justify-center transition-opacity"
+ aria-hidden="true"
+ >
+ <svg class="h-3 w-3 text-gray-400" fill="none" viewBox="0 0 12 12">
+ <path
+ d="M4 8l2-2m0 0l2-2M6 6L4 4m2 2l2 2"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </svg>
+ </span>
+ <span
+ class="{enabled
+ ? 'opacity-100 ease-in duration-200'
+ : 'opacity-0 ease-out duration-100'} absolute inset-0 flex h-full w-full items-center justify-center transition-opacity"
+ aria-hidden="true"
+ >
+ <svg class="h-3 w-3 text-indigo-600" fill="currentColor" viewBox="0 0 12 12">
+ <path
+ d="M3.707 5.293a1 1 0 00-1.414 1.414l1.414-1.414zM5 8l-.707.707a1 1 0 001.414 0L5 8zm4.707-3.293a1 1 0 00-1.414-1.414l1.414 1.414zm-7.414 2l2 2 1.414-1.414-2-2-1.414 1.414zm3.414 2l4-4-1.414-1.414-4 4 1.414 1.414z"
+ />
+ </svg>
+ </span>
+ </span>
+ </button>
+ {:else if type === "default"}
+ <button
+ type="button"
+ class="{colorClass} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-offset-2"
+ role="switch"
+ aria-checked={enabled}
+ use:pwKey={_pwKey}
+ on:click={toggle}
+ >
+ <span class="sr-only">{srText}</span>
+ <span
+ aria-hidden="true"
+ class="{translateClass} pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"
+ />
+ </button>
+ {/if}
+ {#if hasLabelOrDescription && rightAlignedLabelDescription}
+ <span class="ml-3">
+ {#if label}
+ <span class="text-sm font-medium text-gray-900">{label}</span>
+ {/if}
+ {#if description}
+ <span class="text-sm text-gray-500">{description}</span>
+ {/if}
+ </span>
+ {/if}
+</div>
diff --git a/code/app/src/components/textarea.svelte b/code/app/src/components/textarea.svelte
new file mode 100644
index 0000000..223a265
--- /dev/null
+++ b/code/app/src/components/textarea.svelte
@@ -0,0 +1,81 @@
+<script lang="ts">
+ import {random_string} from "$utilities/misc-helpers";
+
+ export let id = "textarea-" + random_string(4);
+ export let disabled = false;
+ export let rows = 2;
+ export let cols = 0;
+ export let name = "";
+ export let placeholder = "";
+ export let value;
+ export let label = "";
+ export let required = false;
+ export let errorText = "";
+ export let errors: Array<string> | undefined = undefined;
+
+ $: ariaErrorDescribedBy = id + "__" + "error";
+ $: attributes = {
+ "aria-describedby": errorText || errors?.length ? ariaErrorDescribedBy : null,
+ "aria-invalid": errorText || errors?.length ? "true" : null,
+ rows: rows || null,
+ cols: cols || null,
+ name: name || null,
+ id: id || null,
+ disabled: disabled || null,
+ required: required || null,
+ } as any;
+
+ let textareaElement;
+ let scrollHeight = 0;
+ const defaultColorClass = "border-gray-300 focus:border-teal-500 focus:ring-teal-500";
+ let colorClass = defaultColorClass;
+
+ $: if (errorText) {
+ colorClass = "placeholder-red-300 focus:border-red-500 focus:outline-none focus:ring-red-500 text-red-900 pr-10 border-red-300";
+ } else {
+ colorClass = defaultColorClass;
+ }
+
+ $: if (textareaElement) {
+ scrollHeight = textareaElement.scrollHeight;
+ }
+
+ function on_input(event) {
+ event.target.style.height = "auto";
+ event.target.style.height = this.scrollHeight + "px";
+ }
+</script>
+
+<div>
+ {#if label}
+ <label for={id} class="block text-sm font-medium text-gray-700">
+ {label}
+ {@html required ? "<span class='text-red-500'>*</span>" : ""}
+ </label>
+ {/if}
+ <div class="mt-1">
+ <textarea
+ {rows}
+ {name}
+ {id}
+ {...attributes}
+ style="overflow-y:hidden;min-height:calc(1.5em + .75rem + 2px);{scrollHeight ? 'height:{scrollHeight}px' : ''};"
+ bind:value
+ bind:this={textareaElement}
+ on:input={on_input}
+ {placeholder}
+ class="block w-full rounded-md {colorClass} shadow-sm sm:text-sm"
+ />
+ {#if errorText || errors?.length === 1}
+ <p class="mt-2 text-sm text-red-600" id={ariaErrorDescribedBy}>
+ {errorText ?? errors[0]}
+ </p>
+ {:else if errors && errors.length}
+ <ul class="mt-2 list-disc" id={ariaErrorDescribedBy}>
+ {#each errors as error}
+ <li class="text-sm text-red-600">{error}</li>
+ {/each}
+ </ul>
+ {/if}
+ </div>
+</div>
diff --git a/code/app/src/configuration/index.ts b/code/app/src/configuration/index.ts
new file mode 100644
index 0000000..abf6ac5
--- /dev/null
+++ b/code/app/src/configuration/index.ts
@@ -0,0 +1,64 @@
+import { env } from "$env/dynamic/private";
+
+export const APP_ADDRESS = "https://stage.greatoffice.app";
+export const API_ADDRESS = "https://stage-api.greatoffice.app";
+export const DEV_APP_ADDRESS = "http://localhost";
+export const DEV_API_ADDRESS = "http://localhost:5000";
+
+export function api_base(path: string = "", explicitVersion = 1): string {
+ if (path && !path.startsWith("_")) path = "v" + explicitVersion + path;
+ return (is_development() ? DEV_API_ADDRESS : API_ADDRESS) + (path !== "" ? "/" + path : "");
+}
+
+export function is_development(): boolean {
+ return import.meta.env.DEV;
+}
+
+export function is_testing(): boolean {
+ return env.TESTING == "true";
+}
+
+export function is_debug(): boolean {
+ return localStorage.getItem(StorageKeys.debug) !== "true";
+}
+
+export const CookieNames = {
+ theme: "go_theme",
+ locale: "go_locale",
+ session: "go_session",
+};
+
+export function get_test_context(): TestContext {
+ return {
+ user: {
+ username: env.TEST_USERNAME,
+ password: env.TEST_PASSWORD,
+ },
+ };
+}
+
+export interface TestContext {
+ user: {
+ username: string,
+ password: string
+ };
+}
+
+export const QueryKeys = {
+ labels: "labels",
+ categories: "categories",
+ entries: "entries",
+};
+
+export const StorageKeys = {
+ session: "sessionData",
+ theme: "theme",
+ debug: "debug",
+ categories: "categories",
+ labels: "labels",
+ entries: "entries",
+ stopwatch: "stopwatchState",
+ logLevel: "logLevel",
+};
+
+export type PortalMessage = "emailValidated"; \ No newline at end of file
diff --git a/code/app/src/global.d.ts b/code/app/src/global.d.ts
new file mode 100644
index 0000000..13f5e16
--- /dev/null
+++ b/code/app/src/global.d.ts
@@ -0,0 +1,11 @@
+/// <reference types="@sveltejs/kit" />
+
+type Locales = import('$lib/i18n/i18n-types').Locales
+type TranslationFunctions = import('$lib/i18n/i18n-types').TranslationFunctions
+
+declare namespace App {
+ interface Locals {
+ locale: Locales
+ LL: TranslationFunctions
+ }
+} \ No newline at end of file
diff --git a/code/app/src/hooks.server.ts b/code/app/src/hooks.server.ts
new file mode 100644
index 0000000..2720480
--- /dev/null
+++ b/code/app/src/hooks.server.ts
@@ -0,0 +1,49 @@
+import { CookieNames } from "$configuration";
+import { detectLocale, i18n, isLocale, locales } from "$i18n/i18n-util";
+import { log_debug } from "$utilities/logger";
+import type { Handle, RequestEvent } from "@sveltejs/kit";
+import { initAcceptLanguageHeaderDetector } from "typesafe-i18n/detectors";
+import type { Locales } from "$i18n/i18n-types";
+import { loadAllLocales } from "$i18n/i18n-util.sync";
+
+loadAllLocales();
+const L = i18n();
+
+export const handle: Handle = async ({ event, resolve }) => {
+ const localeCookie = event.cookies.get(CookieNames.locale);
+ const preferredLocale = getPreferredLocale(event);
+ let finalLocale = localeCookie ?? preferredLocale;
+ let forceCookieSet = false;
+
+ log_debug("Handling locale", {
+ locales,
+ localeCookie,
+ preferredLocale,
+ finalLocale,
+ });
+
+ if (!isLocale(finalLocale)) {
+ log_debug(finalLocale + " is not a valid locale or it does not exist, switching to default: en");
+ finalLocale = "en";
+ forceCookieSet = true;
+ }
+
+ if (!localeCookie || forceCookieSet) {
+ // Set a locale cookie
+ event.cookies.set(CookieNames.locale, finalLocale, {
+ sameSite: "strict",
+ path: "/",
+ httpOnly: false,
+ });
+ }
+
+ event.locals.locale = finalLocale as Locales;
+ event.locals.LL = L[finalLocale as Locales];
+
+ return resolve(event, { transformPageChunk: ({ html }) => html.replace("%lang%", finalLocale) });
+};
+
+function getPreferredLocale(event: RequestEvent) {
+ const acceptLanguageDetector = initAcceptLanguageHeaderDetector(event.request);
+ return detectLocale(acceptLanguageDetector);
+}
diff --git a/code/app/src/i18n/en/app/index.ts b/code/app/src/i18n/en/app/index.ts
new file mode 100644
index 0000000..7ccfc97
--- /dev/null
+++ b/code/app/src/i18n/en/app/index.ts
@@ -0,0 +1,7 @@
+import type { BaseTranslation } from '../../i18n-types'
+
+const en_app: BaseTranslation = {
+ members: "Members",
+}
+
+export default en_app \ No newline at end of file
diff --git a/code/app/src/i18n/en/index.ts b/code/app/src/i18n/en/index.ts
new file mode 100644
index 0000000..b38eb48
--- /dev/null
+++ b/code/app/src/i18n/en/index.ts
@@ -0,0 +1,63 @@
+import type { BaseTranslation } from "../i18n-types";
+
+const en: BaseTranslation = {
+ or: "Or",
+ name: "Name",
+ emailAddress: "Email address",
+ password: "Password",
+ pageNotFound: "Page not found",
+ noInternet: "It seems like your device does not have a internet connection, please check your connection.",
+ reset: "Reset",
+ of: "{0} of {1}",
+ isRequired: "{0} is required",
+ submit: "Submit",
+ success: "Success",
+ tryAgainSoon: "Try again soon",
+ createANewAccount: "Create a new account",
+ unexpectedError: "An unexpected error occured",
+ notFound: "Not found",
+ documentation: "Documentation",
+ tos: "Terms of service",
+ privacyPolicy: "Privacy policy",
+ signIntoYourAccount: "Sign into your account",
+ combobox: {
+ search: "Search",
+ noRecordsFound: "No records found",
+ createRecordHelpText: "Create a record by typing the name in the search bar and pressing enter",
+ createRecordButtonText: "Press enter or click here to create {0}"
+ },
+ signInPage: {
+ title: "Sign in",
+ notMyComputer: "This is not my computer",
+ resetPassword: "Reset password",
+ yourPasswordIsUpdated: "Your password is updated",
+ signIn: "Sign In",
+ yourNewPasswordIsApplied: "Your new password is applied",
+ signInBelow: "Sign in below",
+ yourAccountIsDisabled: "Your account is disabled",
+ contactYourAdminIfDisabled: "Contact your administrator if this feels wrong",
+ youHaveReachedInactivityLimit: "You've reached the hidden inactivity limit",
+ feelFreeToSignInAgain: "Feel free to sign in again"
+ },
+ signUpPage: {
+ title: "Sign up",
+ createYourNewAccount: "Create your new account",
+ },
+ resetPasswordPage: {
+ title: "Reset password",
+ fulfillTitle: "Set new password",
+ setANewPassword: "Set a new password",
+ expired: "Expired",
+ requestHasExpired: "Your request has expired",
+ requestANewReset: "Request a new reset",
+ invalidRequestTitle: "Your request is invalid",
+ invalidRequestMessage: "This could be due to it being expired, nonexsistent or something else",
+ newPassword: "New password",
+ requestSentMessage: "If we find your email address in our systems, you will receive an email with instructions on how to set a new password for your account.",
+ requestAPasswordReset: "Request a password reset",
+ requestNotFound: "Your request was not found",
+ submitANewRequestBelow: "Submit a new reset request below"
+ }
+};
+
+export default en;
diff --git a/code/app/src/i18n/formatters.ts b/code/app/src/i18n/formatters.ts
new file mode 100644
index 0000000..ade2f89
--- /dev/null
+++ b/code/app/src/i18n/formatters.ts
@@ -0,0 +1,13 @@
+import { capitalise } from "$utilities/misc-helpers";
+import type { FormattersInitializer } from "typesafe-i18n";
+import type { Locales, Formatters } from "./i18n-types";
+
+export const initFormatters: FormattersInitializer<Locales, Formatters> = (locale: Locales) => {
+
+ const formatters: Formatters = {
+ // add your formatter functions here
+ capitalise: (value: string) => capitalise(value),
+ };
+
+ return formatters;
+};
diff --git a/code/app/src/i18n/i18n-svelte.ts b/code/app/src/i18n/i18n-svelte.ts
new file mode 100644
index 0000000..6cdffb3
--- /dev/null
+++ b/code/app/src/i18n/i18n-svelte.ts
@@ -0,0 +1,12 @@
+// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
+/* eslint-disable */
+
+import { initI18nSvelte } from 'typesafe-i18n/svelte'
+import type { Formatters, Locales, TranslationFunctions, Translations } from './i18n-types'
+import { loadedFormatters, loadedLocales } from './i18n-util'
+
+const { locale, LL, setLocale } = initI18nSvelte<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters)
+
+export { locale, LL, setLocale }
+
+export default LL
diff --git a/code/app/src/i18n/i18n-types.ts b/code/app/src/i18n/i18n-types.ts
new file mode 100644
index 0000000..ef1d664
--- /dev/null
+++ b/code/app/src/i18n/i18n-types.ts
@@ -0,0 +1,461 @@
+// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
+/* eslint-disable */
+import type { BaseTranslation as BaseTranslationType, LocalizedString, RequiredParams } from 'typesafe-i18n'
+
+export type BaseTranslation = BaseTranslationType & DisallowNamespaces
+export type BaseLocale = 'en'
+
+export type Locales =
+ | 'en'
+ | 'nb'
+
+export type Translation = RootTranslation & DisallowNamespaces
+
+export type Translations = RootTranslation &
+{
+ app: NamespaceAppTranslation
+}
+
+type RootTranslation = {
+ /**
+ * O​r
+ */
+ or: string
+ /**
+ * N​a​m​e
+ */
+ name: string
+ /**
+ * E​m​a​i​l​ ​a​d​d​r​e​s​s
+ */
+ emailAddress: string
+ /**
+ * P​a​s​s​w​o​r​d
+ */
+ password: string
+ /**
+ * P​a​g​e​ ​n​o​t​ ​f​o​u​n​d
+ */
+ pageNotFound: string
+ /**
+ * I​t​ ​s​e​e​m​s​ ​l​i​k​e​ ​y​o​u​r​ ​d​e​v​i​c​e​ ​d​o​e​s​ ​n​o​t​ ​h​a​v​e​ ​a​ ​i​n​t​e​r​n​e​t​ ​c​o​n​n​e​c​t​i​o​n​,​ ​p​l​e​a​s​e​ ​c​h​e​c​k​ ​y​o​u​r​ ​c​o​n​n​e​c​t​i​o​n​.
+ */
+ noInternet: string
+ /**
+ * R​e​s​e​t
+ */
+ reset: string
+ /**
+ * {​0​}​ ​o​f​ ​{​1​}
+ * @param {unknown} 0
+ * @param {unknown} 1
+ */
+ of: RequiredParams<'0' | '1'>
+ /**
+ * {​0​}​ ​i​s​ ​r​e​q​u​i​r​e​d
+ * @param {unknown} 0
+ */
+ isRequired: RequiredParams<'0'>
+ /**
+ * S​u​b​m​i​t
+ */
+ submit: string
+ /**
+ * S​u​c​c​e​s​s
+ */
+ success: string
+ /**
+ * T​r​y​ ​a​g​a​i​n​ ​s​o​o​n
+ */
+ tryAgainSoon: string
+ /**
+ * C​r​e​a​t​e​ ​a​ ​n​e​w​ ​a​c​c​o​u​n​t
+ */
+ createANewAccount: string
+ /**
+ * A​n​ ​u​n​e​x​p​e​c​t​e​d​ ​e​r​r​o​r​ ​o​c​c​u​r​e​d
+ */
+ unexpectedError: string
+ /**
+ * N​o​t​ ​f​o​u​n​d
+ */
+ notFound: string
+ /**
+ * D​o​c​u​m​e​n​t​a​t​i​o​n
+ */
+ documentation: string
+ /**
+ * T​e​r​m​s​ ​o​f​ ​s​e​r​v​i​c​e
+ */
+ tos: string
+ /**
+ * P​r​i​v​a​c​y​ ​p​o​l​i​c​y
+ */
+ privacyPolicy: string
+ /**
+ * S​i​g​n​ ​i​n​t​o​ ​y​o​u​r​ ​a​c​c​o​u​n​t
+ */
+ signIntoYourAccount: string
+ combobox: {
+ /**
+ * S​e​a​r​c​h
+ */
+ search: string
+ /**
+ * N​o​ ​r​e​c​o​r​d​s​ ​f​o​u​n​d
+ */
+ noRecordsFound: string
+ /**
+ * C​r​e​a​t​e​ ​a​ ​r​e​c​o​r​d​ ​b​y​ ​t​y​p​i​n​g​ ​t​h​e​ ​n​a​m​e​ ​i​n​ ​t​h​e​ ​s​e​a​r​c​h​ ​b​a​r​ ​a​n​d​ ​p​r​e​s​s​i​n​g​ ​e​n​t​e​r
+ */
+ createRecordHelpText: string
+ /**
+ * P​r​e​s​s​ ​e​n​t​e​r​ ​o​r​ ​c​l​i​c​k​ ​h​e​r​e​ ​t​o​ ​c​r​e​a​t​e​ ​{​0​}
+ * @param {unknown} 0
+ */
+ createRecordButtonText: RequiredParams<'0'>
+ }
+ signInPage: {
+ /**
+ * S​i​g​n​ ​i​n
+ */
+ title: string
+ /**
+ * T​h​i​s​ ​i​s​ ​n​o​t​ ​m​y​ ​c​o​m​p​u​t​e​r
+ */
+ notMyComputer: string
+ /**
+ * R​e​s​e​t​ ​p​a​s​s​w​o​r​d
+ */
+ resetPassword: string
+ /**
+ * Y​o​u​r​ ​p​a​s​s​w​o​r​d​ ​i​s​ ​u​p​d​a​t​e​d
+ */
+ yourPasswordIsUpdated: string
+ /**
+ * S​i​g​n​ ​I​n
+ */
+ signIn: string
+ /**
+ * Y​o​u​r​ ​n​e​w​ ​p​a​s​s​w​o​r​d​ ​i​s​ ​a​p​p​l​i​e​d
+ */
+ yourNewPasswordIsApplied: string
+ /**
+ * S​i​g​n​ ​i​n​ ​b​e​l​o​w
+ */
+ signInBelow: string
+ /**
+ * Y​o​u​r​ ​a​c​c​o​u​n​t​ ​i​s​ ​d​i​s​a​b​l​e​d
+ */
+ yourAccountIsDisabled: string
+ /**
+ * C​o​n​t​a​c​t​ ​y​o​u​r​ ​a​d​m​i​n​i​s​t​r​a​t​o​r​ ​i​f​ ​t​h​i​s​ ​f​e​e​l​s​ ​w​r​o​n​g
+ */
+ contactYourAdminIfDisabled: string
+ /**
+ * Y​o​u​'​v​e​ ​r​e​a​c​h​e​d​ ​t​h​e​ ​h​i​d​d​e​n​ ​i​n​a​c​t​i​v​i​t​y​ ​l​i​m​i​t
+ */
+ youHaveReachedInactivityLimit: string
+ /**
+ * F​e​e​l​ ​f​r​e​e​ ​t​o​ ​s​i​g​n​ ​i​n​ ​a​g​a​i​n
+ */
+ feelFreeToSignInAgain: string
+ }
+ signUpPage: {
+ /**
+ * S​i​g​n​ ​u​p
+ */
+ title: string
+ /**
+ * C​r​e​a​t​e​ ​y​o​u​r​ ​n​e​w​ ​a​c​c​o​u​n​t
+ */
+ createYourNewAccount: string
+ }
+ resetPasswordPage: {
+ /**
+ * R​e​s​e​t​ ​p​a​s​s​w​o​r​d
+ */
+ title: string
+ /**
+ * S​e​t​ ​n​e​w​ ​p​a​s​s​w​o​r​d
+ */
+ fulfillTitle: string
+ /**
+ * S​e​t​ ​a​ ​n​e​w​ ​p​a​s​s​w​o​r​d
+ */
+ setANewPassword: string
+ /**
+ * E​x​p​i​r​e​d
+ */
+ expired: string
+ /**
+ * Y​o​u​r​ ​r​e​q​u​e​s​t​ ​h​a​s​ ​e​x​p​i​r​e​d
+ */
+ requestHasExpired: string
+ /**
+ * R​e​q​u​e​s​t​ ​a​ ​n​e​w​ ​r​e​s​e​t
+ */
+ requestANewReset: string
+ /**
+ * Y​o​u​r​ ​r​e​q​u​e​s​t​ ​i​s​ ​i​n​v​a​l​i​d
+ */
+ invalidRequestTitle: string
+ /**
+ * T​h​i​s​ ​c​o​u​l​d​ ​b​e​ ​d​u​e​ ​t​o​ ​i​t​ ​b​e​i​n​g​ ​e​x​p​i​r​e​d​,​ ​n​o​n​e​x​s​i​s​t​e​n​t​ ​o​r​ ​s​o​m​e​t​h​i​n​g​ ​e​l​s​e
+ */
+ invalidRequestMessage: string
+ /**
+ * N​e​w​ ​p​a​s​s​w​o​r​d
+ */
+ newPassword: string
+ /**
+ * I​f​ ​w​e​ ​f​i​n​d​ ​y​o​u​r​ ​e​m​a​i​l​ ​a​d​d​r​e​s​s​ ​i​n​ ​o​u​r​ ​s​y​s​t​e​m​s​,​ ​y​o​u​ ​w​i​l​l​ ​r​e​c​e​i​v​e​ ​a​n​ ​e​m​a​i​l​ ​w​i​t​h​ ​i​n​s​t​r​u​c​t​i​o​n​s​ ​o​n​ ​h​o​w​ ​t​o​ ​s​e​t​ ​a​ ​n​e​w​ ​p​a​s​s​w​o​r​d​ ​f​o​r​ ​y​o​u​r​ ​a​c​c​o​u​n​t​.
+ */
+ requestSentMessage: string
+ /**
+ * R​e​q​u​e​s​t​ ​a​ ​p​a​s​s​w​o​r​d​ ​r​e​s​e​t
+ */
+ requestAPasswordReset: string
+ /**
+ * Y​o​u​r​ ​r​e​q​u​e​s​t​ ​w​a​s​ ​n​o​t​ ​f​o​u​n​d
+ */
+ requestNotFound: string
+ /**
+ * S​u​b​m​i​t​ ​a​ ​n​e​w​ ​r​e​s​e​t​ ​r​e​q​u​e​s​t​ ​b​e​l​o​w
+ */
+ submitANewRequestBelow: string
+ }
+}
+
+export type NamespaceAppTranslation = {
+ /**
+ * M​e​m​b​e​r​s
+ */
+ members: string
+}
+
+export type Namespaces =
+ | 'app'
+
+type DisallowNamespaces = {
+ /**
+ * reserved for 'app'-namespace\
+ * you need to use the `./app/index.ts` file instead
+ */
+ app?: "[typesafe-i18n] reserved for 'app'-namespace. You need to use the `./app/index.ts` file instead."
+}
+
+export type TranslationFunctions = {
+ /**
+ * Or
+ */
+ or: () => LocalizedString
+ /**
+ * Name
+ */
+ name: () => LocalizedString
+ /**
+ * Email address
+ */
+ emailAddress: () => LocalizedString
+ /**
+ * Password
+ */
+ password: () => LocalizedString
+ /**
+ * Page not found
+ */
+ pageNotFound: () => LocalizedString
+ /**
+ * It seems like your device does not have a internet connection, please check your connection.
+ */
+ noInternet: () => LocalizedString
+ /**
+ * Reset
+ */
+ reset: () => LocalizedString
+ /**
+ * {0} of {1}
+ */
+ of: (arg0: unknown, arg1: unknown) => LocalizedString
+ /**
+ * {0} is required
+ */
+ isRequired: (arg0: unknown) => LocalizedString
+ /**
+ * Submit
+ */
+ submit: () => LocalizedString
+ /**
+ * Success
+ */
+ success: () => LocalizedString
+ /**
+ * Try again soon
+ */
+ tryAgainSoon: () => LocalizedString
+ /**
+ * Create a new account
+ */
+ createANewAccount: () => LocalizedString
+ /**
+ * An unexpected error occured
+ */
+ unexpectedError: () => LocalizedString
+ /**
+ * Not found
+ */
+ notFound: () => LocalizedString
+ /**
+ * Documentation
+ */
+ documentation: () => LocalizedString
+ /**
+ * Terms of service
+ */
+ tos: () => LocalizedString
+ /**
+ * Privacy policy
+ */
+ privacyPolicy: () => LocalizedString
+ /**
+ * Sign into your account
+ */
+ signIntoYourAccount: () => LocalizedString
+ combobox: {
+ /**
+ * Search
+ */
+ search: () => LocalizedString
+ /**
+ * No records found
+ */
+ noRecordsFound: () => LocalizedString
+ /**
+ * Create a record by typing the name in the search bar and pressing enter
+ */
+ createRecordHelpText: () => LocalizedString
+ /**
+ * Press enter or click here to create {0}
+ */
+ createRecordButtonText: (arg0: unknown) => LocalizedString
+ }
+ signInPage: {
+ /**
+ * Sign in
+ */
+ title: () => LocalizedString
+ /**
+ * This is not my computer
+ */
+ notMyComputer: () => LocalizedString
+ /**
+ * Reset password
+ */
+ resetPassword: () => LocalizedString
+ /**
+ * Your password is updated
+ */
+ yourPasswordIsUpdated: () => LocalizedString
+ /**
+ * Sign In
+ */
+ signIn: () => LocalizedString
+ /**
+ * Your new password is applied
+ */
+ yourNewPasswordIsApplied: () => LocalizedString
+ /**
+ * Sign in below
+ */
+ signInBelow: () => LocalizedString
+ /**
+ * Your account is disabled
+ */
+ yourAccountIsDisabled: () => LocalizedString
+ /**
+ * Contact your administrator if this feels wrong
+ */
+ contactYourAdminIfDisabled: () => LocalizedString
+ /**
+ * You've reached the hidden inactivity limit
+ */
+ youHaveReachedInactivityLimit: () => LocalizedString
+ /**
+ * Feel free to sign in again
+ */
+ feelFreeToSignInAgain: () => LocalizedString
+ }
+ signUpPage: {
+ /**
+ * Sign up
+ */
+ title: () => LocalizedString
+ /**
+ * Create your new account
+ */
+ createYourNewAccount: () => LocalizedString
+ }
+ resetPasswordPage: {
+ /**
+ * Reset password
+ */
+ title: () => LocalizedString
+ /**
+ * Set new password
+ */
+ fulfillTitle: () => LocalizedString
+ /**
+ * Set a new password
+ */
+ setANewPassword: () => LocalizedString
+ /**
+ * Expired
+ */
+ expired: () => LocalizedString
+ /**
+ * Your request has expired
+ */
+ requestHasExpired: () => LocalizedString
+ /**
+ * Request a new reset
+ */
+ requestANewReset: () => LocalizedString
+ /**
+ * Your request is invalid
+ */
+ invalidRequestTitle: () => LocalizedString
+ /**
+ * This could be due to it being expired, nonexsistent or something else
+ */
+ invalidRequestMessage: () => LocalizedString
+ /**
+ * New password
+ */
+ newPassword: () => LocalizedString
+ /**
+ * If we find your email address in our systems, you will receive an email with instructions on how to set a new password for your account.
+ */
+ requestSentMessage: () => LocalizedString
+ /**
+ * Request a password reset
+ */
+ requestAPasswordReset: () => LocalizedString
+ /**
+ * Your request was not found
+ */
+ requestNotFound: () => LocalizedString
+ /**
+ * Submit a new reset request below
+ */
+ submitANewRequestBelow: () => LocalizedString
+ }
+ app: {
+ /**
+ * Members
+ */
+ members: () => LocalizedString
+ }
+}
+
+export type Formatters = {}
diff --git a/code/app/src/i18n/i18n-util.async.ts b/code/app/src/i18n/i18n-util.async.ts
new file mode 100644
index 0000000..2e6717e
--- /dev/null
+++ b/code/app/src/i18n/i18n-util.async.ts
@@ -0,0 +1,42 @@
+// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
+/* eslint-disable */
+
+import { initFormatters } from './formatters'
+import type { Locales, Namespaces, Translations } from './i18n-types'
+import { loadedFormatters, loadedLocales, locales } from './i18n-util'
+
+const localeTranslationLoaders = {
+ en: () => import('./en'),
+ nb: () => import('./nb'),
+}
+
+const localeNamespaceLoaders = {
+ en: {
+ app: () => import('./en/app')
+ },
+ nb: {
+ app: () => import('./nb/app')
+ }
+}
+
+const updateDictionary = (locale: Locales, dictionary: Partial<Translations>): Translations =>
+ loadedLocales[locale] = { ...loadedLocales[locale], ...dictionary }
+
+export const importLocaleAsync = async (locale: Locales): Promise<Translations> =>
+ (await localeTranslationLoaders[locale]()).default as unknown as Translations
+
+export const loadLocaleAsync = async (locale: Locales): Promise<void> => {
+ updateDictionary(locale, await importLocaleAsync(locale))
+ loadFormatters(locale)
+}
+
+export const loadAllLocalesAsync = (): Promise<void[]> => Promise.all(locales.map(loadLocaleAsync))
+
+export const loadFormatters = (locale: Locales): void =>
+ void (loadedFormatters[locale] = initFormatters(locale))
+
+export const importNamespaceAsync = async<Namespace extends Namespaces>(locale: Locales, namespace: Namespace) =>
+ (await localeNamespaceLoaders[locale][namespace]()).default as unknown as Translations[Namespace]
+
+export const loadNamespaceAsync = async <Namespace extends Namespaces>(locale: Locales, namespace: Namespace): Promise<void> =>
+ void updateDictionary(locale, { [namespace]: await importNamespaceAsync(locale, namespace )})
diff --git a/code/app/src/i18n/i18n-util.sync.ts b/code/app/src/i18n/i18n-util.sync.ts
new file mode 100644
index 0000000..8144fdc
--- /dev/null
+++ b/code/app/src/i18n/i18n-util.sync.ts
@@ -0,0 +1,35 @@
+// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
+/* eslint-disable */
+
+import { initFormatters } from './formatters'
+import type { Locales, Translations } from './i18n-types'
+import { loadedFormatters, loadedLocales, locales } from './i18n-util'
+
+import en from './en'
+import nb from './nb'
+
+import en_app from './en/app'
+import nb_app from './nb/app'
+
+const localeTranslations = {
+ en: {
+ ...en,
+ app: en_app
+ },
+ nb: {
+ ...nb,
+ app: nb_app
+ },
+}
+
+export const loadLocale = (locale: Locales): void => {
+ if (loadedLocales[locale]) return
+
+ loadedLocales[locale] = localeTranslations[locale] as unknown as Translations
+ loadFormatters(locale)
+}
+
+export const loadAllLocales = (): void => locales.forEach(loadLocale)
+
+export const loadFormatters = (locale: Locales): void =>
+ void (loadedFormatters[locale] = initFormatters(locale))
diff --git a/code/app/src/i18n/i18n-util.ts b/code/app/src/i18n/i18n-util.ts
new file mode 100644
index 0000000..5b7b6ed
--- /dev/null
+++ b/code/app/src/i18n/i18n-util.ts
@@ -0,0 +1,45 @@
+// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
+/* eslint-disable */
+
+import { i18n as initI18n, i18nObject as initI18nObject, i18nString as initI18nString } from 'typesafe-i18n'
+import type { LocaleDetector } from 'typesafe-i18n/detectors'
+import type { LocaleTranslationFunctions, TranslateByString } from 'typesafe-i18n'
+import { detectLocale as detectLocaleFn } from 'typesafe-i18n/detectors'
+import { initExtendDictionary } from 'typesafe-i18n/utils'
+import type { Formatters, Locales, Namespaces, Translations, TranslationFunctions } from './i18n-types'
+
+export const baseLocale: Locales = 'en'
+
+export const locales: Locales[] = [
+ 'en',
+ 'nb'
+]
+
+export const namespaces: Namespaces[] = [
+ 'app'
+]
+
+export const isLocale = (locale: string): locale is Locales => locales.includes(locale as Locales)
+
+
+ export const isNamespace = (namespace: string): namespace is Namespaces => namespaces.includes(namespace as Namespaces)
+
+export const loadedLocales: Record<Locales, Translations> = {} as Record<Locales, Translations>
+
+export const loadedFormatters: Record<Locales, Formatters> = {} as Record<Locales, Formatters>
+
+export const extendDictionary = initExtendDictionary<Translations>()
+
+export const i18nString = (locale: Locales): TranslateByString => initI18nString<Locales, Formatters>(locale, loadedFormatters[locale])
+
+export const i18nObject = (locale: Locales): TranslationFunctions =>
+ initI18nObject<Locales, Translations, TranslationFunctions, Formatters>(
+ locale,
+ loadedLocales[locale],
+ loadedFormatters[locale]
+ )
+
+export const i18n = (): LocaleTranslationFunctions<Locales, Translations, TranslationFunctions> =>
+ initI18n<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters)
+
+export const detectLocale = (...detectors: LocaleDetector[]): Locales => detectLocaleFn<Locales>(baseLocale, locales, ...detectors)
diff --git a/code/app/src/i18n/nb/app/index.ts b/code/app/src/i18n/nb/app/index.ts
new file mode 100644
index 0000000..6bf9ba6
--- /dev/null
+++ b/code/app/src/i18n/nb/app/index.ts
@@ -0,0 +1,7 @@
+import type { NamespaceAppTranslation } from '../../i18n-types'
+
+const nb_app: NamespaceAppTranslation = {
+ members: "Medlemmer"
+}
+
+export default nb_app
diff --git a/code/app/src/i18n/nb/index.ts b/code/app/src/i18n/nb/index.ts
new file mode 100644
index 0000000..ef67504
--- /dev/null
+++ b/code/app/src/i18n/nb/index.ts
@@ -0,0 +1,51 @@
+import type { Translation } from "../i18n-types";
+
+const nb: Translation = {
+ or: "Eller",
+ name: "Navn",
+ emailAddress: "E-postadresse",
+ password: "Passord",
+ pageNotFound: "Fant ikke siden",
+ noInternet: "Det ser ut som at du ikke tilkoblet internettet, sjekk tilkoblingen din for å fortsette",
+ reset: "Tilbakestill",
+ of: "{0} av {1}",
+ isRequired: "{0} er påkrevd",
+ submit: "Send",
+ success: "Suksess",
+ tryAgainSoon: "Prøv igjen snart",
+ createANewAccount: "Lag en ny konto",
+ unexpectedError: "En uventet feil oppstod",
+ notFound: "Ikke funnet",
+ documentation: "Dokumentasjon",
+ tos: "Vilkår",
+ privacyPolicy: "Personvernerklæring",
+ signIntoYourAccount: "Logg inn med din konto",
+ signInPage: {
+ notMyComputer: "Dette er ikke min datamaskin",
+ resetPassword: "Tilbakestill passord",
+ yourPasswordIsUpdated: "Ditt passord er oppdater",
+ signIn: "Logg inn",
+ yourNewPasswordIsApplied: "Ditt nye passord er satt",
+ signInBelow: "Logg inn nedenfor",
+ yourAccountIsDisabled: "Din konto er deaktivert",
+ contactYourAdminIfDisabled: "Ta kontakt med din administrator hvis dette føles feil",
+ youHaveReachedInactivityLimit: "Du har nådd den hemmelige inaktivitetsgrensen",
+ feelFreeToSignInAgain: "Logg gjerne inn igjen"
+ },
+ signUpPage: {
+ createYourNewAccount: "Opprett din nye konto",
+ },
+ resetPasswordPage: {
+ setANewPassword: "Skriv et nytt passord",
+ expired: "Utgått",
+ requestHasExpired: "Din forespørsel er utgått",
+ requestANewReset: "Spør om en ny tilbakestillingslenke",
+ newPassword: "Nytt passord",
+ requestSentMessage: "Hvis vi finner e-postadressen din i våre systemer, vil du få en e-post med instrukser for å sette ditt nye passord.",
+ requestAPasswordReset: "Forespør tilbakestilling av ditt passord",
+ requestNotFound: "Din forespørsel ble ikke funnet",
+ submitANewRequestBelow: "Spør om en ny tilbakestillingslenke nedenfor"
+ }
+}
+
+export default nb; \ No newline at end of file
diff --git a/code/app/src/models/base/Customer.ts b/code/app/src/models/base/Customer.ts
new file mode 100644
index 0000000..ff52fbd
--- /dev/null
+++ b/code/app/src/models/base/Customer.ts
@@ -0,0 +1,21 @@
+import type {CustomerContact} from "./CustomerContact";
+import type {User} from "./User";
+
+export type Customer = {
+ /**
+ * Guid id for customer
+ */
+ id: string,
+ /**
+ * The name of the company
+ */
+ name: string,
+ /**
+ * Responsible contact in the current tenant
+ */
+ tenantContact: User,
+ /**
+ * The customers main contact
+ */
+ mainContact: CustomerContact,
+} \ No newline at end of file
diff --git a/code/app/src/models/base/CustomerContact.ts b/code/app/src/models/base/CustomerContact.ts
new file mode 100644
index 0000000..e8abea5
--- /dev/null
+++ b/code/app/src/models/base/CustomerContact.ts
@@ -0,0 +1,8 @@
+export type CustomerContact = {
+ firstName: string,
+ lastname: string,
+ email: string,
+ phone: string,
+ workTitle: string,
+ note: string
+} \ No newline at end of file
diff --git a/code/app/src/models/base/CustomerEvent.ts b/code/app/src/models/base/CustomerEvent.ts
new file mode 100644
index 0000000..af86511
--- /dev/null
+++ b/code/app/src/models/base/CustomerEvent.ts
@@ -0,0 +1,6 @@
+export type CustomerEvent = {
+ /**
+ * A descriptive name for the occured event
+ */
+ name: string,
+} \ No newline at end of file
diff --git a/code/app/src/models/base/SessionData.ts b/code/app/src/models/base/SessionData.ts
new file mode 100644
index 0000000..015cbf3
--- /dev/null
+++ b/code/app/src/models/base/SessionData.ts
@@ -0,0 +1,5 @@
+export type SessionData = {
+ id: string,
+ username: string,
+ displayName: string,
+} \ No newline at end of file
diff --git a/code/app/src/models/base/Tenant.ts b/code/app/src/models/base/Tenant.ts
new file mode 100644
index 0000000..6307efc
--- /dev/null
+++ b/code/app/src/models/base/Tenant.ts
@@ -0,0 +1,8 @@
+import type {User} from "./User";
+
+export type Tenant = {
+ id: string,
+ name: string,
+ description: string,
+ masterUser: User,
+} \ No newline at end of file
diff --git a/code/app/src/models/base/User.ts b/code/app/src/models/base/User.ts
new file mode 100644
index 0000000..2b74d0e
--- /dev/null
+++ b/code/app/src/models/base/User.ts
@@ -0,0 +1,13 @@
+import type {UserRole} from "./UserRole";
+
+export type User = {
+ /**
+ * Guid id for user
+ */
+ id: string,
+ firstName: string,
+ lastName: string,
+ role: UserRole,
+ username: string,
+ email: string
+} \ No newline at end of file
diff --git a/code/app/src/models/base/UserRole.ts b/code/app/src/models/base/UserRole.ts
new file mode 100644
index 0000000..ec32852
--- /dev/null
+++ b/code/app/src/models/base/UserRole.ts
@@ -0,0 +1,5 @@
+export enum UserRole {
+ REGULAR = "reg",
+ ADMINISTRATOR = "adm",
+ OWNER = "own"
+} \ No newline at end of file
diff --git a/code/app/src/models/internal/FormError.ts b/code/app/src/models/internal/FormError.ts
new file mode 100644
index 0000000..f6d8978
--- /dev/null
+++ b/code/app/src/models/internal/FormError.ts
@@ -0,0 +1,24 @@
+import type { KnownProblem } from "./KnownProblem";
+
+export class FormError {
+ title: string;
+ subtitle: string;
+ constructor(title: string = "", subtitle: string = "") {
+ this.title = title;
+ this.title = subtitle;
+ }
+
+ set(title: string = "", subtitle: string = "") {
+ this.title = title;
+ this.subtitle = subtitle;
+ }
+
+ set_from_known_problem(knownProblem: KnownProblem) {
+ this.title = knownProblem.title ?? "";
+ this.subtitle = knownProblem.subtitle ?? "";
+ }
+
+ has_error() {
+ return this.title?.length > 0 || this.subtitle?.length > 0;
+ }
+} \ No newline at end of file
diff --git a/code/app/src/models/internal/IForm.ts b/code/app/src/models/internal/IForm.ts
new file mode 100644
index 0000000..c14b770
--- /dev/null
+++ b/code/app/src/models/internal/IForm.ts
@@ -0,0 +1,15 @@
+import type { FormError } from "./FormError";
+
+export interface IForm {
+ fields: Record<string, IFormField>;
+ error: FormError;
+ get_payload: Function;
+ submit_async: Function;
+ isLoading: boolean;
+ showError: boolean;
+}
+
+export interface IFormField {
+ value: any;
+ errors: Array<string>;
+}
diff --git a/code/app/src/models/internal/KnownProblem.ts b/code/app/src/models/internal/KnownProblem.ts
new file mode 100644
index 0000000..b6923d9
--- /dev/null
+++ b/code/app/src/models/internal/KnownProblem.ts
@@ -0,0 +1,10 @@
+export type KnownProblem = {
+ title: string,
+ subtitle: string,
+ errors: Record<string, string[]>,
+ traceId: string,
+}
+
+export function is_known_problem(response: Response): boolean {
+ return response.headers.has("X-IsKnownProblem");
+} \ No newline at end of file
diff --git a/code/app/src/models/projects/Project.ts b/code/app/src/models/projects/Project.ts
new file mode 100644
index 0000000..f265e67
--- /dev/null
+++ b/code/app/src/models/projects/Project.ts
@@ -0,0 +1,13 @@
+import type { Temporal } from "temporal-polyfill"
+import type { ProjectMember } from "./ProjectMember"
+import type { ProjectStatus } from "./ProjectStatus"
+
+export type Project = {
+ id: string,
+ name: string,
+ description?: string,
+ start: Temporal.PlainDate,
+ stop?: Temporal.PlainDate,
+ members: Array<ProjectMember>,
+ status: ProjectStatus
+} \ No newline at end of file
diff --git a/code/app/src/models/projects/ProjectLabel.ts b/code/app/src/models/projects/ProjectLabel.ts
new file mode 100644
index 0000000..59aa9d5
--- /dev/null
+++ b/code/app/src/models/projects/ProjectLabel.ts
@@ -0,0 +1,5 @@
+export type ProjectLabel = {
+ id: string,
+ name: string,
+ color: string
+} \ No newline at end of file
diff --git a/code/app/src/models/projects/ProjectMember.ts b/code/app/src/models/projects/ProjectMember.ts
new file mode 100644
index 0000000..de348ef
--- /dev/null
+++ b/code/app/src/models/projects/ProjectMember.ts
@@ -0,0 +1,10 @@
+import type { ProjectRole } from "./ProjectRole"
+
+export type ProjectMember = {
+ id: string,
+ name: string,
+ role: ProjectRole,
+ email: string,
+ userId?: string,
+ customerId?: string
+} \ No newline at end of file
diff --git a/code/app/src/models/projects/ProjectMeta.ts b/code/app/src/models/projects/ProjectMeta.ts
new file mode 100644
index 0000000..c583b47
--- /dev/null
+++ b/code/app/src/models/projects/ProjectMeta.ts
@@ -0,0 +1,7 @@
+import type { Temporal } from "temporal-polyfill"
+import type { User } from "../base/User"
+
+export type ProjectMeta = {
+ created: Temporal.PlainDateTime,
+ createdBy: User,
+} \ No newline at end of file
diff --git a/code/app/src/models/projects/ProjectRole.ts b/code/app/src/models/projects/ProjectRole.ts
new file mode 100644
index 0000000..0fa2347
--- /dev/null
+++ b/code/app/src/models/projects/ProjectRole.ts
@@ -0,0 +1,7 @@
+export enum ProjectRole {
+ EXTERNAL = "ext",
+ INTERNAL = "int",
+ RESOURCE = "res",
+ MANAGER = "man",
+ OWNER = "own"
+} \ No newline at end of file
diff --git a/code/app/src/models/projects/ProjectStatus.ts b/code/app/src/models/projects/ProjectStatus.ts
new file mode 100644
index 0000000..2df4b88
--- /dev/null
+++ b/code/app/src/models/projects/ProjectStatus.ts
@@ -0,0 +1,5 @@
+export enum ProjectStatus {
+ ACTIVE = "act",
+ EXPIRED = "exp",
+ IDLE = "idl"
+} \ No newline at end of file
diff --git a/code/app/src/models/work/WorkCategory.ts b/code/app/src/models/work/WorkCategory.ts
new file mode 100644
index 0000000..7dd85d5
--- /dev/null
+++ b/code/app/src/models/work/WorkCategory.ts
@@ -0,0 +1,5 @@
+export type WorkCategory = {
+ id: string,
+ name: string,
+ color: string
+}
diff --git a/code/app/src/models/work/WorkEntry.ts b/code/app/src/models/work/WorkEntry.ts
new file mode 100644
index 0000000..2108b88
--- /dev/null
+++ b/code/app/src/models/work/WorkEntry.ts
@@ -0,0 +1,13 @@
+import type { WorkLabel } from "./WorkLabel";
+import type { WorkCategory } from "./WorkCategory";
+import type { Project } from "../projects/Project";
+
+export type WorkEntry = {
+ id: string,
+ start: string,
+ stop: string,
+ description: string,
+ labels?: Array<WorkLabel>,
+ category?: WorkCategory,
+ project?: Project
+}
diff --git a/code/app/src/models/work/WorkEntryQueryResponse.ts b/code/app/src/models/work/WorkEntryQueryResponse.ts
new file mode 100644
index 0000000..a6974f1
--- /dev/null
+++ b/code/app/src/models/work/WorkEntryQueryResponse.ts
@@ -0,0 +1,27 @@
+import type { WorkCategory } from "./WorkCategory";
+import type { WorkLabel } from "./WorkLabel";
+import type { Temporal } from "temporal-polyfill";
+
+export interface WorkEntryQueryResponse {
+ duration: WorkEntryQueryDuration,
+ categories?: Array<WorkCategory>,
+ labels?: Array<WorkLabel>,
+ dateRange?: WorkEntryQueryDateRange,
+ specificDate?: Temporal.PlainDateTime
+ page: number,
+ pageSize: number
+}
+
+export interface WorkEntryQueryDateRange {
+ from: Temporal.PlainDateTime,
+ to: Temporal.PlainDateTime
+}
+
+export enum WorkEntryQueryDuration {
+ TODAY = 0,
+ THIS_WEEK = 1,
+ THIS_MONTH = 2,
+ THIS_YEAR = 3,
+ SPECIFIC_DATE = 4,
+ DATE_RANGE = 5,
+}
diff --git a/code/app/src/models/work/WorkLabel.ts b/code/app/src/models/work/WorkLabel.ts
new file mode 100644
index 0000000..f7e2795
--- /dev/null
+++ b/code/app/src/models/work/WorkLabel.ts
@@ -0,0 +1,5 @@
+export interface WorkLabel {
+ id?: string,
+ name?: string,
+ color?: string
+}
diff --git a/code/app/src/models/work/WorkQuery.ts b/code/app/src/models/work/WorkQuery.ts
new file mode 100644
index 0000000..93b0aa4
--- /dev/null
+++ b/code/app/src/models/work/WorkQuery.ts
@@ -0,0 +1,17 @@
+import type {WorkEntry} from "./WorkEntry";
+
+export interface IWorkQuery {
+ results: Array<WorkEntry>,
+ page: number,
+ pageSize: number,
+ totalRecords: number,
+ totalPageCount: number,
+}
+
+export class WorkQuery implements IWorkQuery {
+ results: WorkEntry[];
+ page: number;
+ pageSize: number;
+ totalRecords: number;
+ totalPageCount: number;
+}
diff --git a/code/app/src/routes/(api)/delete-cookie/+server.ts b/code/app/src/routes/(api)/delete-cookie/+server.ts
new file mode 100644
index 0000000..ee5e1dc
--- /dev/null
+++ b/code/app/src/routes/(api)/delete-cookie/+server.ts
@@ -0,0 +1,8 @@
+import type { RequestHandler } from './$types';
+
+export const GET: RequestHandler = async ({ cookies, url }) => {
+ const cookieToDelete = url.searchParams.get("key");
+ if (!cookieToDelete || cookies.get(cookieToDelete) === undefined) return;
+ cookies.delete(cookieToDelete)
+ return new Response();
+}; \ No newline at end of file
diff --git a/code/app/src/routes/(main)/(app)/+layout.svelte b/code/app/src/routes/(main)/(app)/+layout.svelte
new file mode 100644
index 0000000..09dbb47
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/+layout.svelte
@@ -0,0 +1,379 @@
+<script lang="ts">
+ import {
+ ChevronUpDownIcon,
+ MagnifyingGlassIcon,
+ Bars3CenterLeftIcon,
+ XMarkIcon,
+ HomeIcon,
+ MegaphoneIcon,
+ FolderOpenIcon,
+ QueueListIcon,
+ CalendarIcon,
+ } from "$components/icons";
+ import { AccountService } from "$services/account-service";
+ import {
+ Dialog,
+ Menu,
+ MenuButton,
+ MenuItem,
+ MenuItems,
+ Transition,
+ TransitionChild,
+ TransitionRoot,
+ } from "@rgossiaux/svelte-headlessui";
+ import { DialogPanel } from "@developermuch/dev-svelte-headlessui";
+ import { Input, Notification } from "$components";
+ import { goto } from "$app/navigation";
+ import { page } from "$app/stores";
+ import { onMount } from "svelte";
+ import { fgs, sgs } from "$utilities/global-state";
+
+ const accountService = AccountService.resolve();
+ const session = {
+ profile: {
+ username: "Brukernavn",
+ displayName: "epost@adresse.no",
+ },
+ };
+
+ let sidebarOpen = false;
+ let sidebarSearchValue: string | undefined;
+ let showEmailValidatedNotif = false;
+
+ onMount(() => {
+ showEmailValidatedNotif =
+ fgs("showEmailValidatedAlertWhenLoggedIn") === "true";
+ if (showEmailValidatedNotif)
+ sgs("showEmailValidatedAlertWhenLoggedIn", false);
+ });
+
+ function sign_out() {
+ accountService.end_session(() => goto("/sign-in"));
+ }
+ const navigationItems = [
+ {
+ href: "/home",
+ name: "Home",
+ icon: HomeIcon,
+ },
+ {
+ href: "/projects",
+ name: "Projects",
+ icon: CalendarIcon,
+ },
+ {
+ href: "/tickets",
+ name: "Tickets",
+ icon: MegaphoneIcon,
+ },
+ {
+ href: "/todo",
+ name: "Todo",
+ icon: QueueListIcon,
+ },
+ {
+ href: "/wiki",
+ name: "Wiki",
+ icon: FolderOpenIcon,
+ },
+ ];
+</script>
+
+{#if showEmailValidatedNotif}
+ <Notification
+ title="Email successfully validated"
+ subtitle="Because of this, you now have gained access to more functionality"
+ show={true}
+ />
+{/if}
+
+<div class="min-h-full">
+ <!-- Mobile sidebar -->
+ <TransitionRoot show={sidebarOpen}>
+ <Dialog
+ as="div"
+ class="relative z-40 lg:hidden"
+ on:close={() => (sidebarOpen = false)}
+ >
+ <TransitionChild
+ as="div"
+ enter="transition-opacity ease-linear duration-300"
+ enterFrom="opacity-0"
+ enterTo="opacity-100"
+ leave="transition-opacity ease-linear duration-300"
+ leaveFrom="opacity-100"
+ leaveTo="opacity-0"
+ >
+ <div class="fixed inset-0 bg-gray-600 bg-opacity-75" />
+ </TransitionChild>
+
+ <div class="fixed inset-0 z-40 flex">
+ <TransitionChild
+ as="div"
+ enter="transition ease-in-out duration-300 transform"
+ enterFrom="-translate-x-full"
+ enterTo="translate-x-0"
+ leave="transition ease-in-out duration-300 transform"
+ leaveFrom="translate-x-0"
+ leaveTo="-translate-x-full"
+ >
+ <DialogPanel
+ class="relative flex w-full max-w-xs flex-1 flex-col bg-white pt-5 pb-4"
+ >
+ <TransitionChild
+ as="div"
+ enter="ease-in-out duration-300"
+ enterFrom="opacity-0"
+ enterTo="opacity-100"
+ leave="ease-in-out duration-300"
+ leaveFrom="opacity-100"
+ leaveTo="opacity-0"
+ >
+ <div class="absolute top-0 right-0 -mr-12 pt-2">
+ <button
+ type="button"
+ class="ml-1 flex h-10 w-10 items-center justify-center rounded-full focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white"
+ on:click={() => (sidebarOpen = false)}
+ >
+ <span class="sr-only">Close sidebar</span>
+ <XMarkIcon class="text-white" aria-hidden="true" />
+ </button>
+ </div>
+ </TransitionChild>
+ <div class="mt-5 h-0 flex-1 overflow-y-auto">
+ <nav class="px-2">
+ <div class="space-y-1">
+ {#each navigationItems as item}
+ {@const current = $page.url.pathname.startsWith(item.href)}
+ <a
+ href={item.href}
+ aria-current={current ? "page" : undefined}
+ class="group flex items-center px-2 py-2 text-base leading-5 font-medium rounded-md
+ {current
+ ? 'bg-gray-100 text-gray-900'
+ : 'text-gray-600 hover:text-gray-900 hover:bg-gray-50'}"
+ >
+ <svelte:component
+ this={item.icon}
+ class="mr-3 flex-shrink-0 h-6 w-6 {current
+ ? 'text-gray-500'
+ : 'text-gray-400 group-hover:text-gray-500'}"
+ aria-hidden="true"
+ />
+ {item.name}
+ </a>
+ {/each}
+ </div>
+ </nav>
+ </div>
+ </DialogPanel>
+ </TransitionChild>
+ <div class="w-14 flex-shrink-0" aria-hidden="true">
+ <!-- Dummy element to force sidebar to shrink to fit close icon -->
+ </div>
+ </div>
+ </Dialog>
+ </TransitionRoot>
+
+ <!-- Static sidebar for desktop -->
+ <div
+ class="hidden lg:fixed lg:inset-y-0 lg:flex lg:w-64 lg:flex-col lg:border-r lg:border-gray-200 lg:bg-gray-100 lg:pb-4"
+ >
+ <div class="flex h-0 flex-1 p-3 flex-col overflow-y-auto">
+ <!-- User account dropdown -->
+ <Menu class="relative inline-block text-left">
+ <MenuButton
+ class="group w-full rounded-md bg-gray-100 px-3.5 py-2 text-left text-sm font-medium text-gray-700 hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-teal-500 focus:ring-offset-2 focus:ring-offset-gray-100"
+ >
+ <span class="flex w-full items-center justify-between">
+ <span class="flex min-w-0 items-center justify-between space-x-3">
+ <span class="flex min-w-0 flex-1 flex-col">
+ <span class="truncate text-sm font-medium text-gray-900">
+ {session.profile.username}
+ </span>
+ <span class="truncate text-sm text-gray-500"
+ >{session.profile.displayName}</span
+ >
+ </span>
+ </span>
+ <ChevronUpDownIcon
+ class="flex-shrink-0 text-gray-400 group-hover:text-gray-500"
+ aria-hidden="true"
+ />
+ </span>
+ </MenuButton>
+ <Transition
+ leave="transition ease-in duration-75"
+ enter="transition ease-out duration-100"
+ enterFrom="transform opacity-0 scale-95"
+ enterTo="transform opacity-100 scale-100"
+ leaveFrom="transform opacity-100 scale-100"
+ leaveTo="transform opacity-0 scale-95"
+ as="div"
+ >
+ <MenuItems
+ class="absolute right-0 left-0 z-10 mt-1 origin-top divide-y divide-gray-200 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"
+ >
+ <div class="py-1">
+ <MenuItem>
+ <a
+ href="/profile"
+ class="text-gray-700 block px-4 py-2 text-sm hover:text-gray-900 hover:bg-gray-100"
+ >
+ View profile
+ </a>
+ </MenuItem>
+ <MenuItem>
+ <a
+ href="/settings"
+ class="text-gray-700 block px-4 py-2 text-sm hover:text-gray-900 hover:bg-gray-100"
+ >
+ Settings
+ </a>
+ </MenuItem>
+ </div>
+ <div class="py-1">
+ <MenuItem>
+ <span
+ on:click={() => sign_out()}
+ class="text-gray-700 block px-4 py-2 text-sm hover:bg-red-200 hover:text-red-900 cursor-pointer"
+ >
+ Sign out
+ </span>
+ </MenuItem>
+ </div>
+ </MenuItems>
+ </Transition>
+ </Menu>
+ <!-- Sidebar Search -->
+ <div class="mt-3 hidden">
+ <label for="search" class="sr-only">Search</label>
+ <div class="relative mt-1 rounded-md shadow-sm">
+ <Input
+ type="search"
+ name="search"
+ icon={MagnifyingGlassIcon}
+ placeholder="Search"
+ bind:value={sidebarSearchValue}
+ />
+ </div>
+ </div>
+ <!-- Navigation -->
+ <nav class="mt-5">
+ <div class="space-y-1">
+ {#each navigationItems as item}
+ {@const current = $page.url.pathname.startsWith(item.href)}
+ <a
+ href={item.href}
+ aria-current={current ? "page" : undefined}
+ class="group flex items-center px-2 py-2 text-base leading-5 font-medium rounded-md
+ {current
+ ? 'bg-gray-200 text-gray-900'
+ : 'text-gray-700 hover:text-gray-900 hover:bg-gray-50'}"
+ >
+ <svelte:component
+ this={item.icon}
+ class="mr-3 flex-shrink-0 h-6 w-6 {current
+ ? 'text-gray-500'
+ : 'text-gray-400 group-hover:text-gray-500'}"
+ aria-hidden="true"
+ />
+ {item.name}
+ </a>
+ {/each}
+ </div>
+ </nav>
+ </div>
+ </div>
+
+ <!-- Main column -->
+ <div class="flex flex-col lg:pl-64">
+ <!-- Search header -->
+ <div
+ class="sticky top-0 z-10 flex h-16 flex-shrink-0 border-b border-gray-200 bg-white lg:hidden"
+ >
+ <button
+ type="button"
+ class="border-r border-gray-200 px-4 text-gray-500 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-teal-500 lg:hidden"
+ on:click={() => (sidebarOpen = true)}
+ >
+ <span class="sr-only">Open sidebar</span>
+ <Bars3CenterLeftIcon aria-hidden="true" />
+ </button>
+ <div class="flex flex-1 justify-between px-4 sm:px-6 lg:px-8">
+ <div class="flex flex-1">
+ <form class="flex w-full md:ml-0" action="#" method="GET">
+ <label for="search-field" class="sr-only">Search</label>
+ <div
+ class="relative w-full text-gray-400 focus-within:text-gray-600"
+ >
+ <Input
+ bind:value={sidebarSearchValue}
+ icon={MagnifyingGlassIcon}
+ id="search-field"
+ name="search-field"
+ placeholder="Search"
+ type="search"
+ />
+ </div>
+ </form>
+ </div>
+ <div class="flex items-center">
+ <!-- Profile dropdown -->
+ <Menu as="div" class="relative ml-3">
+ <div>
+ <MenuButton
+ class="flex max-w-xs items-center rounded-full bg-white text-sm focus:outline-none focus:ring-2 focus:ring-teal-500 focus:ring-offset-2"
+ >
+ <span class="sr-only">Open user menu</span>
+ </MenuButton>
+ </div>
+ <Transition
+ enterFrom="transform opacity-0 scale-95"
+ enterTo="transform opacity-100 scale-100"
+ leaveFrom="transform opacity-100 scale-100"
+ leaveTo="transform opacity-0 scale-95"
+ as="div"
+ >
+ <MenuItems
+ class="absolute right-0 z-10 mt-2 w-48 origin-top-right divide-y divide-gray-200 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"
+ >
+ <div class="py-1">
+ <MenuItem>
+ <a
+ href="/profile"
+ class="text-gray-700 block px-4 py-2 text-sm"
+ >
+ View profile
+ </a>
+ </MenuItem>
+ <MenuItem>
+ <a
+ href="/settings"
+ class="text-gray-700 block px-4 py-2 text-sm hover:text-gray-900 hover:bg-gray-100"
+ >
+ Settings
+ </a>
+ </MenuItem>
+ <div class="py-1">
+ <MenuItem>
+ <span
+ on:click={() => sign_out()}
+ class="text-gray-700 block px-4 py-2 text-sm"
+ >
+ Sign out
+ </span>
+ </MenuItem>
+ </div>
+ </div>
+ </MenuItems>
+ </Transition>
+ </Menu>
+ </div>
+ </div>
+ </div>
+ <main class="flex-1 p-3">
+ <slot />
+ </main>
+ </div>
+</div>
diff --git a/code/app/src/routes/(main)/(app)/home/+page.svelte b/code/app/src/routes/(main)/(app)/home/+page.svelte
new file mode 100644
index 0000000..247ee47
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/home/+page.svelte
@@ -0,0 +1 @@
+<h1>Welcome Home</h1> \ No newline at end of file
diff --git a/code/app/src/routes/(main)/(app)/org/+page.svelte b/code/app/src/routes/(main)/(app)/org/+page.svelte
new file mode 100644
index 0000000..429ec25
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/org/+page.svelte
@@ -0,0 +1,4 @@
+<script lang="ts">
+</script>
+
+<h1>$ORGNAME</h1>
diff --git a/code/app/src/routes/(main)/(app)/profile/+page.svelte b/code/app/src/routes/(main)/(app)/profile/+page.svelte
new file mode 100644
index 0000000..7c6eb3e
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/profile/+page.svelte
@@ -0,0 +1,4 @@
+<script lang="ts">
+</script>
+
+<h1>Hi, Ivar</h1>
diff --git a/code/app/src/routes/(main)/(app)/projects/+page.svelte b/code/app/src/routes/(main)/(app)/projects/+page.svelte
new file mode 100644
index 0000000..2585331
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/projects/+page.svelte
@@ -0,0 +1,118 @@
+<script lang="ts">
+ import { Button, ProjectStatusBadge, Input } from "$components";
+ import type { Project } from "$models/projects/Project";
+ import { createTable, Subscribe, Render } from "svelte-headless-table";
+ import { addSortBy, addTableFilter } from "svelte-headless-table/plugins";
+ import { writable, type Writable } from "svelte/store";
+ import { ChevronDownIcon, ChevronUpIcon, ChevronUpDownIcon, MagnifyingGlassIcon, FunnelIcon } from "$components/icons";
+ import LL from "$i18n/i18n-svelte";
+ import { goto } from "$app/navigation";
+
+ const projects: Writable<Array<Project>> = writable([]);
+
+ function on_open_project(event) {
+ if (event.code && (event.code !== "Enter" || event.code !== "Space")) return;
+ const name = event.target.innerText;
+ const projectId = $projects.find((p) => p.name === name).id;
+ goto("/projects/" + projectId);
+ }
+
+ const table = createTable(projects, {
+ sort: addSortBy(),
+ filter: addTableFilter(),
+ });
+
+ const columns = table.createColumns([
+ table.column({ header: $LL.name(), accessor: "name" }),
+ table.column({ header: "Status", accessor: "status" }),
+ table.column({ header: "Start", accessor: "start" }),
+ table.column({ header: "Description", accessor: "description", plugins: { sort: { disable: true } } }),
+ ]);
+
+ const { headerRows, rows, tableAttrs, tableBodyAttrs, pluginStates } = table.createViewModel(columns);
+ const { filterValue } = pluginStates.filter;
+</script>
+
+<div class="sm:flex sm:items-center">
+ <div class="sm:flex-auto">
+ <h1 class="text-xl font-semibold text-gray-900">Projects</h1>
+ <p class="mt-2 text-sm text-gray-700">A list of all the projects in your organsation.</p>
+ </div>
+ <div class="mt-4 sm:mt-0 sm:ml-16 inline-flex gap-1 sm:flex-none">
+ <Input icon={MagnifyingGlassIcon} placeholder="Search" bind:value={$filterValue} />
+ <Button text="Create project" href="/projects/create" />
+ </div>
+</div>
+<div class="-mx-2 mt-6 rounded-md shadow overflow-auto max-h-[80vh] sm:-mx-6 md:mx-0">
+ <table {...$tableAttrs} class="min-w-full divide-y divide-gray-300">
+ <thead class="bg-gray-50">
+ {#each $headerRows as headerRow (headerRow.id)}
+ <Subscribe rowAttrs={headerRow.attrs()} let:rowAttrs>
+ <tr {...rowAttrs} class="shadow-sm">
+ {#each headerRow.cells as cell (cell.id)}
+ <Subscribe attrs={cell.attrs()} let:attrs props={cell.props()} let:props>
+ <th
+ {...attrs}
+ scope="col"
+ class="sticky top-0 bg-gray-50 bg-opacity-100 whitespace-nowrap px-2 py-3.5 text-left text-sm font-semibold text-gray-900"
+ >
+ <div class="group inline-flex">
+ <Render of={cell.render()} />
+ <span
+ on:click={props.sort.toggle}
+ on:keypress={props.sort.toggle}
+ class="{props.sort.disabled
+ ? 'bg-gray-200 text-gray-900 group-hover:bg-gray-300'
+ : 'invisible text-gray-400 group-hover:visible group-focus:visible'}
+ {props.sort.disabled ? '' : 'cursor-pointer'}
+ ml-2 flex-none rounded"
+ >
+ {#if props.sort.order === "asc"}
+ <ChevronUpIcon />
+ {:else if props.sort.order === "desc"}
+ <ChevronDownIcon />
+ {:else if !props.sort.disabled}
+ <ChevronUpDownIcon />
+ {/if}
+ </span>
+ {#if cell.id === "status"}
+ <span
+ class="invisible text-gray-400 cursor-pointer group-hover:visible group-focus:visible ml-2 flex-none rounded"
+ >
+ <FunnelIcon />
+ </span>
+ {/if}
+ </div>
+ </th>
+ </Subscribe>
+ {/each}
+ </tr>
+ </Subscribe>
+ {/each}
+ </thead>
+ <tbody {...$tableBodyAttrs} class="divide-y divide-gray-200 bg-white">
+ {#each $rows as row (row.id)}
+ <Subscribe rowAttrs={row.attrs()} let:rowAttrs>
+ <tr {...rowAttrs}>
+ {#each row.cells as cell (cell.id)}
+ {@const materialisedCell = cell.render()}
+ <Subscribe attrs={cell.attrs()} let:attrs>
+ <td {...attrs} class="whitespace-nowrap px-2 py-2 text-sm">
+ {#if cell.id === "name"}
+ <span class="link" title="Open project" on:click={on_open_project} on:keypress={on_open_project}>
+ <Render of={materialisedCell} />
+ </span>
+ {:else if cell.id === "status"}
+ <ProjectStatusBadge status={materialisedCell.toString()} />
+ {:else}
+ <Render of={materialisedCell} />
+ {/if}
+ </td>
+ </Subscribe>
+ {/each}
+ </tr>
+ </Subscribe>
+ {/each}
+ </tbody>
+ </table>
+</div>
diff --git a/code/app/src/routes/(main)/(app)/projects/[id]/+page.svelte b/code/app/src/routes/(main)/(app)/projects/[id]/+page.svelte
new file mode 100644
index 0000000..ca474e2
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/projects/[id]/+page.svelte
@@ -0,0 +1,5 @@
+<script lang="ts">
+ import { page } from "$app/stores";
+</script>
+
+<h1>{$page.params.id}</h1>
diff --git a/code/app/src/routes/(main)/(app)/projects/create/+page.svelte b/code/app/src/routes/(main)/(app)/projects/create/+page.svelte
new file mode 100644
index 0000000..d710edc
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/projects/create/+page.svelte
@@ -0,0 +1,59 @@
+<script lang="ts">
+ import { Input, TextArea, Combobox, Button } from "$components";
+ import type { ProjectMember } from "$models/projects/ProjectMember";
+ import LL from "$i18n/i18n-svelte";
+
+ let members = [];
+ const formData = {
+ name: {
+ value: "",
+ errors: [],
+ },
+ description: {
+ value: "",
+ errors: [],
+ },
+ start: {
+ value: "",
+ errors: [],
+ },
+ stop: {
+ value: "",
+ errors: [],
+ },
+ members: {
+ value: [] as Array<ProjectMember>,
+ errors: [],
+ },
+ };
+
+ const formError = {
+ title: "",
+ subtitle: "",
+ };
+
+ async function submit_form_async() {
+ alert("Submitted");
+ }
+</script>
+
+<h1>Create a new project</h1>
+<form on:submit|preventDefault={submit_form_async} class="max-w-md flex flex-col gap-2">
+ <Input label="Name" bind:value={formData.name.value} errors={formData.name.errors} required />
+ <TextArea label="Description" bind:value={formData.description.value} errors={formData.description.errors} />
+ <section class="grid grid-flow-row sm:grid-flow-col gap-2">
+ <Input type="date" label="Start" bind:value={formData.start.value} errors={formData.start.errors} />
+ <Input type="date" label="Stop" bind:value={formData.stop.value} errors={formData.stop.errors} />
+ </section>
+ <Combobox options={members} label={$LL.app.members()}>
+ <svelte:fragment slot="no-records">
+ <h1>No members found</h1>
+ {#if !members?.length}
+ <p>
+ <a href="/users/create" class="link">Click here</a> to create your first user
+ </p>
+ {/if}
+ </svelte:fragment>
+ </Combobox>
+ <Button text={$LL.submit()} />
+</form>
diff --git a/code/app/src/routes/(main)/(app)/settings/+page.svelte b/code/app/src/routes/(main)/(app)/settings/+page.svelte
new file mode 100644
index 0000000..8e99661
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/settings/+page.svelte
@@ -0,0 +1,205 @@
+<script lang="ts">
+ import {Input, Button, Switch} from "$components";
+</script>
+
+<div class="relative mx-auto max-w-4xl md:px-8 xl:px-0">
+ <div class="pt-10 pb-16">
+ <div class="px-4 sm:px-6 md:px-0">
+ <h1 class="text-3xl font-bold tracking-tight text-gray-900">Settings</h1>
+ </div>
+ <div class="px-4 sm:px-6 md:px-0">
+ <div class="py-6">
+ <!-- Tabs -->
+ <div class="lg:hidden">
+ <label for="selected-tab" class="sr-only">Select a tab</label>
+ <select
+ id="selected-tab"
+ name="selected-tab"
+ class="mt-1 block w-full rounded-md border-gray-300 py-2 pl-3 pr-10 text-base focus:border-purple-500 focus:outline-none focus:ring-purple-500 sm:text-sm"
+ >
+ <option selected>General</option>
+
+ <option>Password</option>
+
+ <option>Notifications</option>
+
+>
+
+ <option>Billing</option>
+
+ <option>Team Members</option>
+ </select>
+ </div>
+ <div class="hidden lg:block">
+ <div class="border-b border-gray-200">
+ <nav class="-mb-px flex space-x-8">
+ <!-- Current: "border-purple-500 text-purple-600", Default: "border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700" -->
+ <a href="#"
+ class="border-purple-500 text-purple-600 whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm"
+ >General</a
+ >
+
+ <a
+ href="#"
+ class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm"
+ >Password</a
+ >
+
+ <a
+ href="#"
+ class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm"
+ >Notifications</a
+ >
+
+ <a
+ href="#"
+ class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm"
+ >Plan</a
+ >
+
+ <a
+ href="#"
+ class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm"
+ >Billing</a
+ >
+
+ <a
+ href="#"
+ class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm"
+ >Team Members</a
+ >
+ </nav>
+ </div>
+ </div>
+
+ <!-- Description list with inline editing -->
+ <div class="mt-10 divide-y divide-gray-200">
+ <div class="space-y-1">
+ <h3 class="text-lg font-medium leading-6 text-gray-900">Profile</h3>
+ <p class="max-w-2xl text-sm text-gray-500">
+ This information will be displayed publicly so be careful what you share.
+ </p>
+ </div>
+ <div class="mt-6">
+ <dl class="divide-y divide-gray-200">
+ <div class="py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:py-5">
+ <dt class="text-sm font-medium text-gray-500">Name</dt>
+ <dd class="mt-1 flex text-sm text-gray-900 sm:col-span-2 sm:mt-0">
+ <span class="flex-grow">Chelsea Hagon</span>
+ <span class="ml-4 flex-shrink-0">
+ <button
+ type="button"
+ class="rounded-md bg-white font-medium text-purple-600 hover:text-purple-500 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2"
+ >Update</button
+ >
+ </span>
+ </dd>
+ </div>
+ <div class="py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:py-5 sm:pt-5">
+ <dt class="text-sm font-medium text-gray-500">Photo</dt>
+ <dd class="mt-1 flex text-sm text-gray-900 sm:col-span-2 sm:mt-0">
+ <span class="flex-grow">
+ <img
+ class="h-8 w-8 rounded-full"
+ src="https://images.unsplash.com/photo-1550525811-e5869dd03032?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
+ alt=""
+ />
+ </span>
+ <span class="ml-4 flex flex-shrink-0 items-start space-x-4">
+ <button
+ type="button"
+ class="rounded-md bg-white font-medium text-purple-600 hover:text-purple-500 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2"
+ >Update</button
+ >
+ <span class="text-gray-300" aria-hidden="true">|</span>
+ <button
+ type="button"
+ class="rounded-md bg-white font-medium text-purple-600 hover:text-purple-500 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2"
+ >Remove</button
+ >
+ </span>
+ </dd>
+ </div>
+ <div class="py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:py-5 sm:pt-5">
+ <dt class="text-sm font-medium text-gray-500">Email</dt>
+ <dd class="mt-1 flex text-sm text-gray-900 sm:col-span-2 sm:mt-0">
+ <span class="flex-grow">chelsea.hagon@example.com</span>
+ <span class="ml-4 flex-shrink-0">
+ <button
+ type="button"
+ class="rounded-md bg-white font-medium text-purple-600 hover:text-purple-500 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2"
+ >Update</button
+ >
+ </span>
+ </dd>
+ </div>
+ <div class="py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:border-b sm:border-gray-200 sm:py-5">
+ <dt class="text-sm font-medium text-gray-500">Job title</dt>
+ <dd class="mt-1 flex text-sm text-gray-900 sm:col-span-2 sm:mt-0">
+ <span class="flex-grow">Human Resources Manager</span>
+ <span class="ml-4 flex-shrink-0">
+ <button
+ type="button"
+ class="rounded-md bg-white font-medium text-purple-600 hover:text-purple-500 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2"
+ >Update</button
+ >
+ </span>
+ </dd>
+ </div>
+ </dl>
+ </div>
+ </div>
+
+ <div class="mt-10 divide-y divide-gray-200">
+ <div class="space-y-1">
+ <h3 class="text-lg font-medium leading-6 text-gray-900">Account</h3>
+ <p class="max-w-2xl text-sm text-gray-500">Manage how information is displayed on your
+ account.</p>
+ </div>
+ <div class="mt-6">
+ <dl class="divide-y divide-gray-200">
+ <div class="py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:py-5">
+ <dt class="text-sm font-medium text-gray-500">Language</dt>
+ <dd class="mt-1 flex text-sm text-gray-900 sm:col-span-2 sm:mt-0">
+ <span class="flex-grow">English</span>
+ <span class="ml-4 flex-shrink-0">
+ <button
+ type="button"
+ class="rounded-md bg-white font-medium text-purple-600 hover:text-purple-500 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2"
+ >Update</button
+ >
+ </span>
+ </dd>
+ </div>
+ <div class="py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:py-5 sm:pt-5">
+ <dt class="text-sm font-medium text-gray-500">Date format</dt>
+ <dd class="mt-1 flex text-sm text-gray-900 sm:col-span-2 sm:mt-0">
+ <span class="flex-grow">DD-MM-YYYY</span>
+ <span class="ml-4 flex flex-shrink-0 items-start space-x-4">
+ <button
+ type="button"
+ class="rounded-md bg-white font-medium text-purple-600 hover:text-purple-500 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2"
+ >Update</button
+ >
+ <span class="text-gray-300" aria-hidden="true">|</span>
+ <button
+ type="button"
+ class="rounded-md bg-white font-medium text-purple-600 hover:text-purple-500 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2"
+ >Remove</button
+ >
+ </span>
+ </dd>
+ </div>
+ <div class="py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:py-5 sm:pt-5">
+ <dt class="text-sm font-medium text-gray-500" id="timezone-option-label">Automatic
+ timezone
+ </dt>
+ <Switch/>
+ </div>
+ </dl>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
diff --git a/code/app/src/routes/(main)/(app)/tickets/+page.svelte b/code/app/src/routes/(main)/(app)/tickets/+page.svelte
new file mode 100644
index 0000000..2a4792b
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/tickets/+page.svelte
@@ -0,0 +1,4 @@
+<script lang="ts">
+</script>
+
+<h1>Tickets</h1>
diff --git a/code/app/src/routes/(main)/(app)/todo/+page.svelte b/code/app/src/routes/(main)/(app)/todo/+page.svelte
new file mode 100644
index 0000000..e29f263
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/todo/+page.svelte
@@ -0,0 +1,4 @@
+<script lang="ts">
+</script>
+
+<h1>Todo</h1>
diff --git a/code/app/src/routes/(main)/(app)/wiki/+page.svelte b/code/app/src/routes/(main)/(app)/wiki/+page.svelte
new file mode 100644
index 0000000..1762d43
--- /dev/null
+++ b/code/app/src/routes/(main)/(app)/wiki/+page.svelte
@@ -0,0 +1,4 @@
+<script lang="ts">
+</script>
+
+<h1>Wiki</h1>
diff --git a/code/app/src/routes/(main)/(public)/+layout.svelte b/code/app/src/routes/(main)/(public)/+layout.svelte
new file mode 100644
index 0000000..6da653c
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/+layout.svelte
@@ -0,0 +1,18 @@
+<script>
+ import { LocaleSwitcher } from "$components";
+ import LL from "$i18n/i18n-svelte";
+</script>
+
+<LocaleSwitcher tabindex={-1} />
+<slot />
+<footer class="grid sm:gap-5 grid-flow-row sm:justify-center px-2 sm:grid-flow-col">
+ <a href="https://greatoffice.life/privacy" class="link">
+ {$LL.privacyPolicy()}
+ </a>
+ <a href="https://greatoffice.life/terms" class="link">
+ {$LL.tos()}
+ </a>
+ <a href="https://greatoffice.life/docs" class="link">
+ {$LL.documentation()}
+ </a>
+</footer>
diff --git a/code/app/src/routes/(main)/(public)/portal/+page.svelte b/code/app/src/routes/(main)/(public)/portal/+page.svelte
new file mode 100644
index 0000000..b363e4b
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/portal/+page.svelte
@@ -0,0 +1,26 @@
+<script lang="ts">
+ import { onMount } from "svelte";
+ import type { PageData } from "./$types";
+ import type { PortalMessage } from "$configuration";
+ import { goto } from "$app/navigation";
+ import { sgs } from "$utilities/global-state";
+
+ export let data: PageData;
+
+ onMount(async () => {
+ switch (data.message as PortalMessage) {
+ case "emailValidated": {
+ sgs("showEmailValidatedAlertWhenLoggedIn", true);
+ await goto("/home");
+ break;
+ }
+ default: {
+ await goto("/home");
+ }
+ }
+ });
+</script>
+
+<div class="p-3">
+ <h1>Warping...</h1>
+</div>
diff --git a/code/app/src/routes/(main)/(public)/portal/+page.ts b/code/app/src/routes/(main)/(public)/portal/+page.ts
new file mode 100644
index 0000000..72338cb
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/portal/+page.ts
@@ -0,0 +1,9 @@
+import type { PortalMessage } from '$configuration';
+import { redirect } from '@sveltejs/kit';
+import type { PageLoad } from './$types';
+
+export const load: PageLoad = async ({ url }) => {
+ const message = url.searchParams.get("msg") as PortalMessage;
+ if (!message) throw redirect(302, "/");
+ return { message };
+}; \ No newline at end of file
diff --git a/code/app/src/routes/(main)/(public)/reset-password/+page.svelte b/code/app/src/routes/(main)/(public)/reset-password/+page.svelte
new file mode 100644
index 0000000..a45ccdd
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/reset-password/+page.svelte
@@ -0,0 +1,81 @@
+<script lang="ts">
+ import { Alert, Input, Button } from "$components";
+ import LL from "$i18n/i18n-svelte";
+ import { FormError } from "$models/internal/FormError";
+ import { PasswordResetService } from "$services/password-reset-service";
+
+ const formData = {
+ email: {
+ value: "",
+ errors: [],
+ },
+ };
+
+ const formError = new FormError();
+ const passwordResetService = PasswordResetService.resolve();
+
+ let loading = false;
+ let showSuccessAlert = false;
+ let showErrorAlert = false;
+
+ async function submit_form_async() {
+ formError.set();
+ showSuccessAlert = false;
+ showErrorAlert = false;
+ loading = true;
+ const response = await passwordResetService.create_request_async(formData.email.value);
+ loading = false;
+ if (response.isCreated) {
+ showSuccessAlert = true;
+ } else if (response.knownProblem) {
+ formError.set_from_known_problem(response.knownProblem);
+ for (const error of Object.entries(response.knownProblem.errors)) {
+ if (error[0] === "email") {
+ let errors = [];
+ error[1].forEach((e) => errors.push(e));
+ formData.email.errors = errors;
+ }
+ }
+ } else {
+ formError.set($LL.unexpectedError(), $LL.tryAgainSoon());
+ }
+ showErrorAlert = formError.has_error() && !showSuccessAlert;
+ }
+</script>
+
+<div class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8">
+ <div class="sm:mx-auto sm:w-full p-2 sm:p-0 sm:max-w-md">
+ <h2 class="mt-6 text-3xl tracking-tight font-bold text-gray-900">
+ {$LL.resetPasswordPage.requestAPasswordReset()}
+ </h2>
+ <p class="mt-2 text-sm text-gray-600">
+ {$LL.or().toLowerCase()}
+ <a href="/sign-in" class="link">
+ {$LL.signIntoYourAccount().toLowerCase()}
+ </a>
+ </p>
+ </div>
+
+ <div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
+ <div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
+ <form class="space-y-6" on:submit|preventDefault={submit_form_async}>
+ {#if showErrorAlert}
+ <Alert title={formError.title} message={formError.subtitle} type="error" />
+ {:else if showSuccessAlert}
+ <Alert type="success" title={$LL.success()} message={$LL.resetPasswordPage.requestSentMessage()} />
+ {/if}
+ <Input
+ id="email"
+ name="email"
+ type="email"
+ autocomplete="email"
+ errors={formData.email.errors}
+ bind:value={formData.email.value}
+ required
+ label={$LL.emailAddress()}
+ />
+ <Button text={$LL.submit()} type="submit" {loading} fullWidth />
+ </form>
+ </div>
+ </div>
+</div>
diff --git a/code/app/src/routes/(main)/(public)/reset-password/+page.ts b/code/app/src/routes/(main)/(public)/reset-password/+page.ts
new file mode 100644
index 0000000..c0859e0
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/reset-password/+page.ts
@@ -0,0 +1,11 @@
+import LL from '$i18n/i18n-svelte';
+import { get } from 'svelte/store';
+import type { PageLoad } from './$types';
+
+const l = get(LL);
+
+export const load: PageLoad = async () => {
+ return {
+ title: l.resetPasswordPage.title(),
+ };
+}; \ No newline at end of file
diff --git a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.server.ts b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.server.ts
new file mode 100644
index 0000000..22fa29d
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.server.ts
@@ -0,0 +1,11 @@
+import { is_guid } from "$utilities/validators";
+import { redirect } from "@sveltejs/kit";
+import type { PageServerLoad } from "./$types";
+
+export const load: PageServerLoad = async ({ params }) => {
+ const resetRequestId = params.id ?? "";
+ if (!is_guid(resetRequestId)) throw redirect(302, "/reset-password");
+ return {
+ resetRequestId,
+ };
+}; \ No newline at end of file
diff --git a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte
new file mode 100644
index 0000000..27a1af5
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte
@@ -0,0 +1,82 @@
+<script lang="ts">
+ import { onMount } from "svelte";
+ import LL from "$i18n/i18n-svelte";
+ import { Alert, Input, Button } from "$components";
+ import type { PageServerData } from "./$types";
+ import { goto } from "$app/navigation";
+ import { SignInPageMessage, signInPageMessageQueryKey } from "$routes/(main)/(public)/sign-in";
+ import { PasswordResetService } from "$services/password-reset-service";
+
+ export let data: PageServerData;
+ const passwordResetService = PasswordResetService.resolve();
+
+ const formData = {
+ newPassword: {
+ value: "",
+ errors: [],
+ },
+ };
+
+ let finishedPreliminaryLoading = false;
+ let loading = false;
+ let canSubmit = true;
+ let requestIsInvalid = false;
+
+ async function submitFormAsync() {
+ if (!canSubmit) return;
+ loading = true;
+ const request = await passwordResetService.fulfill_request_async(data.resetRequestId, formData.newPassword.value);
+ if (request.isFulfilled) {
+ goto("/sign-in?" + signInPageMessageQueryKey + "=" + SignInPageMessage.AFTER_PASSWORD_RESET);
+ } else if (request.knownProblem) {
+ }
+ loading = false;
+ }
+
+ onMount(async () => {
+ const response = await passwordResetService.request_is_valid_async(data.resetRequestId);
+ requestIsInvalid = !response.isValid;
+ finishedPreliminaryLoading = true;
+ });
+</script>
+
+<div class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8">
+ {#if finishedPreliminaryLoading}
+ <div class="sm:mx-auto sm:w-full p-2 sm:p-0 sm:max-w-md">
+ <h2 class="mt-6 text-3xl tracking-tight font-bold text-gray-900">
+ {$LL.resetPasswordPage.setANewPassword()}
+ </h2>
+ <p class="mt-2 text-sm text-gray-600">
+ {$LL.or().toLowerCase()}
+ <a href="/sign-in" class="link">
+ {$LL.signIntoYourAccount().toLowerCase()}
+ </a>
+ </p>
+ </div>
+
+ <div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
+ <div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
+ <form class="space-y-6" on:submit|preventDefault={submitFormAsync}>
+ {#if requestIsInvalid}
+ <Alert
+ title={$LL.resetPasswordPage.invalidRequestTitle()}
+ message={$LL.resetPasswordPage.invalidRequestMessage()}
+ />
+ {/if}
+ <Input
+ id="password"
+ name="password"
+ type="password"
+ autocomplete="new-password"
+ required
+ bind:value={formData.newPassword.value}
+ label={$LL.resetPasswordPage.newPassword()}
+ />
+ <Button text={$LL.submit()} type="submit" {loading} fullWidth />
+ </form>
+ </div>
+ </div>
+ {:else}
+ <p>Checking your request...</p>
+ {/if}
+</div>
diff --git a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.ts b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.ts
new file mode 100644
index 0000000..3252b7a
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.ts
@@ -0,0 +1,11 @@
+import LL from '$i18n/i18n-svelte';
+import { get } from 'svelte/store';
+import type { PageLoad } from './$types';
+
+const l = get(LL);
+
+export const load: PageLoad = async () => {
+ return {
+ title: l.resetPasswordPage.fulfillTitle(),
+ };
+}; \ No newline at end of file
diff --git a/code/app/src/routes/(main)/(public)/sign-in/+page.svelte b/code/app/src/routes/(main)/(public)/sign-in/+page.svelte
new file mode 100644
index 0000000..66d4575
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/sign-in/+page.svelte
@@ -0,0 +1,155 @@
+<script lang="ts">
+ import { goto } from "$app/navigation";
+ import { Button, Checkbox, Input, Alert } from "$components";
+ import LL from "$i18n/i18n-svelte";
+ import pwKey from "$actions/pwKey";
+ import { onMount } from "svelte";
+ import { signInPageMessageQueryKey, signInPageTestKeys, type SignInPageMessage } from ".";
+ import { AccountService } from "$services/account-service";
+ import type { LoginPayload } from "$services/abstractions/IAccountService";
+ import { FormError } from "$models/internal/FormError";
+ import type { IForm } from "$models/internal/IForm";
+
+ let messageType: SignInPageMessage | undefined = undefined;
+
+ const accountService = AccountService.resolve();
+ const form = {
+ fields: {
+ username: {
+ value: "",
+ errors: [],
+ },
+ password: {
+ value: "",
+ errors: [],
+ },
+ persist: {
+ value: false,
+ errors: [],
+ },
+ },
+ error: new FormError(),
+ isLoading: false,
+ showError: false,
+ get_payload(): LoginPayload {
+ return {
+ password: form.fields.password.value,
+ username: form.fields.username.value,
+ persist: !form.fields.persist.value,
+ };
+ },
+ async submit_async() {
+ console.log("sadf");
+ form.error.set();
+ form.showError = form.error.has_error();
+ form.isLoading = true;
+ const loginResponse = await accountService.login_async(form.get_payload());
+ if (loginResponse.isLoggedIn) {
+ await goto("/home");
+ } else if (loginResponse.knownProblem) {
+ form.error.set_from_known_problem(loginResponse.knownProblem);
+ } else {
+ form.error.set($LL.unexpectedError(), $LL.tryAgainSoon());
+ }
+ form.isLoading = false;
+ form.showError = form.error.has_error();
+ },
+ } as IForm;
+
+ onMount(() => {
+ const queryParams = new URLSearchParams(window.location.search);
+ if (queryParams.get(signInPageMessageQueryKey)) {
+ messageType = queryParams.get(signInPageMessageQueryKey) as SignInPageMessage;
+ queryParams.delete(signInPageMessageQueryKey);
+ window.history.replaceState(null, "", window.location.origin + window.location.pathname);
+ }
+ });
+</script>
+
+<div class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8">
+ {#if messageType}
+ <div class="sm:max-w-md sm:mx-auto sm:w-full">
+ {#if messageType === "after-password-reset"}
+ <Alert
+ title={$LL.signInPage.yourNewPasswordIsApplied()}
+ _pwKey={signInPageTestKeys.afterPasswordResetAlert}
+ message={$LL.signInPage.signInBelow()}
+ closeable
+ />
+ {:else if messageType === "user-disabled"}
+ <Alert
+ title={$LL.signInPage.yourAccountIsDisabled()}
+ _pwKey={signInPageTestKeys.userDisabledAlert}
+ message={$LL.signInPage.contactYourAdminIfDisabled()}
+ closeable
+ />
+ {:else if messageType === "user-inactivity"}
+ <Alert
+ title={$LL.signInPage.youHaveReachedInactivityLimit()}
+ _pwKey={signInPageTestKeys.userInactivityAlert}
+ message={$LL.signInPage.feelFreeToSignInAgain()}
+ closeable
+ />
+ {/if}
+ </div>
+ {/if}
+ <div class="sm:mx-auto sm:w-full p-2 sm:p-0 sm:max-w-md">
+ <h2 class="mt-6 text-3xl tracking-tight font-bold text-gray-900">
+ {$LL.signInPage.signIn()}
+ </h2>
+ <p class="mt-2 text-sm text-gray-600">
+ {$LL.or().toLowerCase()}
+ <a href="/sign-up" use:pwKey={signInPageTestKeys.signUpAnchor} class="link">
+ {$LL.createANewAccount().toLowerCase()}
+ </a>
+ </p>
+ </div>
+ <div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
+ <div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
+ {#if form.showError}
+ <Alert title={form.error.title} message={form.error.subtitle} type="error" _pwKey={signInPageTestKeys.formErrorAlert} />
+ {/if}
+ <form class="space-y-6 mt-2" use:pwKey={signInPageTestKeys.signInForm} on:submit|preventDefault={() => form.submit_async()}>
+ <Input
+ id="username"
+ _pwKey={signInPageTestKeys.usernameInput}
+ name="username"
+ type="email"
+ label={$LL.emailAddress()}
+ required
+ errors={form.fields.username.errors}
+ bind:value={form.fields.username.value}
+ />
+
+ <Input
+ id="password"
+ name="password"
+ type="password"
+ label={$LL.password()}
+ _pwKey={signInPageTestKeys.passwordInput}
+ autocomplete="current-password"
+ required
+ errors={form.fields.password.errors}
+ bind:value={form.fields.password.value}
+ />
+
+ <div class="flex items-center justify-between">
+ <Checkbox
+ id="remember-me"
+ _pwKey={signInPageTestKeys.rememberMeCheckbox}
+ name="remember-me"
+ bind:checked={form.fields.persist.value}
+ label={$LL.signInPage.notMyComputer()}
+ />
+ <div class="text-sm">
+ <a href="/reset-password" class="link" use:pwKey={signInPageTestKeys.resetPasswordAnchor}>
+ {$LL.signInPage.resetPassword()}
+ </a>
+ </div>
+ </div>
+
+ <Button text={$LL.submit()} fullWidth type="submit" loading={form.isLoading} />
+ </form>
+ </div>
+ </div>
+</div>
diff --git a/code/app/src/routes/(main)/(public)/sign-in/+page.ts b/code/app/src/routes/(main)/(public)/sign-in/+page.ts
new file mode 100644
index 0000000..bebc459
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/sign-in/+page.ts
@@ -0,0 +1,11 @@
+import LL from '$i18n/i18n-svelte';
+import { get } from 'svelte/store';
+import type { PageLoad } from './$types';
+
+const l = get(LL);
+
+export const load: PageLoad = async () => {
+ return {
+ title: l.signInPage.title(),
+ };
+}; \ No newline at end of file
diff --git a/code/app/src/routes/(main)/(public)/sign-in/index.spec.js b/code/app/src/routes/(main)/(public)/sign-in/index.spec.js
new file mode 100644
index 0000000..9d0122d
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/sign-in/index.spec.js
@@ -0,0 +1,12 @@
+import { test, expect } from "@playwright/test";
+import { signInPageTestKeys } from "./index.js";
+import { get_test_context } from "$configuration";
+import { get_pw_key_selector } from "$utilities/testing-helpers";
+
+const context = get_test_context();
+
+test("form loads", async ({ page }) => {
+ page.goto("/sign-in");
+ const form = page.locator(get_pw_key_selector(signInPageTestKeys.signInForm));
+ expect(form.isVisible()).toBeTruthy();
+});
diff --git a/code/app/src/routes/(main)/(public)/sign-in/index.ts b/code/app/src/routes/(main)/(public)/sign-in/index.ts
new file mode 100644
index 0000000..c1a1929
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/sign-in/index.ts
@@ -0,0 +1,20 @@
+export enum SignInPageMessage {
+ AFTER_PASSWORD_RESET = "after-password-reset",
+ USER_INACTIVITY = "user-inactivity",
+ USER_DISABLED = "user-disabled",
+ LOGGED_OUT = "logged-out"
+}
+
+export const signInPageMessageQueryKey = "m";
+export const signInPageTestKeys = {
+ passwordInput: "password-input",
+ usernameInput: "username-input",
+ rememberMeCheckbox: "remember-me-checkbox",
+ signInForm: "sign-in-form",
+ userInactivityAlert: SignInPageMessage.USER_INACTIVITY + "-alert",
+ userDisabledAlert: SignInPageMessage.USER_DISABLED + "-alert",
+ afterPasswordResetAlert: SignInPageMessage.AFTER_PASSWORD_RESET + "-alert",
+ formErrorAlert: "form-error-alert",
+ resetPasswordAnchor: "reset-password-anchor",
+ signUpAnchor: "sign-up-anchor",
+}; \ No newline at end of file
diff --git a/code/app/src/routes/(main)/(public)/sign-up/+page.svelte b/code/app/src/routes/(main)/(public)/sign-up/+page.svelte
new file mode 100644
index 0000000..470ac5d
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/sign-up/+page.svelte
@@ -0,0 +1,106 @@
+<script lang="ts">
+ import { goto } from "$app/navigation";
+ import { Button, Input, Alert } from "$components";
+ import LL from "$i18n/i18n-svelte";
+ import { FormError } from "$models/internal/FormError";
+ import type { CreateAccountPayload } from "$services/abstractions/IAccountService";
+ import { AccountService } from "$services/account-service";
+
+ const formData = {
+ username: {
+ value: "",
+ errors: [],
+ },
+ password: {
+ value: "",
+ errors: [],
+ },
+ as_payload(): CreateAccountPayload {
+ return {
+ username: formData.username.value,
+ password: formData.password.value,
+ };
+ },
+ };
+
+ const formError = new FormError();
+ const accountService = new AccountService();
+
+ let loading = false;
+ let showErrorAlert = false;
+
+ async function submit_form_async() {
+ loading = true;
+ showErrorAlert = false;
+ formError.set();
+ formData.username.errors = [];
+ formData.password.errors = [];
+ const response = await accountService.create_account_async(formData.as_payload());
+ if (response.isCreated) {
+ await goto("/home");
+ } else if (response.knownProblem) {
+ formError.set_from_known_problem(response.knownProblem);
+ for (const error of Object.entries(response.knownProblem.errors)) {
+ if (error[0] === "username") {
+ const errors = [];
+ error[1].forEach((e) => errors.push(e));
+ formData.username.errors = errors;
+ }
+ if (error[0] === "password") {
+ const errors = [];
+ error[1].forEach((e) => errors.push(e));
+ formData.password.errors = errors;
+ }
+ }
+ } else {
+ formError.set($LL.unexpectedError(), $LL.tryAgainSoon());
+ }
+ loading = false;
+ showErrorAlert = formError.has_error();
+ }
+</script>
+
+<div class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8">
+ <div class="sm:mx-auto sm:w-full p-2 sm:p-0 sm:max-w-md">
+ <h2 class="mt-6 text-3xl tracking-tight font-bold text-gray-900">
+ {$LL.signUpPage.createYourNewAccount()}
+ </h2>
+ <p class="mt-2 text-sm text-gray-600">
+ {$LL.or().toLowerCase()}
+ <a href="/sign-in" class="link">
+ {$LL.signIntoYourAccount().toLowerCase()}
+ </a>
+ </p>
+ </div>
+
+ <div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
+ <div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
+ {#if showErrorAlert}
+ <Alert title={formError.title} message={formError.subtitle} type="error" class="mb-2" />
+ {/if}
+ <form class="space-y-6" on:submit|preventDefault={submit_form_async}>
+ <Input
+ label={$LL.emailAddress()}
+ id="email"
+ name="email"
+ autocomplete="email"
+ required
+ type="email"
+ bind:value={formData.username.value}
+ errors={formData.username.errors}
+ />
+
+ <Input
+ label={$LL.password()}
+ id="password"
+ name="password"
+ required
+ type="password"
+ bind:value={formData.password.value}
+ errors={formData.password.errors}
+ />
+ <Button type="submit" text={$LL.submit()} {loading} fullWidth />
+ </form>
+ </div>
+ </div>
+</div>
diff --git a/code/app/src/routes/(main)/(public)/sign-up/+page.ts b/code/app/src/routes/(main)/(public)/sign-up/+page.ts
new file mode 100644
index 0000000..8c86f55
--- /dev/null
+++ b/code/app/src/routes/(main)/(public)/sign-up/+page.ts
@@ -0,0 +1,11 @@
+import LL from '$i18n/i18n-svelte';
+import { get } from 'svelte/store';
+import type { PageLoad } from './$types';
+
+const l = get(LL);
+
+export const load: PageLoad = async () => {
+ return {
+ title: l.signUpPage.title(),
+ };
+}; \ No newline at end of file
diff --git a/code/app/src/routes/(main)/+layout.server.ts b/code/app/src/routes/(main)/+layout.server.ts
new file mode 100644
index 0000000..25043aa
--- /dev/null
+++ b/code/app/src/routes/(main)/+layout.server.ts
@@ -0,0 +1,45 @@
+import { api_base, CookieNames } from "$configuration";
+import { cached_result_async, CacheKeys } from "$utilities/cache";
+import { log_debug, log_error } from "$utilities/logger";
+import { get_md5_hash } from "$utilities/crypto-helpers";
+import { error, redirect } from "@sveltejs/kit";
+import type { LayoutServerLoad } from "./$types";
+
+export const load: LayoutServerLoad = async ({ route, cookies, locals, fetch }) => {
+ const isBaseRoute = route.id === "/(main)";
+ const isPortalRoute = route.id === "/(main)/(public)/portal";
+ const isPublicRoute = (isBaseRoute || (route.id?.startsWith("/(main)/(public)") ?? false)) ?? true;
+ const sessionCookieValue = cookies.get(CookieNames.session);
+ let sessionIsValid = false;
+ if ((sessionCookieValue?.length > 0 ?? false)) {
+ const sessionHash = get_md5_hash(sessionCookieValue);
+ sessionIsValid = (await cached_result_async<Response>(sessionHash + "_" + CacheKeys.isAuthenticated, 120, () => fetch(api_base("_/is-authenticated"), {
+ headers: {
+ Cookie: CookieNames.session + "=" + sessionCookieValue,
+ },
+ }).catch((e) => {
+ log_error(e);
+ throw error(503, {
+ message: "We are experiencing a service disruption! Have patience while we resolve the issue.",
+ });
+ }))).ok;
+ }
+
+ log_debug("Base Layout loaded", {
+ sessionIsValid,
+ isPublicRoute,
+ isBaseRoute,
+ isPortalRoute,
+ routeId: route.id,
+ });
+
+ if (sessionIsValid && isPublicRoute && !isPortalRoute) {
+ throw redirect(302, "/home");
+ } else if (!isPortalRoute && (isBaseRoute || !sessionIsValid && !isPublicRoute)) {
+ throw redirect(302, "/sign-in");
+ }
+
+ return {
+ locale: locals.locale,
+ };
+};
diff --git a/code/app/src/routes/(main)/+layout.svelte b/code/app/src/routes/(main)/+layout.svelte
new file mode 100644
index 0000000..7662d6a
--- /dev/null
+++ b/code/app/src/routes/(main)/+layout.svelte
@@ -0,0 +1,31 @@
+<script lang="ts">
+ import "../../app.pcss";
+ import { setLocale } from "$i18n/i18n-svelte";
+ import { ExclamationTriangleIcon } from "$components/icons";
+ import { page } from "$app/stores";
+ import type { LayoutData } from "./$types";
+
+ let online = true;
+ export let data: LayoutData;
+ setLocale(data.locale);
+</script>
+
+<svelte:window bind:online />
+<svelte:head>
+ <title>{$page.data.title ? $page.data.title + " - Greatoffice" : "Greatoffice"}</title>
+</svelte:head>
+
+{#if !online}
+ <div class="bg-yellow-50 relative z-50 p-4">
+ <div class="flex">
+ <div class="flex-shrink-0">
+ <ExclamationTriangleIcon class="bg-yellow-50 text-yellow-500" />
+ </div>
+ <div class="ml-3">
+ <p class="text-sm text-yellow-700">You seem to be offline, please check your internet connection.</p>
+ </div>
+ </div>
+ </div>
+{/if}
+
+<slot />
diff --git a/code/app/src/routes/(main)/+layout.ts b/code/app/src/routes/(main)/+layout.ts
new file mode 100644
index 0000000..3893260
--- /dev/null
+++ b/code/app/src/routes/(main)/+layout.ts
@@ -0,0 +1,10 @@
+import type { LayoutLoad } from "./$types";
+import type { Locales } from "$i18n/i18n-types";
+import { loadLocaleAsync } from "$i18n/i18n-util.async";
+import { setLocale } from "$i18n/i18n-svelte";
+
+export const load: LayoutLoad<{ locale: Locales }> = async ({ data: { locale } }) => {
+ await loadLocaleAsync(locale);
+ setLocale(locale);
+ return { locale };
+}; \ No newline at end of file
diff --git a/code/app/src/routes/(main)/+page.svelte b/code/app/src/routes/(main)/+page.svelte
new file mode 100644
index 0000000..e507a19
--- /dev/null
+++ b/code/app/src/routes/(main)/+page.svelte
@@ -0,0 +1 @@
+<p class="text-bold p-1">Hold on...</p>
diff --git a/code/app/src/routes/book/+layout.svelte b/code/app/src/routes/book/+layout.svelte
new file mode 100644
index 0000000..385d0a6
--- /dev/null
+++ b/code/app/src/routes/book/+layout.svelte
@@ -0,0 +1,46 @@
+<script>
+ import { page } from "$app/stores";
+ import "../../app.pcss";
+</script>
+
+<div id="wrapper">
+ <nav>
+ <a href="/book/alerts" class="link" class:active={$page.url.pathname.startsWith("/book/alerts")}>Alerts</a>
+ <a href="/book/buttons" class="link" class:active={$page.url.pathname.startsWith("/book/buttons")}>Buttons</a>
+ <a href="/book/toggles" class="link" class:active={$page.url.pathname.startsWith("/book/toggles")}>Toggles</a>
+ <a href="/book/inputs" class="link" class:active={$page.url.pathname.startsWith("/book/inputs")}>Inputs</a>
+ <a href="/book/badges" class="link" class:active={$page.url.pathname.startsWith("/book/badges")}>Badges</a>
+ <a href="/book/notifications" class="link" class:active={$page.url.pathname.startsWith("/book/notifications")}>Notifications</a>
+ </nav>
+ <main>
+ <slot />
+ </main>
+</div>
+
+<style global lang="postcss">
+ #wrapper {
+ display: flex;
+ flex-direction: row;
+ }
+ nav {
+ min-width: 120px;
+ padding: 10px;
+ display: flex;
+ flex-direction: column;
+ position: sticky;
+ position: -webkit-sticky;
+ top: 0;
+ height: fit-content;
+ }
+ main {
+ width: 100%;
+ padding: 10px;
+ }
+ section {
+ margin-bottom: 25px;
+
+ h2 {
+ margin-bottom: 5px;
+ }
+ }
+</style>
diff --git a/code/app/src/routes/book/+layout.ts b/code/app/src/routes/book/+layout.ts
new file mode 100644
index 0000000..d297dfd
--- /dev/null
+++ b/code/app/src/routes/book/+layout.ts
@@ -0,0 +1,3 @@
+export const ssr = import.meta.env.DEV;
+export const csr = import.meta.env.DEV;
+export const prerender = import.meta.env.DEV; \ No newline at end of file
diff --git a/code/app/src/routes/book/+page.svelte b/code/app/src/routes/book/+page.svelte
new file mode 100644
index 0000000..635b3c2
--- /dev/null
+++ b/code/app/src/routes/book/+page.svelte
@@ -0,0 +1 @@
+<p>A showcase of greatoffices components</p>
diff --git a/code/app/src/routes/book/alerts/+page.svelte b/code/app/src/routes/book/alerts/+page.svelte
new file mode 100644
index 0000000..ed4c92b
--- /dev/null
+++ b/code/app/src/routes/book/alerts/+page.svelte
@@ -0,0 +1,70 @@
+<script>
+ import Alert from "$components/alert.svelte";
+</script>
+
+<section>
+ <h2>Info</h2>
+ <Alert type="info" message="This is message" title="This is title"/>
+</section>
+<section>
+ <h2>Warning</h2>
+ <Alert type="warning" message="This is message" title="This is title"/>
+</section>
+<section>
+ <h2>Error</h2>
+ <Alert type="error" message="This is message" title="This is title"/>
+</section>
+<section>
+ <h2>Success</h2>
+ <Alert type="success" message="This is message" title="This is title"/>
+</section>
+<section>
+ <h2>Actions</h2>
+ <Alert
+ type="info"
+ message="This is message"
+ title="This is title"
+ closeable
+ actions={[
+ {
+ id: "confirm",
+ text: "Yes!",
+ },
+ {
+ id: "cancel",
+ text: "No!",
+ color: "red",
+ },
+ ]}
+ />
+</section>
+<section>
+ <h2>Right link</h2>
+ <Alert
+ on:rightLinkCliked={() => alert("Right link clicked")}
+ rightLinkText="Link or action"
+ title="Go here"
+ message="Hehe"
+ type="error"
+ />
+</section>
+<section>
+ <h2>List</h2>
+ <Alert
+ title="This is title"
+ listItems={["Message 1", "Message 2"]}
+ type="error"
+ message="This is bad dude"
+ closeable
+ closeableCooldown="60"
+ id="alert-1"
+ on:actrepeat={() => {
+ alert("Repeat requested");
+ }}
+ actions={[{ id: "repeat", text: "Try again" }]}
+ />
+</section>
+<section>
+ <h2>Closeable</h2>
+ <Alert message="This is message" closeable type="info"/>
+</section>
diff --git a/code/app/src/routes/book/badges/+page.svelte b/code/app/src/routes/book/badges/+page.svelte
new file mode 100644
index 0000000..50ae61e
--- /dev/null
+++ b/code/app/src/routes/book/badges/+page.svelte
@@ -0,0 +1,19 @@
+<script lang="ts">
+ import Badge from "$components/badge.svelte";
+</script>
+
+<section>
+ <h2>Variants</h2>
+ <Badge text="default"/>
+ <Badge type="blue" text="blue"/>
+ <Badge type="green" text="green"/>
+ <Badge type="red" text="red"/>
+ <Badge type="tame" text="tame"/>
+ <Badge type="yellow" text="yellow"/>
+ <Badge size="large" text="large"/>
+ <Badge text="with dot" withDot type="blue"/>
+ <Badge text="removable" removable id="badge-1" on:remove={(e) => alert("removed " + e.detail.id)}/>
+ <Badge text="with dot" size="large" withDot type="blue"/>
+ <Badge text="removable" removable size="large" id="badge-2" uppercase
+ on:remove={(e) => alert("removed " + e.detail.id)}/>
+</section>
diff --git a/code/app/src/routes/book/buttons/+page.svelte b/code/app/src/routes/book/buttons/+page.svelte
new file mode 100644
index 0000000..6668a64
--- /dev/null
+++ b/code/app/src/routes/book/buttons/+page.svelte
@@ -0,0 +1,23 @@
+<script>
+ import Button from "$components/button.svelte";
+</script>
+
+<section>
+ <h2>Primary</h2>
+ <Button kind="primary" text="Small" size="sm"/>
+ <Button kind="primary" text="Medium/Default"/>
+ <Button kind="primary" text="Large" size="lg"/>
+ <Button kind="primary" text="Extra large" size="xl"/>
+</section>
+<section>
+ <h2>Secondary</h2>
+ <Button kind="secondary" text="Click me!"/>
+</section>
+<section>
+ <h2>White</h2>
+ <Button kind="white" text="Click me!"/>
+</section>
+<section>
+ <h2>Loading</h2>
+ <Button kind="primary" loading={true} text="Wait"/>
+</section>
diff --git a/code/app/src/routes/book/inputs/+page.svelte b/code/app/src/routes/book/inputs/+page.svelte
new file mode 100644
index 0000000..433607b
--- /dev/null
+++ b/code/app/src/routes/book/inputs/+page.svelte
@@ -0,0 +1,75 @@
+<script lang="ts">
+ import {TextArea, Input, Combobox} from "$components";
+ import {DatabaseIcon} from "$components/icons";
+
+ let value;
+ let i = 0;
+ let options = [];
+ let tempOptions = [];
+ while (i < 101) {
+ tempOptions.push({
+ id: crypto.randomUUID(),
+ name: "Option " + i,
+ });
+ options = tempOptions;
+ i++;
+ }
+
+ async function add({name}) {
+ const copy = options;
+ copy.push({
+ id: crypto.randomUUID(),
+ name: name,
+ });
+ options = copy;
+ }
+</script>
+
+<section>
+ <h2>Combobox</h2>
+ <Combobox {options} label="Wiii" multiple createable on_create_async={add}/>
+</section>
+
+<section>
+ <h2>Default</h2>
+ <Input label="Input me" placeholder="Hello" bind:value/>
+</section>
+
+<section>
+ <h2>With icon</h2>
+ <Input label="Input me" placeholder="Hello" icon={DatabaseIcon} bind:value/>
+</section>
+
+<section>
+ <h2>With corner hint</h2>
+ <Input label="Input me ->" placeholder="Hello" cornerHint="Hint hint" bind:value/>
+</section>
+
+<section>
+ <h2>Disabled</h2>
+ <Input label="No" placeholder="Sorry" disabled bind:value/>
+</section>
+
+<section>
+ <h2>Errored</h2>
+ <Input label="No" placeholder="Sorry" errorText="That's not right" bind:value icon={DatabaseIcon}/>
+</section>
+
+<section>
+ <h2>Many errors</h2>
+ <Input label="No" placeholder="Sorry" errors={["That's not right", "Call help!", "Get it together"]} bind:value
+ icon={DatabaseIcon}/>
+</section>
+
+<section>
+ <h2>Help</h2>
+ <Input label="Go ahead" placeholder="Write here" helpText="Write above" bind:value/>
+</section>
+<section>
+ <h2>Addon</h2>
+ <Input label="Go ahead" placeholder="Write here" bind:value helpText="Write above" addon="To the right"/>
+</section>
+<section>
+ <h2>Textarea</h2>
+ <TextArea bind:value label="Hi"/>
+</section>
diff --git a/code/app/src/routes/book/notifications/+page.svelte b/code/app/src/routes/book/notifications/+page.svelte
new file mode 100644
index 0000000..1a6144d
--- /dev/null
+++ b/code/app/src/routes/book/notifications/+page.svelte
@@ -0,0 +1,50 @@
+<script lang="ts">
+ import { Notification } from "$components";
+ import type { NotificationType } from "$components/notification.svelte";
+
+ let type = "info" as NotificationType;
+ let nonClosable = false;
+ let title = "Title";
+ let subtitle = "Subtitle";
+ let hideAfterSeconds = -1;
+ let timeout;
+
+ function open(newtype: NotificationType) {
+ console.log(newtype);
+ type = newtype;
+ }
+</script>
+
+<section style="display: flex;flex-direction: column; max-width:200px;gap:5px">
+ <h2>Type:</h2>
+ <select
+ on:change={(e) => {
+ //@ts-ignore
+ open(e.target.selectedOptions[0].value);
+ }}
+ >
+ <option value="info">info</option>
+ <option value="warning">warning</option>
+ <option value="error">error</option>
+ <option value="success">success</option>
+ <option value="subtle">subtle</option>
+ </select>
+ <label for="nonClosable">
+ <input type="checkbox" id="nonClosable" bind:checked={nonClosable} />
+ nonClosable
+ </label>
+ <input type="text" bind:value={title} />
+ <input type="text" bind:value={subtitle} />
+ <input type="number" bind:value={timeout} placeholder="hideAfterSeconds" />
+ <small class="text-sm justify-end">
+ <span class="link" on:click={() => (hideAfterSeconds = timeout ?? -1)}>Apply</span>
+ <span
+ class="link"
+ on:click={() => {
+ hideAfterSeconds = -1;
+ timeout = 0;
+ }}>Reset</span
+ >
+ </small>
+ <Notification {title} {subtitle} show={true} {type} {nonClosable} {hideAfterSeconds} />
+</section>
diff --git a/code/app/src/routes/book/toggles/+page.svelte b/code/app/src/routes/book/toggles/+page.svelte
new file mode 100644
index 0000000..cb0adec
--- /dev/null
+++ b/code/app/src/routes/book/toggles/+page.svelte
@@ -0,0 +1,27 @@
+<script>
+ import Switch from "$components/switch.svelte";
+</script>
+
+<section>
+ <h2>Default</h2>
+ <Switch />
+</section>
+<section>
+ <h2>Short</h2>
+ <Switch type="short" />
+</section>
+<section>
+ <h2>Icon</h2>
+ <Switch type="icon" />
+</section>
+<section>
+ <h2>Label / Description</h2>
+ <div class="max-w-md">
+ <Switch label="Label" description="Some text" />
+ </div>
+</section>
+
+<section>
+ <h2>Label / Description (right aligned)</h2>
+ <Switch label="Label" description="Some text" rightAlignedLabelDescription />
+</section>
diff --git a/code/app/src/services/abstractions/IAccountService.ts b/code/app/src/services/abstractions/IAccountService.ts
new file mode 100644
index 0000000..d3d48b0
--- /dev/null
+++ b/code/app/src/services/abstractions/IAccountService.ts
@@ -0,0 +1,54 @@
+import type { KnownProblem } from "$models/internal/KnownProblem";
+import type { Writable } from "svelte/store";
+
+export interface IAccountService {
+ session: Writable<Session>,
+ login_async(payload: LoginPayload): Promise<LoginResponse>,
+ logout_async(): Promise<void>,
+ end_session_async(callback?: Function): Promise<void>,
+ create_account_async(payload: CreateAccountPayload): Promise<CreateAccountResponse>,
+ delete_current_async(): Promise<DeleteAccountResponse>,
+ update_current_async(payload: UpdateAccountPayload): Promise<UpdateAccountResponse>,
+}
+
+export type Session = {
+ username: string,
+ displayName: string,
+ id: string,
+ _lastUpdated: number
+}
+
+export type LoginPayload = {
+ username: string,
+ password: string,
+ persist: boolean
+}
+
+export type LoginResponse = {
+ isLoggedIn: boolean,
+ knownProblem?: KnownProblem
+}
+
+export type CreateAccountPayload = {
+ username: string,
+ password: string,
+}
+
+export type CreateAccountResponse = {
+ isCreated: boolean,
+ knownProblem?: KnownProblem
+}
+
+export type DeleteAccountResponse = {
+ isDeleted: boolean
+}
+
+export type UpdateAccountPayload = {
+ username: string,
+ password: string
+}
+
+export type UpdateAccountResponse = {
+ isUpdated: boolean,
+ knownProblem?: KnownProblem
+} \ No newline at end of file
diff --git a/code/app/src/services/abstractions/IApiTokenService.ts b/code/app/src/services/abstractions/IApiTokenService.ts
new file mode 100644
index 0000000..fdf82eb
--- /dev/null
+++ b/code/app/src/services/abstractions/IApiTokenService.ts
@@ -0,0 +1,34 @@
+import type { Temporal } from "temporal-polyfill"
+
+export interface IApiTokenService {
+ create_token_async(payload: CreateTokenPayload): Promise<CreateTokenResponse>,
+ delete_token_async(payload: DeleteTokenPayload): Promise<DeleteTokenResponse>,
+ get_tokens_async(query: TokenQuery): Promise<GetTokensResponse>
+}
+export type GetTokensResponse = {
+ results: Array<GetTokensTokenModel>
+};
+export type GetTokensTokenModel = {
+ id: string,
+ name: string,
+ permissions: string[]
+}
+export type TokenQuery = {
+ includeStale: boolean
+};
+export type DeleteTokenResponse = {
+ isDeleted: boolean
+};
+export type DeleteTokenPayload = {
+ id: string
+};
+export type CreateTokenResponse = {
+ isCreated: boolean
+};
+export type CreateTokenPayload = {
+ expiryDate: Temporal.PlainDateTime,
+ allowRead: boolean,
+ allowCreate: boolean,
+ allowUpdate: boolean,
+ allowDelete: boolean
+}; \ No newline at end of file
diff --git a/code/app/src/services/abstractions/IPasswordResetService.ts b/code/app/src/services/abstractions/IPasswordResetService.ts
new file mode 100644
index 0000000..59d2bc6
--- /dev/null
+++ b/code/app/src/services/abstractions/IPasswordResetService.ts
@@ -0,0 +1,21 @@
+import type { KnownProblem } from "$models/internal/KnownProblem"
+
+export interface IPasswordResetService {
+ create_request_async(email: string): Promise<CreateRequestResponse>,
+ fulfill_request_async(id: string, newPassword: string): Promise<FulfillRequestResponse>,
+ request_is_valid_async(id: string): Promise<RequestIsValidResponse>
+}
+
+export type RequestIsValidResponse = {
+ isValid: boolean
+}
+
+export type FulfillRequestResponse = {
+ isFulfilled: boolean,
+ knownProblem?: KnownProblem
+}
+
+export type CreateRequestResponse = {
+ isCreated: boolean,
+ knownProblem?: KnownProblem
+} \ No newline at end of file
diff --git a/code/app/src/services/abstractions/ISettingsService.ts b/code/app/src/services/abstractions/ISettingsService.ts
new file mode 100644
index 0000000..366e337
--- /dev/null
+++ b/code/app/src/services/abstractions/ISettingsService.ts
@@ -0,0 +1,3 @@
+export interface ISettingsService {
+ get_user_settings(): Promise<void>,
+} \ No newline at end of file
diff --git a/code/app/src/services/account-service.ts b/code/app/src/services/account-service.ts
new file mode 100644
index 0000000..b2bb375
--- /dev/null
+++ b/code/app/src/services/account-service.ts
@@ -0,0 +1,124 @@
+import { http_delete_async, http_get_async, http_post_async } from "$utilities/_fetch";
+import { browser } from "$app/environment";
+import { api_base, CookieNames, StorageKeys } from "$configuration";
+import { is_known_problem } from "$models/internal/KnownProblem";
+import { log_debug } from "$utilities/logger";
+import { StoreType, create_writable_persistent } from "$utilities/persistent-store";
+import { get } from "svelte/store";
+import type { Writable } from "svelte/store";
+import { Temporal } from "temporal-polyfill";
+import type {
+ CreateAccountPayload,
+ CreateAccountResponse,
+ DeleteAccountResponse,
+ IAccountService,
+ LoginPayload,
+ LoginResponse,
+ Session,
+ UpdateAccountPayload,
+ UpdateAccountResponse,
+} from "./abstractions/IAccountService";
+
+export class AccountService implements IAccountService {
+ session: Writable<Session> | undefined;
+ private sessionCooldown = 3600;
+
+ constructor() {
+ if (browser) {
+ this.session = create_writable_persistent({
+ name: StorageKeys.session,
+ initialState: {} as Session,
+ options: {
+ store: StoreType.LOCAL,
+ },
+ });
+ this.refresh_session();
+ } else {
+ this.session = undefined;
+ }
+ }
+
+ static resolve(): IAccountService {
+ return new AccountService();
+ }
+
+ async refresh_session(forceRefresh: boolean = false): Promise<void> {
+ if (!this.session) return;
+ const currentValue = get(this.session);
+ const currentEpoch = Temporal.Now.instant().epochSeconds;
+ if (!forceRefresh && ((currentValue?._lastUpdated ?? 0) + this.sessionCooldown) > currentEpoch) {
+ log_debug("Session is not stale yet", {
+ currentEpoch,
+ staleEpoch: currentValue?._lastUpdated + this.sessionCooldown,
+ });
+ return;
+ }
+ const sessionResponse = await http_get_async(api_base("_/session-data"));
+ if (sessionResponse.ok) {
+ this.session.set(await sessionResponse.json());
+ } else {
+ this.session.set(null);
+ }
+ }
+
+ async end_session_async(callback: Function = undefined): Promise<void> {
+ if (!this.session) return;
+ await this.logout_async();
+ this.session.set(null);
+ if (callback && typeof callback === "function") callback();
+ }
+
+ async login_async(payload: LoginPayload): Promise<LoginResponse> {
+ const response = await http_post_async(api_base("_/account/login"), payload);
+ if (response.ok) return { isLoggedIn: true };
+ if (is_known_problem(response)) return {
+ isLoggedIn: false,
+ knownProblem: await response.json(),
+ };
+ return {
+ isLoggedIn: false,
+ };
+ }
+
+ async logout_async(): Promise<void> {
+ const response = await http_get_async(api_base("_/account/logout"));
+ if (!response.ok) {
+ const deleteCookieResponse = await fetch("/delete-cookie?key=" + CookieNames.session);
+ if (!deleteCookieResponse.ok) {
+ throw new Error("Could neither logout nor delete session cookie.");
+ }
+ }
+ return;
+ }
+
+ async create_account_async(payload: CreateAccountPayload): Promise<CreateAccountResponse> {
+ const response = await http_post_async(api_base("_/account/create"), payload);
+ if (response.ok) return { isCreated: true };
+ if (is_known_problem(response)) return {
+ isCreated: false,
+ knownProblem: await response.json(),
+ };
+ return {
+ isCreated: false,
+ };
+ }
+
+ async delete_current_async(): Promise<DeleteAccountResponse> {
+ const response = await http_delete_async(api_base("_/account/delete"));
+ return {
+ isDeleted: response.ok,
+ };
+ }
+
+ async update_current_async(payload: UpdateAccountPayload): Promise<UpdateAccountResponse> {
+ const response = await http_post_async(api_base("_/account/update"), payload);
+ if (response.ok) return { isUpdated: true };
+ if (is_known_problem(response)) return {
+ isUpdated: false,
+ knownProblem: await response.json(),
+ };
+ return {
+ isUpdated: false,
+ };
+ }
+} \ No newline at end of file
diff --git a/code/app/src/services/api-tokens-service.ts b/code/app/src/services/api-tokens-service.ts
new file mode 100644
index 0000000..fb8b126
--- /dev/null
+++ b/code/app/src/services/api-tokens-service.ts
@@ -0,0 +1,22 @@
+import { api_base } from "$configuration";
+import { http_delete_async, http_get_async, http_post_async } from "$utilities/_fetch";
+import type { CreateTokenPayload, CreateTokenResponse, DeleteTokenPayload, DeleteTokenResponse, GetTokensResponse, IApiTokenService, TokenQuery } from "./abstractions/IApiTokenService";
+
+export class ApiTokenService implements IApiTokenService {
+ constructor() { }
+ static resolve() {
+ return new ApiTokenService();
+ }
+ async create_token_async(payload: CreateTokenPayload): Promise<CreateTokenResponse> {
+ const response = await http_post_async(api_base("v1/api-tokens/create"), payload);
+ return;
+ };
+ async delete_token_async(payload: DeleteTokenPayload): Promise<DeleteTokenResponse> {
+ const response = await http_delete_async(api_base("v1/api-tokens/delete"), payload);
+ return;
+ };
+ async get_tokens_async(query: TokenQuery): Promise<GetTokensResponse> {
+ const response = await http_get_async(api_base("v1/api-tokens"));
+ return;
+ };
+} \ No newline at end of file
diff --git a/code/app/src/services/password-reset-service.ts b/code/app/src/services/password-reset-service.ts
new file mode 100644
index 0000000..4a174fa
--- /dev/null
+++ b/code/app/src/services/password-reset-service.ts
@@ -0,0 +1,48 @@
+import { http_get_async, http_post_async } from "$utilities/_fetch";
+import { api_base } from "$configuration";
+import { is_known_problem } from "$models/internal/KnownProblem";
+import type {
+ CreateRequestResponse,
+ FulfillRequestResponse,
+ IPasswordResetService,
+ RequestIsValidResponse,
+} from "./abstractions/IPasswordResetService";
+
+export class PasswordResetService implements IPasswordResetService {
+ static resolve(): IPasswordResetService {
+ return new PasswordResetService();
+ }
+ async create_request_async(email: string): Promise<CreateRequestResponse> {
+ const response = await http_post_async(api_base("_/password-reset-request/create"), { email });
+ if (response.ok) return { isCreated: true };
+ if (is_known_problem(response)) return {
+ isCreated: false,
+ knownProblem: await response.json(),
+ };
+
+ return {
+ isCreated: false,
+ };
+ }
+
+ async fulfill_request_async(id: string, newPassword: string): Promise<FulfillRequestResponse> {
+ const response = await http_post_async(api_base("_/password-reset-request/fulfill"), { id: id, newPassword });
+ if (response.ok) return { isFulfilled: true };
+ if (is_known_problem(response)) return {
+ isFulfilled: false,
+ knownProblem: await response.json(),
+ };
+
+ return {
+ isFulfilled: false,
+ };
+ }
+
+ async request_is_valid_async(id: string): Promise<RequestIsValidResponse> {
+ const response = await http_get_async(api_base("_/password-reset-request/is-valid?id=" + id));
+ const responseBody = await response.json() as { isValid: boolean };
+ return {
+ isValid: responseBody.isValid,
+ };
+ }
+} \ No newline at end of file
diff --git a/code/app/src/services/settings-service.ts b/code/app/src/services/settings-service.ts
new file mode 100644
index 0000000..a0a77d4
--- /dev/null
+++ b/code/app/src/services/settings-service.ts
@@ -0,0 +1,10 @@
+import type { ISettingsService } from "./abstractions/ISettingsService";
+
+export class SettingService implements ISettingsService {
+ static resolve(): ISettingsService {
+ return new SettingService();
+ }
+ get_user_settings(): Promise<void> {
+ throw new Error("Method not implemented.");
+ }
+} \ No newline at end of file
diff --git a/code/app/src/utilities/_fetch.ts b/code/app/src/utilities/_fetch.ts
new file mode 100644
index 0000000..992c7f5
--- /dev/null
+++ b/code/app/src/utilities/_fetch.ts
@@ -0,0 +1,94 @@
+import { Temporal } from "temporal-polyfill";
+import { redirect } from "@sveltejs/kit";
+import { browser } from "$app/environment";
+import { goto } from "$app/navigation";
+import { SignInPageMessage, signInPageMessageQueryKey } from "$routes/(main)/(public)/sign-in";
+import { log_error } from "$utilities/logger";
+import { AccountService } from "$services/account-service";
+
+export async function http_post_async(url: string, body?: object | string, timeout = -1, skip_401_check = false, abort_signal?: AbortSignal): Promise<Response> {
+ const init = make_request_init("post", body, abort_signal);
+ const response = await internal_fetch_async({ url, init, timeout });
+ if (!skip_401_check && await redirect_if_401_async(response)) throw new Error("Server returned 401");
+ return response;
+}
+
+export async function http_get_async(url: string, timeout = -1, skip_401_check = false, abort_signal?: AbortSignal): Promise<Response> {
+ const init = make_request_init("get", undefined, abort_signal);
+ const response = await internal_fetch_async({ url, init, timeout });
+ if (!skip_401_check && await redirect_if_401_async(response)) throw new Error("Server returned 401");
+ return response;
+}
+
+export async function http_delete_async(url: string, body?: object | string, timeout = -1, skip_401_check = false, abort_signal?: AbortSignal): Promise<Response> {
+ const init = make_request_init("delete", body, abort_signal);
+ const response = await internal_fetch_async({ url, init, timeout });
+ if (!skip_401_check && await redirect_if_401_async(response)) throw new Error("Server returned 401");
+ return response;
+}
+
+async function internal_fetch_async(request: InternalFetchRequest): Promise<Response> {
+ if (!request.init) throw new Error("request.init is required");
+ const fetch_request = new Request(request.url, request.init);
+ let response: any;
+
+ try {
+ if (request.timeout && request.timeout > 500) {
+ response = await Promise.race([
+ fetch(fetch_request),
+ new Promise((_, reject) => setTimeout(() => reject(new Error("Timeout")), request.timeout)),
+ ]);
+ } else {
+ response = await fetch(fetch_request);
+ }
+ } catch (error: any) {
+ log_error(error);
+ if (error.message === "Timeout") {
+ console.error("Request timed out");
+ } else if (error.message === "Network request failed") {
+ console.error("No internet connection");
+ } else {
+ throw error;
+ }
+ }
+
+ return response;
+}
+
+async function redirect_if_401_async(response: Response): Promise<boolean> {
+ if (response.status === 401) {
+ const redirectUrl = `/sign-in?${signInPageMessageQueryKey}=${SignInPageMessage.LOGGED_OUT}`;
+ await AccountService.resolve().end_session_async();
+ if (browser) {
+ await goto(redirectUrl);
+ } else {
+ throw redirect(307, redirectUrl);
+ }
+ }
+ return false;
+}
+
+function make_request_init(method: string, body?: any, signal?: AbortSignal): RequestInit {
+ const init = {
+ method,
+ credentials: "include",
+ signal,
+ headers: {
+ "X-TimeZone": Temporal.Now.timeZone().id,
+ },
+ } as RequestInit;
+
+ if (body) {
+ init.body = JSON.stringify(body);
+ init.headers["Content-Type"] = "application/json;charset=UTF-8";
+ }
+
+ return init;
+}
+
+export type InternalFetchRequest = {
+ url: string,
+ init: RequestInit,
+ timeout?: number
+ retry_count?: number,
+} \ No newline at end of file
diff --git a/code/app/src/utilities/cache.ts b/code/app/src/utilities/cache.ts
new file mode 100644
index 0000000..db9be9a
--- /dev/null
+++ b/code/app/src/utilities/cache.ts
@@ -0,0 +1,38 @@
+import { Temporal } from "temporal-polyfill";
+import { log_debug } from "$utilities/logger";
+
+let cache = {};
+
+export const CacheKeys = {
+ isAuthenticated: "isAuthenticated"
+}
+
+export async function cached_result_async<T>(key: string, staleAfterSeconds: number, get_result: any, forceRefresh: boolean = false) {
+ if (!cache[key]) {
+ cache[key] = {
+ l: 0,
+ c: undefined as T,
+ };
+ }
+ const staleEpoch = ((cache[key]?.l ?? 0) + staleAfterSeconds);
+ const isStale = forceRefresh || (staleEpoch < Temporal.Now.instant().epochSeconds);
+ if (isStale || !cache[key]?.c) {
+ cache[key].c = typeof get_result === "function" ? await get_result() : get_result;
+ cache[key].l = Temporal.Now.instant().epochSeconds;
+ }
+
+ log_debug("Ran cached_result_async", {
+ cacheKey: key,
+ isStale,
+ cache: cache[key],
+ staleEpoch,
+ });
+
+ return cache[key].c as T;
+}
+
+export function clear_cache_key(key: string) {
+ if (!key) throw new Error("No key was specified");
+ cache[key].c = undefined;
+ log_debug("Cleared cache with key: " + key);
+} \ No newline at end of file
diff --git a/code/app/src/utilities/colors.ts b/code/app/src/utilities/colors.ts
new file mode 100644
index 0000000..34c7992
--- /dev/null
+++ b/code/app/src/utilities/colors.ts
@@ -0,0 +1,47 @@
+export function generate_random_hex_color(skip_contrast_check = false) {
+ let hex = __generate_random_hex_color();
+ if (skip_contrast_check) return hex;
+ while ((__calculate_contrast_ratio("#ffffff", hex) < 4.5) || (__calculate_contrast_ratio("#000000", hex) < 4.5)) {
+ hex = __generate_random_hex_color();
+ }
+
+ return hex;
+}
+
+// Largely copied from chroma js api
+function __generate_random_hex_color(): string {
+ let code = "#";
+ for (let i = 0; i < 6; i++) {
+ code += "0123456789abcdef".charAt(Math.floor(Math.random() * 16));
+ }
+ return code;
+}
+
+function __calculate_contrast_ratio(hex1: string, hex2: string): number {
+ const rgb1 = __hex_to_rgb(hex1);
+ const rgb2 = __hex_to_rgb(hex2);
+ const l1 = __get_luminance(rgb1[0], rgb1[1], rgb1[2]);
+ const l2 = __get_luminance(rgb2[0], rgb2[1], rgb2[2]);
+ const result = l1 > l2 ? (l1 + 0.05) / (l2 + 0.05) : (l2 + 0.05) / (l1 + 0.05);
+ return result;
+}
+
+function __hex_to_rgb(hex: string): number[] {
+ if (!hex.match(/^#([A-Fa-f0-9]{6})$/)) return [];
+ if (hex[0] === "#") hex = hex.substring(1, hex.length);
+ return [parseInt(hex.substring(0, 2), 16), parseInt(hex.substring(2, 4), 16), parseInt(hex.substring(4, 6), 16)];
+}
+
+function __get_luminance(r: any, g: any, b: any) {
+ // relative luminance
+ // see http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
+ r = __luminance_x(r);
+ g = __luminance_x(g);
+ b = __luminance_x(b);
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
+}
+
+function __luminance_x(x: any) {
+ x /= 255;
+ return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
+}
diff --git a/code/app/src/utilities/crypto-helpers.ts b/code/app/src/utilities/crypto-helpers.ts
new file mode 100644
index 0000000..49af7d3
--- /dev/null
+++ b/code/app/src/utilities/crypto-helpers.ts
@@ -0,0 +1,48 @@
+// A formatted version of a popular md5 implementation.
+// Original copyright (c) Paul Johnston & Greg Holt.
+// The function itself is now 42 lines long.
+// https://stackoverflow.com/a/60467595 "Don't deny."
+
+export function get_md5_hash(inputString: string): string {
+ const hc = "0123456789abcdef";
+ function rh(n) { var j, s = ""; for (j = 0; j <= 3; j++) s += hc.charAt((n >> (j * 8 + 4)) & 0x0F) + hc.charAt((n >> (j * 8)) & 0x0F); return s; }
+ function ad(x, y) { var l = (x & 0xFFFF) + (y & 0xFFFF); var m = (x >> 16) + (y >> 16) + (l >> 16); return (m << 16) | (l & 0xFFFF); }
+ function rl(n, c) { return (n << c) | (n >>> (32 - c)); }
+ function cm(q, a, b, x, s, t) { return ad(rl(ad(ad(a, q), ad(x, t)), s), b); }
+ function ff(a, b, c, d, x, s, t) { return cm((b & c) | ((~b) & d), a, b, x, s, t); }
+ function gg(a, b, c, d, x, s, t) { return cm((b & d) | (c & (~d)), a, b, x, s, t); }
+ function hh(a, b, c, d, x, s, t) { return cm(b ^ c ^ d, a, b, x, s, t); }
+ function ii(a, b, c, d, x, s, t) { return cm(c ^ (b | (~d)), a, b, x, s, t); }
+ function sb(x) {
+ var i; var nblk = ((x.length + 8) >> 6) + 1; var blks = new Array(nblk * 16); for (i = 0; i < nblk * 16; i++) blks[i] = 0;
+ for (i = 0; i < x.length; i++) blks[i >> 2] |= x.charCodeAt(i) << ((i % 4) * 8);
+ blks[i >> 2] |= 0x80 << ((i % 4) * 8); blks[nblk * 16 - 2] = x.length * 8; return blks;
+ }
+ var i, x = sb(inputString), a = 1732584193, b = -271733879, c = -1732584194, d = 271733878, olda, oldb, oldc, oldd;
+ for (i = 0; i < x.length; i += 16) {
+ olda = a; oldb = b; oldc = c; oldd = d;
+ a = ff(a, b, c, d, x[i + 0], 7, -680876936); d = ff(d, a, b, c, x[i + 1], 12, -389564586); c = ff(c, d, a, b, x[i + 2], 17, 606105819);
+ b = ff(b, c, d, a, x[i + 3], 22, -1044525330); a = ff(a, b, c, d, x[i + 4], 7, -176418897); d = ff(d, a, b, c, x[i + 5], 12, 1200080426);
+ c = ff(c, d, a, b, x[i + 6], 17, -1473231341); b = ff(b, c, d, a, x[i + 7], 22, -45705983); a = ff(a, b, c, d, x[i + 8], 7, 1770035416);
+ d = ff(d, a, b, c, x[i + 9], 12, -1958414417); c = ff(c, d, a, b, x[i + 10], 17, -42063); b = ff(b, c, d, a, x[i + 11], 22, -1990404162);
+ a = ff(a, b, c, d, x[i + 12], 7, 1804603682); d = ff(d, a, b, c, x[i + 13], 12, -40341101); c = ff(c, d, a, b, x[i + 14], 17, -1502002290);
+ b = ff(b, c, d, a, x[i + 15], 22, 1236535329); a = gg(a, b, c, d, x[i + 1], 5, -165796510); d = gg(d, a, b, c, x[i + 6], 9, -1069501632);
+ c = gg(c, d, a, b, x[i + 11], 14, 643717713); b = gg(b, c, d, a, x[i + 0], 20, -373897302); a = gg(a, b, c, d, x[i + 5], 5, -701558691);
+ d = gg(d, a, b, c, x[i + 10], 9, 38016083); c = gg(c, d, a, b, x[i + 15], 14, -660478335); b = gg(b, c, d, a, x[i + 4], 20, -405537848);
+ a = gg(a, b, c, d, x[i + 9], 5, 568446438); d = gg(d, a, b, c, x[i + 14], 9, -1019803690); c = gg(c, d, a, b, x[i + 3], 14, -187363961);
+ b = gg(b, c, d, a, x[i + 8], 20, 1163531501); a = gg(a, b, c, d, x[i + 13], 5, -1444681467); d = gg(d, a, b, c, x[i + 2], 9, -51403784);
+ c = gg(c, d, a, b, x[i + 7], 14, 1735328473); b = gg(b, c, d, a, x[i + 12], 20, -1926607734); a = hh(a, b, c, d, x[i + 5], 4, -378558);
+ d = hh(d, a, b, c, x[i + 8], 11, -2022574463); c = hh(c, d, a, b, x[i + 11], 16, 1839030562); b = hh(b, c, d, a, x[i + 14], 23, -35309556);
+ a = hh(a, b, c, d, x[i + 1], 4, -1530992060); d = hh(d, a, b, c, x[i + 4], 11, 1272893353); c = hh(c, d, a, b, x[i + 7], 16, -155497632);
+ b = hh(b, c, d, a, x[i + 10], 23, -1094730640); a = hh(a, b, c, d, x[i + 13], 4, 681279174); d = hh(d, a, b, c, x[i + 0], 11, -358537222);
+ c = hh(c, d, a, b, x[i + 3], 16, -722521979); b = hh(b, c, d, a, x[i + 6], 23, 76029189); a = hh(a, b, c, d, x[i + 9], 4, -640364487);
+ d = hh(d, a, b, c, x[i + 12], 11, -421815835); c = hh(c, d, a, b, x[i + 15], 16, 530742520); b = hh(b, c, d, a, x[i + 2], 23, -995338651);
+ a = ii(a, b, c, d, x[i + 0], 6, -198630844); d = ii(d, a, b, c, x[i + 7], 10, 1126891415); c = ii(c, d, a, b, x[i + 14], 15, -1416354905);
+ b = ii(b, c, d, a, x[i + 5], 21, -57434055); a = ii(a, b, c, d, x[i + 12], 6, 1700485571); d = ii(d, a, b, c, x[i + 3], 10, -1894986606);
+ c = ii(c, d, a, b, x[i + 10], 15, -1051523); b = ii(b, c, d, a, x[i + 1], 21, -2054922799); a = ii(a, b, c, d, x[i + 8], 6, 1873313359);
+ d = ii(d, a, b, c, x[i + 15], 10, -30611744); c = ii(c, d, a, b, x[i + 6], 15, -1560198380); b = ii(b, c, d, a, x[i + 13], 21, 1309151649);
+ a = ii(a, b, c, d, x[i + 4], 6, -145523070); d = ii(d, a, b, c, x[i + 11], 10, -1120210379); c = ii(c, d, a, b, x[i + 2], 15, 718787259);
+ b = ii(b, c, d, a, x[i + 9], 21, -343485551); a = ad(a, olda); b = ad(b, oldb); c = ad(c, oldc); d = ad(d, oldd);
+ }
+ return rh(a) + rh(b) + rh(c) + rh(d);
+} \ No newline at end of file
diff --git a/code/app/src/utilities/dom-helpers.ts b/code/app/src/utilities/dom-helpers.ts
new file mode 100644
index 0000000..94a74c1
--- /dev/null
+++ b/code/app/src/utilities/dom-helpers.ts
@@ -0,0 +1,105 @@
+interface CreateElementOptions {
+ name: string,
+ properties?: object,
+ children?: Array<HTMLElement | Function | Node>
+}
+
+export function create_element_from_object(elementOptions: CreateElementOptions): HTMLElement {
+ return create_element(elementOptions.name, elementOptions.properties, elementOptions.children);
+}
+
+export function create_element(name: string, properties?: object, children?: Array<HTMLElement | any>): HTMLElement {
+ if (!name || name.length < 1) {
+ throw new Error("name is required");
+ }
+ const node = document.createElement(name);
+ if (properties) {
+ for (const [key, value] of Object.entries(properties)) {
+ // @ts-ignore
+ node[key] = value;
+ }
+ }
+
+ if (children && children.length > 0) {
+ let actualChildren = children;
+ if (typeof children === "function") {
+ // @ts-ignore
+ actualChildren = children();
+ }
+ for (const child of actualChildren) {
+ node.appendChild(child as Node);
+ }
+ }
+ return node;
+}
+
+// https://stackoverflow.com/a/45215694/11961742
+export function get_selected_options(domElement: HTMLSelectElement): Array<string> {
+ const ret = [];
+
+ // fast but not universally supported
+ if (domElement.selectedOptions !== undefined) {
+ for (let i = 0; i < domElement.selectedOptions.length; i++) {
+ ret.push(domElement.selectedOptions[i].value);
+ }
+
+ // compatible, but can be painfully slow
+ } else {
+ for (let i = 0; i < domElement.options.length; i++) {
+ if (domElement.options[i].selected) {
+ ret.push(domElement.options[i].value);
+ }
+ }
+ }
+ return ret;
+}
+
+
+export function get_element_position(element: HTMLElement | any) {
+ if (!element) return {x: 0, y: 0};
+ let x = 0;
+ let y = 0;
+ while (true) {
+ x += element.offsetLeft;
+ y += element.offsetTop;
+ if (element.offsetParent === null) {
+ break;
+ }
+ element = element.offsetParent;
+ }
+ return {x, y};
+}
+
+export function restrict_input_to_numbers(element: HTMLElement, specials: Array<string> = [], mergeSpecialsWithDefaults: boolean = false): void {
+ if (!element) return;
+ element.addEventListener("keydown", (e) => {
+ const defaultSpecials = ["Backspace", "ArrowLeft", "ArrowRight", "Tab"];
+ let keys = specials.length > 0 ? specials : defaultSpecials;
+ if (mergeSpecialsWithDefaults && specials) {
+ keys = [...specials, ...defaultSpecials];
+ }
+ if (keys.indexOf(e.key) !== -1) {
+ return;
+ }
+ if (isNaN(parseInt(e.key))) {
+ e.preventDefault();
+ }
+ });
+}
+
+export function element_has_focus(element: HTMLElement): boolean {
+ return element === document.activeElement;
+}
+
+export function move_focus(element: HTMLElement): void {
+ if (!element) {
+ element = document.getElementsByTagName("body")[0];
+ }
+ element.focus();
+ // @ts-ignore
+ if (!element_has_focus(element)) {
+ element.setAttribute("tabindex", "-1");
+ element.focus();
+ }
+}
+
diff --git a/code/app/src/utilities/global-state.ts b/code/app/src/utilities/global-state.ts
new file mode 100644
index 0000000..b585ced
--- /dev/null
+++ b/code/app/src/utilities/global-state.ts
@@ -0,0 +1,22 @@
+import { get } from "svelte/store";
+import { create_writable_persistent } from "./persistent-store";
+
+const state = create_writable_persistent<any>({
+ initialState: {},
+ name: "global-state"
+});
+
+export type GlobalStateKeys = "isLoggedIn" | "showEmailValidatedAlertWhenLoggedIn" | "all";
+
+export function fgs(key: GlobalStateKeys): any {
+ const value = get(state);
+ if (key === "all") return value;
+ return value[key];
+}
+
+export function sgs(key: GlobalStateKeys, value: any) {
+ if (key === "all") throw new Error("Not allowed to set global state key: all");
+ const stateValue = get(state);
+ stateValue[key] = JSON.stringify(value)
+ state.set(stateValue);
+} \ No newline at end of file
diff --git a/code/app/src/utilities/logger.ts b/code/app/src/utilities/logger.ts
new file mode 100644
index 0000000..c21bd76
--- /dev/null
+++ b/code/app/src/utilities/logger.ts
@@ -0,0 +1,118 @@
+import { browser, dev } from "$app/environment";
+import { env } from '$env/dynamic/private';
+import { StorageKeys } from "$configuration";
+import pino, { type Logger, type LoggerOptions } from "pino";
+import { createStream } from "pino-seq";
+import type { SeqConfig } from "pino-seq";
+
+function get_pino_logger(): Logger {
+ const config = {
+ name: "greatoffice-app",
+ level: LogLevel.current().as_string(),
+ customLevels: {
+ "INFO": LogLevel.INFO,
+ "WARNING": LogLevel.WARNING,
+ "ERROR": LogLevel.ERROR,
+ "DEBUG": LogLevel.DEBUG,
+ "SILENT": LogLevel.SILENT,
+ }
+ } as LoggerOptions;
+
+ const seq = {
+ config: {
+ apiKey: browser ? env.SEQ_API_KEY : "",
+ serverUrl: browser ? env.SEQ_SERVER_URL : ""
+ } as SeqConfig,
+ streams: [{
+ level: LogLevel.to_string(LogLevel.DEBUG),
+ }],
+ enabled: () => (
+ !browser
+ && !dev
+ && seq.config.apiKey.length > 0
+ && seq.config.serverUrl.length > 0
+ )
+ };
+
+ return seq.enabled() ? pino(config, createStream(seq.config)) : pino(config);
+}
+
+type LogLevelString = "DEBUG" | "INFO" | "WARNING" | "ERROR" | "SILENT";
+
+export const LogLevel = {
+ DEBUG: 0,
+ INFO: 1,
+ WARNING: 2,
+ ERROR: 3,
+ SILENT: 4,
+ current(): { as_string: Function, as_number: Function } {
+ const logLevelString = (browser ? window.sessionStorage.getItem(StorageKeys.logLevel) : env.LOG_LEVEL) as LogLevelString;
+ return {
+ as_number(): number {
+ return LogLevel.to_number_or_default(logLevelString, LogLevel.INFO)
+ },
+ as_string(): LogLevelString {
+ return logLevelString.length > 3 ? logLevelString : LogLevel.to_string(LogLevel.INFO);
+ }
+ }
+ },
+ to_string(levelInt: number): LogLevelString {
+ switch (levelInt) {
+ case 0:
+ return "DEBUG";
+ case 1:
+ return "INFO";
+ case 2:
+ return "WARNING";
+ case 3:
+ return "ERROR";
+ case 4:
+ return "SILENT";
+ default:
+ throw new Error("Unknown LogLevel number " + levelInt);
+ }
+ },
+ to_number_or_default(levelString?: string | null, defaultValue?: number): number {
+ if (!levelString && defaultValue) return defaultValue;
+ else if (!levelString && !defaultValue) throw new Error("levelString was empty, and no default value was specified");
+ switch (levelString?.toUpperCase()) {
+ case "DEBUG":
+ return 0;
+ case "INFO":
+ return 1;
+ case "WARNING":
+ return 2;
+ case "ERROR":
+ return 3;
+ case "SILENT":
+ return 4;
+ default:
+ if (!defaultValue) throw new Error("Unknown LogLevel string " + levelString + ", and no defaultValue");
+ else return defaultValue;
+ }
+ },
+};
+
+export function log_warning(message: string, ...additional: any[]): void {
+ if (LogLevel.current().as_number() <= LogLevel.WARNING) {
+ get_pino_logger().warn(message, additional);
+ }
+}
+
+export function log_debug(message: string, ...additional: any[]): void {
+ if (LogLevel.current().as_number() <= LogLevel.DEBUG) {
+ get_pino_logger().debug(message, additional);
+ }
+}
+
+export function log_info(message: string, ...additional: any[]): void {
+ if (LogLevel.current().as_number() <= LogLevel.INFO) {
+ get_pino_logger().info(message, additional);
+ }
+}
+
+export function log_error(message: any, ...additional: any[]): void {
+ if (LogLevel.current().as_number() <= LogLevel.ERROR) {
+ get_pino_logger().error(message, additional);
+ }
+} \ No newline at end of file
diff --git a/code/app/src/utilities/misc-helpers.ts b/code/app/src/utilities/misc-helpers.ts
new file mode 100644
index 0000000..afb20e7
--- /dev/null
+++ b/code/app/src/utilities/misc-helpers.ts
@@ -0,0 +1,77 @@
+export function merge_obj_arr<T>(a: Array<T>, b: Array<T>, props: Array<string>): Array<T> {
+ let start = 0;
+ let merge = [];
+
+ while (start < a.length) {
+
+ if (a[start] === b[start]) {
+ //pushing the merged objects into array
+ merge.push({ ...a[start], ...b[start] });
+ }
+ //incrementing start value
+ start = start + 1;
+ }
+ return merge;
+}
+
+export function no_type_check(x: any) {
+ return x;
+}
+
+export function capitalise(value: string): string {
+ return value.charAt(0).toUpperCase() + value.slice(1);
+}
+
+export function get_query_string(params: any = {}): string {
+ const map = Object.keys(params).reduce((arr: Array<string>, key: string) => {
+ if (params[key] !== undefined) {
+ return arr.concat(`${key}=${encodeURIComponent(params[key])}`);
+ }
+ return arr;
+ }, [] as any);
+
+ if (map.length) {
+ return `?${map.join("&")}`;
+ }
+
+ return "";
+}
+
+export function make_url(url: string, params: object): string {
+ return `${url}${get_query_string(params)}`;
+}
+
+export function noop() {
+}
+
+export function random_string(length: number): string {
+ if (!length) {
+ throw new Error("length is undefined");
+ }
+ let result = "";
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ const charactersLength = characters.length;
+ for (let i = 0; i < length; i++) {
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
+ }
+ return result;
+}
+
+export function get_random_int(min: number, max: number): number {
+ min = Math.ceil(min);
+ max = Math.floor(max);
+ return Math.floor(Math.random() * (max - min + 1)) + min;
+}
+
+export function get_hash_code(value: string): number | undefined {
+ let hash = 0;
+ if (value.length === 0) {
+ return;
+ }
+ for (let i = 0; i < value.length; i++) {
+ const char = value.charCodeAt(i);
+ hash = (hash << 5) - hash + char;
+ hash |= 0;
+ }
+ return hash;
+}
diff --git a/code/app/src/utilities/persistent-store.ts b/code/app/src/utilities/persistent-store.ts
new file mode 100644
index 0000000..3f56312
--- /dev/null
+++ b/code/app/src/utilities/persistent-store.ts
@@ -0,0 +1,111 @@
+import { browser } from "$app/environment";
+import { writable as _writable, readable as _readable } from "svelte/store";
+import type { Writable, Readable, StartStopNotifier } from "svelte/store";
+import { log_debug, log_info } from "./logger";
+
+enum StoreType {
+ SESSION = 0,
+ LOCAL = 1
+}
+
+interface StoreOptions {
+ store?: StoreType;
+}
+
+interface WritableStoreInit<T> {
+ name: string,
+ initialState: T,
+ options?: StoreOptions
+}
+
+interface ReadableStoreInit<T> {
+ name: string,
+ initialState: T,
+ callback: StartStopNotifier<any>,
+ options?: StoreOptions
+}
+
+function get_store(type: StoreType): Storage {
+ if (!browser) return undefined;
+ switch (type) {
+ case StoreType.SESSION:
+ return window.sessionStorage;
+ case StoreType.LOCAL:
+ return window.localStorage;
+ }
+}
+
+function prepared_store_value(value: any): string {
+ try {
+ return JSON.stringify(value);
+ } catch (e) {
+ console.error(e);
+ return "__INVALID__";
+ }
+}
+
+function get_store_value<T>(init: WritableStoreInit<T> | ReadableStoreInit<T>): any {
+ try {
+ const storage = get_store(init.options.store);
+ if (!storage) return;
+ const value = storage.getItem(init.name);
+ if (!value) return false;
+ return JSON.parse(value);
+ } catch (e) {
+ console.error(e);
+ return { __INVALID__: true };
+ }
+}
+
+function hydrate<T>(store: Writable<T>, init: WritableStoreInit<T> | ReadableStoreInit<T>): void {
+ const value = get_store_value<T>(init);
+ if (value && store.set) store.set(value);
+}
+
+function subscribe<T>(store: Writable<T> | Readable<T>, init: WritableStoreInit<T> | ReadableStoreInit<T>): void {
+ const storage = get_store(init.options.store);
+ if (!storage) return;
+ if (!store.subscribe) return;
+ store.subscribe((state: any) => {
+ storage.setItem(init.name, prepared_store_value(state));
+ });
+}
+
+function create_writable_persistent<T>(init: WritableStoreInit<T>): Writable<T> {
+ if (!browser) {
+ log_info("WARN: Persistent store is only available in the browser");
+ return;
+ }
+ if (init.options === undefined) throw new Error("init is a required parameter");
+ log_debug("creating writable store with options: ", init);
+ const store = _writable<T>(init.initialState);
+ hydrate(store, init);
+ subscribe(store, init);
+ return store;
+}
+
+function create_readable_persistent<T>(init: ReadableStoreInit<T>): Readable<T> {
+ if (!browser) {
+ log_info("WARN: Persistent store is only available in the browser");
+ return;
+ }
+ if (init.options === undefined) throw new Error("init is a required parameter");
+ log_debug("Creating readable store with options: ", init);
+ const store = _readable<T>(init.initialState, init.callback);
+ // hydrate(store, options);
+ subscribe(store, init);
+ return store;
+}
+
+export {
+ create_writable_persistent,
+ create_readable_persistent,
+ StoreType,
+};
+
+export type {
+ WritableStoreInit as WritableStore,
+ ReadableStoreInit as ReadableStore,
+ StoreOptions,
+};
+
diff --git a/code/app/src/utilities/storage-helpers.ts b/code/app/src/utilities/storage-helpers.ts
new file mode 100644
index 0000000..cce655c
--- /dev/null
+++ b/code/app/src/utilities/storage-helpers.ts
@@ -0,0 +1,26 @@
+import { browser } from "$app/environment";
+import { is_empty_object } from "./validators";
+
+export type StorageType = "local" | "session";
+export const browserStorage = {
+ remove_with_regex(type: StorageType, regex: RegExp): void {
+ if (!browser) return;
+ const storage = (type === "local" ? window.localStorage : window.sessionStorage);
+ let n = storage.length;
+ while (n--) {
+ const key = storage.key(n);
+ if (key && regex.test(key)) {
+ storage.removeItem(key);
+ }
+ }
+ },
+ set_stringified(type: StorageType, key: string, value: object): void {
+ if (!browser) return;
+ if (is_empty_object(value)) return;
+ (type === "local" ? window.localStorage : window.sessionStorage).setItem(key, JSON.stringify(value));
+ },
+ get_stringified<T>(type: StorageType, key: string): T | any {
+ if (!browser) return;
+ return JSON.parse((type === "local" ? window.localStorage : window.sessionStorage).getItem(key) ?? "{}");
+ }
+} \ No newline at end of file
diff --git a/code/app/src/utilities/testing-helpers.ts b/code/app/src/utilities/testing-helpers.ts
new file mode 100644
index 0000000..f21412e
--- /dev/null
+++ b/code/app/src/utilities/testing-helpers.ts
@@ -0,0 +1,7 @@
+export function get_element_by_pw_key(key: string): HTMLElement | null {
+ return document.querySelector("[pw-key='" + key + "']");
+}
+
+export function get_pw_key_selector(key: string): string {
+ return "[pw-key='" + key + "']";
+} \ No newline at end of file
diff --git a/code/app/src/utilities/validators.ts b/code/app/src/utilities/validators.ts
new file mode 100644
index 0000000..b69470e
--- /dev/null
+++ b/code/app/src/utilities/validators.ts
@@ -0,0 +1,34 @@
+export const EMAIL_REGEX = new RegExp(/^([a-z0-9]+(?:([._\-])[a-z0-9]+)*@(?:[a-z0-9]+(?:(-)[a-z0-9]+)?\.)+[a-z0-9](?:[a-z0-9]*[a-z0-9])?)$/i);
+export const URL_REGEX = new RegExp(/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-.][a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/gm);
+export const GUID_REGEX = new RegExp(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
+export const NORWEGIAN_PHONE_NUMBER_REGEX = new RegExp(/(0047|\+47|47)?\d{8,12}/);
+
+export function is_email(value: string): boolean {
+ return EMAIL_REGEX.test(String(value).toLowerCase());
+}
+
+export function is_url(value: string): boolean {
+ return URL_REGEX.test(String(value).toLowerCase());
+}
+
+export function is_norwegian_phone_number(value: string): boolean {
+ if (value.length < 8 || value.length > 12) {
+ return false;
+ }
+ return NORWEGIAN_PHONE_NUMBER_REGEX.test(String(value));
+}
+
+export function is_guid(value: string): boolean {
+ if (!value) {
+ return false;
+ }
+ if (value[0] === "{") {
+ value = value.substring(1, value.length - 1);
+ }
+ return GUID_REGEX.test(value);
+}
+
+export function is_empty_object(obj: object): boolean {
+ if (!obj) return true;
+ return obj !== void 0 && Object.keys(obj).length > 0;
+} \ No newline at end of file