building out frontend and docker
This commit is contained in:
13
src/lib/components/AutoRefresh.svelte
Normal file
13
src/lib/components/AutoRefresh.svelte
Normal file
@@ -0,0 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { invalidateAll } from '$app/navigation';
|
||||
|
||||
/** Reloads the page's data on an interval while the tab is visible. */
|
||||
let { intervalMs }: { intervalMs: number } = $props();
|
||||
|
||||
$effect(() => {
|
||||
const timer = setInterval(() => {
|
||||
if (document.visibilityState === 'visible') void invalidateAll();
|
||||
}, intervalMs);
|
||||
return () => clearInterval(timer);
|
||||
});
|
||||
</script>
|
||||
7
src/lib/components/Badge.svelte
Normal file
7
src/lib/components/Badge.svelte
Normal file
@@ -0,0 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { Tone } from '#lib/format.ts';
|
||||
|
||||
let { tone, label }: { tone: Tone; label: string } = $props();
|
||||
</script>
|
||||
|
||||
<span class="badge tone-{tone}">{label}</span>
|
||||
179
src/lib/components/FileTree.svelte
Normal file
179
src/lib/components/FileTree.svelte
Normal file
@@ -0,0 +1,179 @@
|
||||
<script lang="ts">
|
||||
import { SvelteSet } from 'svelte/reactivity';
|
||||
import Badge from '#lib/components/Badge.svelte';
|
||||
import TimeAgo from '#lib/components/TimeAgo.svelte';
|
||||
import { ITEM_STATUS } from '#lib/format.ts';
|
||||
import type { TreeNode } from '#lib/server/status/tree-view.ts';
|
||||
|
||||
let { nodes }: { nodes: TreeNode[] } = $props();
|
||||
|
||||
const collapsed = new SvelteSet<string>();
|
||||
let attentionOnly = $state(false);
|
||||
|
||||
interface Row {
|
||||
node: TreeNode;
|
||||
depth: number;
|
||||
}
|
||||
|
||||
const needsAttention = (node: TreeNode): boolean =>
|
||||
node.status !== 'synced' || node.children.some(needsAttention);
|
||||
|
||||
const rows = $derived.by(() => {
|
||||
const result: Row[] = [];
|
||||
const walk = (list: TreeNode[], depth: number) => {
|
||||
for (const node of list) {
|
||||
if (attentionOnly && !needsAttention(node)) continue;
|
||||
result.push({ node, depth });
|
||||
if (node.isFolder && !collapsed.has(node.sourceId)) walk(node.children, depth + 1);
|
||||
}
|
||||
};
|
||||
walk(nodes, 0);
|
||||
return result;
|
||||
});
|
||||
|
||||
function toggle(id: string) {
|
||||
if (collapsed.has(id)) collapsed.delete(id);
|
||||
else collapsed.add(id);
|
||||
}
|
||||
|
||||
function statusOf(node: TreeNode) {
|
||||
if (node.waiting) return { label: 'Waiting on folder', tone: 'info' as const };
|
||||
return ITEM_STATUS[node.status];
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="toolbar">
|
||||
<label class="check small">
|
||||
<input type="checkbox" bind:checked={attentionOnly} />
|
||||
Only show files that need attention
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{#if rows.length === 0}
|
||||
<p class="empty muted">
|
||||
{attentionOnly
|
||||
? 'Everything is synced.'
|
||||
: 'No files yet. They appear here after the first sync.'}
|
||||
</p>
|
||||
{:else}
|
||||
<div class="table-wrap">
|
||||
<table class="register">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Status</th>
|
||||
<th>Changed in SharePoint</th>
|
||||
<th>Last synced</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each rows as { node, depth } (node.sourceId)}
|
||||
{@const status = statusOf(node)}
|
||||
<tr class:folder={node.isFolder}>
|
||||
<td class="name" style:--depth={depth}>
|
||||
{#if node.isFolder}
|
||||
<button
|
||||
type="button"
|
||||
class="twisty"
|
||||
aria-expanded={!collapsed.has(node.sourceId)}
|
||||
aria-label="{collapsed.has(node.sourceId) ? 'Expand' : 'Collapse'} {node.name}"
|
||||
onclick={() => toggle(node.sourceId)}
|
||||
>
|
||||
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 4l4 4-4 4" /></svg>
|
||||
</button>
|
||||
<svg class="icon" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path d="M1.5 3.5h5l1.5 1.5h6.5v8h-13z" />
|
||||
</svg>
|
||||
{:else}
|
||||
<span class="twisty-spacer"></span>
|
||||
<svg class="icon" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path d="M3.5 1.5h6l3 3v10h-9z M9.5 1.5v3h3" />
|
||||
</svg>
|
||||
{/if}
|
||||
<span title={node.error ?? undefined}>{node.name}</span>
|
||||
{#if node.problems > 0}
|
||||
<span class="problems">{node.problems} failed inside</span>
|
||||
{/if}
|
||||
</td>
|
||||
<td><Badge {...status} /></td>
|
||||
<td class="small"><TimeAgo date={node.isFolder ? null : node.modifiedAt} empty="" /></td
|
||||
>
|
||||
<td class="small"><TimeAgo date={node.syncedAt} empty="Not yet" /></td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.toolbar {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.empty {
|
||||
padding: 1.5rem;
|
||||
border: 1px dashed var(--rule);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
padding-left: calc(0.5rem + var(--depth) * 1.25rem);
|
||||
min-width: 18rem;
|
||||
}
|
||||
|
||||
.folder .name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.twisty,
|
||||
.twisty-spacer {
|
||||
flex: none;
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
}
|
||||
|
||||
.twisty {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: var(--radius);
|
||||
background: none;
|
||||
color: var(--pencil);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.twisty svg {
|
||||
width: 0.85rem;
|
||||
height: 0.85rem;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-width: 1.75;
|
||||
transition: transform 120ms ease;
|
||||
}
|
||||
|
||||
.twisty[aria-expanded='true'] svg {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.icon {
|
||||
flex: none;
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
fill: none;
|
||||
stroke: var(--pencil);
|
||||
stroke-width: 1.1;
|
||||
}
|
||||
|
||||
.problems {
|
||||
margin-left: 0.25rem;
|
||||
font-size: var(--step--1);
|
||||
font-weight: 500;
|
||||
color: var(--danger);
|
||||
}
|
||||
</style>
|
||||
62
src/lib/components/ProjectFields.svelte
Normal file
62
src/lib/components/ProjectFields.svelte
Normal file
@@ -0,0 +1,62 @@
|
||||
<script lang="ts">
|
||||
/** The shared add/edit project form fields. */
|
||||
let {
|
||||
values,
|
||||
rootsLocked = false,
|
||||
current
|
||||
}: {
|
||||
values: { name?: string; sourceInput?: string; targetInput?: string };
|
||||
/** After the first sync the roots can't change until the project is reset. */
|
||||
rootsLocked?: boolean;
|
||||
/** Current root paths, shown when editing. */
|
||||
current?: { source: string; target: string };
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<div class="field">
|
||||
<label for="name">Project name</label>
|
||||
<input id="name" name="name" type="text" required maxlength="100" value={values.name ?? ''} />
|
||||
</div>
|
||||
|
||||
{#if rootsLocked && current}
|
||||
<div class="notice">
|
||||
<p><strong>From SharePoint:</strong> {current.source}</p>
|
||||
<p><strong>To ACC:</strong> {current.target}</p>
|
||||
<p class="small muted">
|
||||
These folders are locked because the project has already synced. Reset the project to change
|
||||
them.
|
||||
</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="field">
|
||||
<label for="sourceInput">SharePoint folder</label>
|
||||
<input
|
||||
id="sourceInput"
|
||||
name="sourceInput"
|
||||
type="text"
|
||||
required={!current}
|
||||
value={values.sourceInput ?? ''}
|
||||
placeholder={current?.source}
|
||||
/>
|
||||
<span class="hint">
|
||||
Open the folder in SharePoint and paste the address from your browser. Everything inside it is
|
||||
synced.
|
||||
{#if current}Leave blank to keep the current folder.{/if}
|
||||
</span>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="targetInput">ACC folder</label>
|
||||
<input
|
||||
id="targetInput"
|
||||
name="targetInput"
|
||||
type="text"
|
||||
required={!current}
|
||||
value={values.targetInput ?? ''}
|
||||
placeholder={current?.target}
|
||||
/>
|
||||
<span class="hint">
|
||||
Open the destination folder in ACC Docs and paste the address from your browser.
|
||||
{#if current}Leave blank to keep the current folder.{/if}
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
81
src/lib/components/RunNowButton.svelte
Normal file
81
src/lib/components/RunNowButton.svelte
Normal file
@@ -0,0 +1,81 @@
|
||||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import type { RunRequestResult } from '#lib/server/sync/coordinator.ts';
|
||||
|
||||
let {
|
||||
running,
|
||||
cooldownSeconds,
|
||||
unavailable = null
|
||||
}: {
|
||||
running: boolean;
|
||||
/** Matches the server's per-project cooldown, so the button disables in step with it. */
|
||||
cooldownSeconds: number;
|
||||
/** Why a run can't start (disabled or paused project), if it can't. */
|
||||
unavailable?: string | null;
|
||||
} = $props();
|
||||
|
||||
let cooldownUntil = $state(0);
|
||||
let tick = $state(Date.now());
|
||||
let message = $state<string | null>(null);
|
||||
const remaining = $derived(Math.max(0, Math.ceil((cooldownUntil - tick) / 1000)));
|
||||
|
||||
$effect(() => {
|
||||
const until = cooldownUntil;
|
||||
if (until <= Date.now()) return;
|
||||
const timer = setInterval(() => (tick = Date.now()), 250);
|
||||
return () => clearInterval(timer);
|
||||
});
|
||||
|
||||
function startCooldown(seconds: number) {
|
||||
tick = Date.now();
|
||||
cooldownUntil = tick + seconds * 1000;
|
||||
}
|
||||
|
||||
const MESSAGES: Record<RunRequestResult['status'], (r: RunRequestResult) => string> = {
|
||||
started: () => 'Sync started.',
|
||||
'already-running': () => 'A sync is already running for this project.',
|
||||
cooldown: () => 'Run now was used moments ago. It will be available again shortly.',
|
||||
unavailable: (r) => (r.status === 'unavailable' ? r.reason : '')
|
||||
};
|
||||
</script>
|
||||
|
||||
<form
|
||||
method="POST"
|
||||
action="?/run"
|
||||
class="run-now"
|
||||
use:enhance={() =>
|
||||
async ({ result, update }) => {
|
||||
if (result.type === 'success' && result.data?.run) {
|
||||
const run = result.data.run as RunRequestResult;
|
||||
message = MESSAGES[run.status](run);
|
||||
if (run.status === 'started') startCooldown(cooldownSeconds);
|
||||
if (run.status === 'cooldown') startCooldown(run.retryAfterSeconds);
|
||||
}
|
||||
await update({ reset: false });
|
||||
}}
|
||||
>
|
||||
<button class="button primary" disabled={running || remaining > 0 || !!unavailable}>
|
||||
{#if running}
|
||||
Syncing…
|
||||
{:else if remaining > 0}
|
||||
Run now ({remaining}s)
|
||||
{:else}
|
||||
Run now
|
||||
{/if}
|
||||
</button>
|
||||
<p class="small muted" role="status">{unavailable ?? message ?? ''}</p>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.run-now {
|
||||
display: grid;
|
||||
justify-items: end;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
|
||||
.run-now p {
|
||||
max-width: 22rem;
|
||||
text-align: right;
|
||||
min-height: 1.2em;
|
||||
}
|
||||
</style>
|
||||
14
src/lib/components/TimeAgo.svelte
Normal file
14
src/lib/components/TimeAgo.svelte
Normal file
@@ -0,0 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { formatDateTime, timeAgo } from '#lib/format.ts';
|
||||
import { now } from '#lib/now.svelte.ts';
|
||||
|
||||
let { date, empty = 'Never' }: { date: Date | null; empty?: string } = $props();
|
||||
</script>
|
||||
|
||||
{#if date}
|
||||
<time datetime={date.toISOString()} title={formatDateTime(date)}
|
||||
>{timeAgo(date, now.current)}</time
|
||||
>
|
||||
{:else}
|
||||
<span class="muted">{empty}</span>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user