mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
* fix(nuxt): pre-bundle the CommonJS deps of the markdown stack
`debug` and `extend` are imported by micromark and unified through
@elysola/ui. Served unbundled by the dev server they have no default
export, so the console page failed with a 500 in `nuxt dev`.
* docs(deployment): list the fragments and feishu link migrations
The manual `d1 execute` fallback stopped at 0008, and AGENTS.md named
0001..0010 although 0011 already exists.
* feat(storage): persist the per-group route order
Routes used to load in id order, so the order saved from the console
was lost on the next read. Migration 0012 adds `d1_routes.position`:
saving writes each route's index within its own group (saving one group
never shifts another), and routes load by `group_id, position, id`.
A database without the column keeps working: only a "no such column" /
"has no column named" error falls back to the legacy statements, and
nothing is cached, so a later migration is picked up on the next call.
* feat(console): add in-app destructive-action confirmation
Deleting a route or a group used `window.confirm`, which blocks the page
and ignores the console theme. A promise-based `useConfirm()` now drives
one <ConfirmDialog /> built on the reka-ui AlertDialog that
@elysola/ui ships; reka-ui is pre-bundled so dev keeps a single copy and
the dialog stacks with the Rc dialogs.
A request never outlives its asker: one made after the asking component
unmounted resolves false, and one still open when it unmounts is
cancelled.
* feat(console): confirm member and webhook removal
Removing a member, revoking an invite link and disabling a group's
webhook endpoint took effect on the first click. They now ask first;
disabling the webhook explains that senders still using the secret will
be rejected, and its button is styled as destructive.
* feat(console): confirm removing filled editor rows
Filter conditions and groups, delivery targets, saved fragments and forge
hosts vanished on a single click, taking whatever had been typed with
them. Rows holding content now ask first, while empty, never-filled
rows (`isBlankNode`: default operator, no path, no values, not negated)
are still removed directly.
* fix(i18n): remove duplicate button glyphs
"New Route", "New Group" and the group cards' "Open" link render a Plus
or ArrowRight icon next to their label, so the "+" and "→" baked into
the strings appeared twice.
* style(console): redesign route cards for narrow screens
The card was one flex row whose badges, filter chips, targets and five
hand-drawn icon buttons squeezed the route name on small screens. It is
now a grid driven by a container query: name and actions share the top
line, the filter summary (clamped to two lines) and targets follow, and
the tags wrap below; from 40rem the tags move up beside the title.
Targets of the same platform collapse into one tag with a count, long
ids truncate instead of widening the page, and the actions use lucide
icons with accessible labels.
* feat(console): reorder a group's routes by drag or keyboard
The per-card up/down arrows saved after every single step, so moving a
route five places took five writes. A Reorder mode on the group page now
swaps each card's switch for a drag handle: pointer drags (mouse and
touch) slide the neighbours out of the way and auto-scroll near the
viewport edges, Arrow Up/Down on a focused handle moves a card by one
and is announced to screen readers, and nothing is written until Save
order. Cancel or Escape (unless a dialog or list owns it) drops the
draft.
The cards move into a new RouteList component that owns the drag state.
* style(members): align member cards and invite actions
* style(group-editor): size forge and log target controls
Keep source hosts, platform selectors and remove actions aligned without stretching short controls across the dialog. Wrap component roots explicitly so their internal markup cannot break the grid.
* style(route-editor): group options and delivery target fields
Give each target labeled fields and a compact platform header, widen the filter workspace, and align fragment controls. Scroll failed validation into view when the footer is far from the affected section.
* feat(filters): add bilingual suggestions and value validation
Catalog forge events, actions, payload paths and known values with searchable English and Chinese descriptions. Match-value validation mirrors the server and only rejects inputs that cannot match.
* feat(filters): add searchable creatable value inputs
Build a theme-aligned combobox on the shared reka-ui primitives. Rank stored keys before bilingual descriptions, allow validated custom values, and preserve unconfirmed multi-value drafts instead of silently committing them.
* feat(filter-editor): integrate searchable condition inputs
Replace chip-only values with context-aware bilingual inputs and a compact condition grid. Preserve drafts across tree changes, block saves and tests until drafts are resolved, and keep keyword filters free of hidden operators.
* feat(filters): split pasted values without breaking regexes
Accept multiple values separated by commas or lines while retaining commas inside wrapped expressions and raw regex patterns. Pasting replaces the selected range and keeps rejected values as an explicit draft.
* fix(filters): adapt suggestions to the selected operator
Offer literal prefixes and suffixes for substring operators, escaped anchored patterns for regex, and numeric suggestions only for comparisons. Suggestion syntax must mean what the selected matcher actually reads.
* fix(filters): preserve regex meaning when changing operators
Swap wrapped and raw regex sources only when both compile identically after saving. Leave literal, glob, multiline and Unicode-sensitive comparisons unchanged rather than inventing non-equivalent conversions.
* a11y(filter-editor): label type and operator controls
Associate each fixed select with a stable per-condition label while keeping the compact visual layout unchanged.
* fix(editors): ignore accidental backdrop dismissal
Do not discard unsaved route or group edits when the user clicks outside the dialog. Preserve Escape, Cancel and explicit close, including popovers and confirmation dialogs stacked above the editor.
* feat(dispatch)!: scope stop and fallback to each group
A match in one group must not suppress delivery in another group. Track regular matches and stopped scopes independently, and document the routing-table boundary.
BREAKING CHANGE: stop and fallback no longer apply globally across
groups. Put mutually exclusive routes in the same group and define
fallback routes in each group that needs its own catch-all.
* fix(dispatch): honor stop on a matching fallback route
Once a fallback matches with stop enabled, skip later routes of the same group without affecting other groups. Cover multiple fallback routes in the group-isolation regression test.
* style(console): pin theme and language controls to the right
Separate utility controls from page actions so narrow screens retain a readable title column and right-aligned actions below. Wrap long headings without letting them push controls out of view.
* style(groups): place creation beside the aligned group count
Keep the new-group action inside the group list at every width and align the label and count on one baseline with a consistent type scale.
* style(groups): align card footers and keep role badges intact
Give long names two lines, show the current role in its own non-wrapping row, and anchor every card footer to the grid-row bottom regardless of optional source metadata.
* style(logs): prevent filter labels and metadata overflow
Keep filter labels on one line and allow long channel, thread and repository identifiers to wrap instead of widening the page.
* style(console): scale the sidebar and hide mobile tab tracks
Narrow the sidebar proportionally while retaining enough room for both locales. Keep mobile navigation swipeable without a visible horizontal scrollbar.
* feat(console): give each group its own routes URL
Resolve the selected group from /admin/groups/{groupId}, validate console paths, and use browser history for back navigation. Keep Groups active and let an active mobile-tab tap return to the list. Scope pending route loads to their group and retain the count beside long headings.
* feat(console): confirm leaving unsaved page work
Guard route changes when an editor or changed order draft is open. Cancel superseded questions and restore the shown history entry when repeated Back or Forward navigation is refused; only completed navigation resets page work.
* feat(console): confirm sign-out from desktop and mobile
Expose sign-out in the mobile topbar when the sidebar is hidden. Both entry points use the in-app confirmation before navigating to the server logout endpoint.
* fix(console): keep topbar tools clear of very narrow headings
Below 360px, place the full-width heading beneath the breadcrumb and utility row so the three top-right buttons cannot overlap it.
* feat(console): prioritize group titles over actions
Place New Route after Reorder in the group bar. Measure available space and remove the reorder label first, then the creation label, before truncating the group title; remeasure on resize, locale and font changes.
* fix(editors): focus the dialog without selecting its name field
Cancel the non-bubbling FocusScope mount event in the capture phase and focus the dialog itself. Keep keyboard navigation working without highlighting the name or opening the touch keyboard automatically.
* perf(console): preserve one instance across admin navigation
Use a fixed page key instead of remounting the whole console for each URL. Refresh each view when shown and isolate overview metrics and logs so page filters cannot leak into the dashboard.
* fix(console-data): discard superseded load responses
Only the latest request may update a list, its error or loading state. Invalidate pending group loads after a save so an older response cannot restore stale configuration during persistent-console navigation.
* fix(routes): serialize writes and reject unloaded route lists
Whole-list saves must start from loaded data and wait for other route writes. Lock switches and actions during saves, recheck deletion after confirmation, and rebuild saved ordering from the newest route objects.
* fix(editors): scope async results and fragment writes to sessions
A completed save or dry run must not close or overwrite a newer editor. Keep fragment state scoped by group, reject writes until the real list is ready, and retain in-flight fragment locks across navigation.
* fix(groups): serialize edits and isolate group detail panels
Prevent overlapping whole-list writes, avoid duplicate ids after rename, and discard delete confirmations prepared on a page that has since been left. Key member and webhook panels by group so local state cannot cross tenants.
* fix(console): omit the empty action row outside overview
Render the refresh-action container only where it has content so narrow layouts do not reserve a blank row after creation controls move into their page bars.
* perf(metrics): send all seven queries in one D1 batch
Avoid seven sequential network round trips and read totals, breakdowns and recent failures in one consistent transaction. Reuse the failed-send statement and row mapping while retaining group scoping.
* fix(admin-api): bypass browser cache locks for live requests
Use no-store on both client requests and admin responses. Personalized live data must not be reused, and one stalled same-URL cache entry must not block later log requests behind the browser cache lock.
* docs(routes): Clarify fallback hints and document group-scoped stop and fallback upgrade behavior
1535 lines
48 KiB
Vue
1535 lines
48 KiB
Vue
<template>
|
|
<div class="console-shell">
|
|
<aside class="console-sidebar">
|
|
<NuxtLink class="console-brand" to="/">
|
|
<AppLogo :size="32" />
|
|
<span
|
|
><strong>WebHooker</strong><small>{{ t("app.tagline") }}</small></span
|
|
>
|
|
</NuxtLink>
|
|
<p class="console-nav-label">{{ t("app.tagline") }}</p>
|
|
<nav class="console-nav">
|
|
<button
|
|
v-for="n in nav"
|
|
:key="n.id"
|
|
class="console-nav-item"
|
|
:class="{ active: n.id === activeNav }"
|
|
@click="switchView(n.id)"
|
|
>
|
|
<component :is="navIcon(n.id)" :size="17" :stroke-width="1.8" />
|
|
{{ n.label }}
|
|
</button>
|
|
</nav>
|
|
<div class="console-sidebar-footer">
|
|
<button type="button" @click="signOut"><LogOut :size="16" />{{ t("app.signOut") }}</button>
|
|
</div>
|
|
</aside>
|
|
|
|
<div class="console-main">
|
|
<header class="console-topbar">
|
|
<div class="console-heading">
|
|
<p class="console-kicker">WebHooker / {{ activeNav }}</p>
|
|
<h1 :title="pageTitle">{{ pageTitle }}</h1>
|
|
</div>
|
|
<div class="console-utilities">
|
|
<RcBadge
|
|
v-if="!needLogin && loadingAny"
|
|
variant="soft"
|
|
size="sm"
|
|
dot
|
|
class="console-status"
|
|
>
|
|
{{ t("status.loading") }}
|
|
</RcBadge>
|
|
<ThemeToggle />
|
|
<RcButton variant="ghost" size="sm" @click="toggle"
|
|
><Languages :size="15" class="console-lang-icon" />{{ t("app.langToggle") }}</RcButton
|
|
>
|
|
<!-- The sidebar (with its sign-out) is hidden on narrow screens. -->
|
|
<RcButton
|
|
v-if="!needLogin"
|
|
variant="ghost"
|
|
size="sm"
|
|
class="console-topbar-signout"
|
|
:title="t('app.signOut')"
|
|
:aria-label="t('app.signOut')"
|
|
@click="signOut"
|
|
><LogOut :size="15" /><span class="console-signout-label">{{
|
|
t("app.signOut")
|
|
}}</span></RcButton
|
|
>
|
|
</div>
|
|
<div v-if="view === 'overview'" class="console-actions">
|
|
<RcButton variant="ghost" size="sm" @click="refreshOverview"
|
|
><RefreshCw :size="15" />{{ t("metrics.refresh") }}</RcButton
|
|
>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="console-mobile-nav" @click="onMobileNavClick">
|
|
<RcTabs
|
|
:model-value="activeNav"
|
|
:items="mobileNav"
|
|
@update:model-value="switchView($event as View)"
|
|
/>
|
|
</div>
|
|
|
|
<main class="console-content">
|
|
<div v-if="needLogin" class="console-login">
|
|
<RcCard variant="outline" padding="lg" class="console-login-card">
|
|
<template #header><LockKeyhole :size="24" /></template>
|
|
<h2>{{ t("login.title") }}</h2>
|
|
<p>{{ forbidden ? t("login.forbidden") : t("login.prompt") }}</p>
|
|
<a href="/admin/login"
|
|
><RcButton size="lg"><LogIn :size="17" />{{ t("login.button") }}</RcButton></a
|
|
>
|
|
</RcCard>
|
|
</div>
|
|
|
|
<template v-else>
|
|
<AdminHome
|
|
v-if="view === 'overview'"
|
|
:key="refreshKey"
|
|
:groups="groups"
|
|
:logs="overviewLogs"
|
|
:metrics="overviewMetrics"
|
|
:groups-loading="groupsLoading"
|
|
:logs-loading="overviewLogsLoading"
|
|
:metrics-loading="overviewMetricsLoading"
|
|
/>
|
|
|
|
<template v-else-if="selectedGroup">
|
|
<section
|
|
ref="groupBarEl"
|
|
class="console-context-bar console-group-bar"
|
|
:class="`labels-${barLabels}`"
|
|
>
|
|
<div class="console-group-heading">
|
|
<h2 ref="groupNameEl" :title="selectedGroup.name">{{ selectedGroup.name }}</h2>
|
|
<RcBadge
|
|
:variant="groupRoutesLoading ? 'soft' : 'success'"
|
|
size="sm"
|
|
dot
|
|
class="shrink-0"
|
|
:title="t('group.routeCount', { count: groupRoutes.length })"
|
|
>{{ groupRoutes.length }}</RcBadge
|
|
>
|
|
</div>
|
|
<div class="console-context-actions">
|
|
<template v-if="reordering">
|
|
<RcButton
|
|
variant="outline"
|
|
color="neutral"
|
|
size="sm"
|
|
:disabled="savingOrder"
|
|
@click="cancelReorder"
|
|
>{{ t("routes.reorderCancel") }}</RcButton
|
|
>
|
|
<RcButton
|
|
size="sm"
|
|
:loading="savingOrder"
|
|
:disabled="!orderChanged || reorderBusy"
|
|
@click="saveOrder"
|
|
><Check :size="15" />{{ t("routes.reorderSave") }}</RcButton
|
|
>
|
|
</template>
|
|
<template v-else>
|
|
<RcButton
|
|
v-if="canReorder"
|
|
variant="outline"
|
|
color="neutral"
|
|
size="sm"
|
|
class="console-reorder-btn"
|
|
:disabled="routesBusy"
|
|
:title="t('routes.reorder')"
|
|
:aria-label="t('routes.reorder')"
|
|
@click="startReorder"
|
|
><ArrowUpDown :size="15" /><span class="console-reorder-label">{{
|
|
t("routes.reorder")
|
|
}}</span></RcButton
|
|
>
|
|
<RcButton
|
|
v-if="canCreateRoute"
|
|
size="sm"
|
|
class="console-new-route-btn"
|
|
:disabled="!routesWritable"
|
|
:title="t('app.newRoute')"
|
|
:aria-label="t('app.newRoute')"
|
|
@click="openNew"
|
|
><Plus :size="15" /><span class="console-new-route-label">{{
|
|
t("app.newRoute")
|
|
}}</span></RcButton
|
|
>
|
|
</template>
|
|
</div>
|
|
<p v-if="reordering" class="console-reorder-hint">{{ t("routes.reorderHint") }}</p>
|
|
<!-- Unseen full-width copies of the buttons: how much room their labels need. -->
|
|
<div
|
|
v-if="!reordering"
|
|
ref="barSizerEl"
|
|
class="console-bar-sizer"
|
|
aria-hidden="true"
|
|
inert
|
|
>
|
|
<RcButton
|
|
v-if="canReorder"
|
|
data-size="reorder"
|
|
variant="outline"
|
|
color="neutral"
|
|
size="sm"
|
|
tabindex="-1"
|
|
><ArrowUpDown :size="15" />{{ t("routes.reorder") }}</RcButton
|
|
>
|
|
<RcButton v-if="canCreateRoute" data-size="new" size="sm" tabindex="-1"
|
|
><Plus :size="15" />{{ t("app.newRoute") }}</RcButton
|
|
>
|
|
</div>
|
|
</section>
|
|
|
|
<p v-if="groupRoutesError" class="err">{{ groupRoutesError }}</p>
|
|
|
|
<RouteList
|
|
:routes="reordering ? orderDraft : groupRoutes"
|
|
:reordering="reordering"
|
|
:locked="routesLocked"
|
|
:readonly="!canEditRoutes(selectedGroup.id)"
|
|
@update:routes="orderDraft = $event"
|
|
@update:busy="reorderBusy = $event"
|
|
@toggle="onToggle"
|
|
@edit="openEdit"
|
|
@delete="onDelete"
|
|
/>
|
|
|
|
<section v-if="groupRoutesReady && !groupRoutes.length" class="console-empty">
|
|
<RcEmptyState :title="t('routes.emptyGroup')">
|
|
<RcButton v-if="canCreateRoute" :disabled="!routesWritable" @click="openNew"
|
|
><Plus :size="16" />{{ t("routes.createFirst") }}</RcButton
|
|
>
|
|
</RcEmptyState>
|
|
</section>
|
|
|
|
<MembersPanel
|
|
:key="selectedGroup.id"
|
|
:group="selectedGroup"
|
|
:can-edit="canEditGroup(selectedGroup.id)"
|
|
:saving="savingGroup"
|
|
@save="onSaveGroupFromPanel"
|
|
/>
|
|
|
|
<WebhookPanel
|
|
v-if="canEditGroup(selectedGroup.id)"
|
|
:key="selectedGroup.id"
|
|
:group-id="selectedGroup.id"
|
|
:can-edit="canEditGroup(selectedGroup.id)"
|
|
/>
|
|
</template>
|
|
|
|
<section v-else-if="groupMissing" class="console-empty">
|
|
<RcEmptyState :title="t('group.notFound')">
|
|
<NuxtLink to="/admin/groups"
|
|
><RcButton variant="outline" color="neutral">{{
|
|
t("group.allGroups")
|
|
}}</RcButton></NuxtLink
|
|
>
|
|
</RcEmptyState>
|
|
</section>
|
|
|
|
<section v-else-if="routeGroupId" class="console-context-bar">
|
|
<p v-if="groupsError" class="err">{{ groupsError }}</p>
|
|
<RcBadge v-else variant="soft" size="sm" dot>{{ t("status.loading") }}</RcBadge>
|
|
</section>
|
|
|
|
<template v-else-if="view === 'groups'">
|
|
<section class="console-context-bar">
|
|
<div class="console-count">
|
|
<p>{{ t("tab.groups") }}</p>
|
|
<strong>{{ groups.length }}</strong>
|
|
</div>
|
|
<div class="console-context-actions">
|
|
<RcBadge v-if="groupsLoading" variant="soft" size="sm" dot>{{
|
|
t("status.loading")
|
|
}}</RcBadge>
|
|
<RcButton
|
|
v-if="canCreateGroup"
|
|
size="sm"
|
|
:disabled="savingGroup"
|
|
@click="openNewGroup"
|
|
><Plus :size="15" />{{ t("app.newGroup") }}</RcButton
|
|
>
|
|
</div>
|
|
</section>
|
|
|
|
<p v-if="groupsError" class="err">{{ groupsError }}</p>
|
|
|
|
<section class="grid grid-cols-1 gap-3.5 sm:grid-cols-2 lg:grid-cols-3">
|
|
<RcCard
|
|
v-for="(g, i) in groups"
|
|
:key="g.id"
|
|
variant="outline"
|
|
:hoverable="true"
|
|
padding="none"
|
|
class="console-group-card transition-all hover:border-border-strong hover:shadow-xs"
|
|
:style="{ animationDelay: i * 35 + 'ms' }"
|
|
@click="enterGroup(g)"
|
|
>
|
|
<div class="flex flex-1 flex-col gap-3 p-4">
|
|
<div class="flex items-start justify-between gap-2.5">
|
|
<div class="min-w-0 flex-1">
|
|
<div
|
|
class="line-clamp-2 text-[15px] leading-snug font-semibold text-text [overflow-wrap:anywhere]"
|
|
:title="g.name || t('route.untitled')"
|
|
>
|
|
{{ g.name || t("route.untitled") }}
|
|
</div>
|
|
<div class="mt-0.5 font-mono text-[11px] text-faint truncate" :title="g.id">
|
|
{{ g.id }}
|
|
</div>
|
|
</div>
|
|
<div
|
|
v-if="canEditGroup(g.id)"
|
|
class="flex shrink-0 items-center gap-1"
|
|
@click.stop
|
|
>
|
|
<RcButton
|
|
variant="ghost"
|
|
size="icon"
|
|
class="h-7 w-7 text-muted hover:text-text"
|
|
:disabled="savingGroup"
|
|
:title="t('groupEditor.editTitle')"
|
|
@click="openEditGroup(g)"
|
|
>
|
|
<Pencil :size="13.5" />
|
|
</RcButton>
|
|
<RcButton
|
|
variant="ghost"
|
|
color="error"
|
|
size="icon"
|
|
class="h-7 w-7 text-muted hover:text-bad"
|
|
:disabled="savingGroup"
|
|
:title="t('groups.delete')"
|
|
:aria-label="t('groups.delete')"
|
|
@click="onDeleteGroup(g)"
|
|
>
|
|
<Trash2 :size="13.5" />
|
|
</RcButton>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="space-y-1.5 text-xs">
|
|
<div
|
|
v-if="roleOf(g.id)"
|
|
class="flex items-center justify-between text-[11.5px]"
|
|
>
|
|
<span class="text-faint font-semibold">{{ t("groups.myRole") }}</span>
|
|
<RcBadge variant="brand" size="xs" class="whitespace-nowrap">
|
|
{{ t("roles." + roleOf(g.id)) }}
|
|
</RcBadge>
|
|
</div>
|
|
<div class="flex items-center justify-between text-[11.5px]">
|
|
<span class="text-faint font-semibold">{{ t("groups.members") }}</span>
|
|
<span class="rounded bg-surface-2 px-1.5 py-0.5 font-mono text-text">
|
|
{{ (g.members ?? []).length || (g.adminIds || []).length || 0 }}
|
|
</span>
|
|
</div>
|
|
<div
|
|
v-if="g.owners?.length"
|
|
class="flex items-center justify-between text-[11.5px]"
|
|
>
|
|
<span class="text-faint font-semibold">{{ t("groups.owners") }}</span>
|
|
<span
|
|
class="truncate max-w-[170px] text-muted text-right font-mono text-[11px]"
|
|
>
|
|
{{ g.owners.join(", ") }}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
class="mt-auto flex items-center justify-between pt-2 border-t border-border/70 text-xs"
|
|
>
|
|
<span class="text-faint text-[11px]">{{ t("overview.routes") }}</span>
|
|
<NuxtLink
|
|
:to="groupPath(g.id)"
|
|
class="inline-flex items-center gap-1 font-semibold text-accent hover:underline"
|
|
@click.stop
|
|
>
|
|
{{ t("groups.open") }}
|
|
<ArrowRight :size="12" />
|
|
</NuxtLink>
|
|
</div>
|
|
</div>
|
|
</RcCard>
|
|
</section>
|
|
|
|
<section v-if="!groupsLoading && !groups.length" class="console-empty">
|
|
<RcEmptyState :title="t('groups.empty')"
|
|
><RcButton v-if="isSuper" :disabled="savingGroup" @click="openNewGroup"
|
|
><Plus :size="16" />{{ t("groups.createFirst") }}</RcButton
|
|
></RcEmptyState
|
|
>
|
|
</section>
|
|
</template>
|
|
|
|
<template v-else-if="view === 'logs'">
|
|
<section v-if="logsLoading" class="console-context-bar">
|
|
<RcBadge variant="soft" size="sm" dot>{{ t("status.loading") }}</RcBadge>
|
|
</section>
|
|
<SendLogs
|
|
:logs="logs"
|
|
:loading="logsLoading"
|
|
:error="logsError"
|
|
:groups="groups"
|
|
:selected-group-id="logFilterGroup"
|
|
@refresh="loadLogs(50, logFilterGroup || undefined)"
|
|
@filter="loadLogs(50, logFilterGroup || undefined)"
|
|
@update:selected-group-id="logFilterGroup = $event"
|
|
/>
|
|
</template>
|
|
|
|
<template v-else-if="view === 'audit'">
|
|
<AuditLog
|
|
:entries="auditEntries"
|
|
:loading="auditLoading"
|
|
:error="auditError"
|
|
:groups="groups"
|
|
:selected-group-id="auditFilterGroup"
|
|
@refresh="loadAudit(50, auditFilterGroup || undefined)"
|
|
@filter="loadAudit(50, auditFilterGroup || undefined)"
|
|
@update:selected-group-id="auditFilterGroup = $event"
|
|
/>
|
|
</template>
|
|
|
|
<template v-else-if="view === 'metrics'">
|
|
<MetricsPanel
|
|
:metrics="metrics"
|
|
:loading="metricsLoading"
|
|
:error="metricsError"
|
|
:groups="groups"
|
|
:selected-group-id="metricsFilterGroup"
|
|
@refresh="loadMetrics(metricsFilterGroup || undefined)"
|
|
@filter="loadMetrics(metricsFilterGroup || undefined)"
|
|
@update:selected-group-id="metricsFilterGroup = $event"
|
|
/>
|
|
</template>
|
|
</template>
|
|
</main>
|
|
</div>
|
|
|
|
<!-- One editor for every group (not keyed): its fragment store, scoped
|
|
per group, keeps a pending fragment write's lock across navigation. -->
|
|
<RouteEditor
|
|
:open="editorOpen"
|
|
:route="editing"
|
|
:saving="routesLocked"
|
|
:group-id="selectedGroup?.id ?? null"
|
|
@close="editorOpen = false"
|
|
@save="onSave"
|
|
/>
|
|
|
|
<GroupEditor
|
|
:open="groupEditorOpen"
|
|
:group="editingGroup"
|
|
:saving="savingGroup"
|
|
:super-admin="isSuper"
|
|
@close="groupEditorOpen = false"
|
|
@save="onSaveGroup"
|
|
/>
|
|
|
|
<ConfirmDialog />
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import {
|
|
Activity,
|
|
ArrowRight,
|
|
ArrowUpDown,
|
|
Check,
|
|
ClipboardList,
|
|
Gauge,
|
|
Languages,
|
|
Layers3,
|
|
LockKeyhole,
|
|
LogIn,
|
|
LogOut,
|
|
Pencil,
|
|
Plus,
|
|
RefreshCw,
|
|
ShieldCheck,
|
|
Trash2,
|
|
} from "lucide-vue-next";
|
|
import type { Group, Route } from "~/types";
|
|
import type { AdminView } from "~/utils/admin-path";
|
|
import { adminGroupPath, parseAdminPath } from "~/utils/admin-path";
|
|
import { useAuditApi } from "~/composables/useAudit";
|
|
import WebhookPanel from "~/components/WebhookPanel.vue";
|
|
import AdminHome from "~/components/AdminHome.vue";
|
|
|
|
const { t, toggle, locale } = useI18n();
|
|
const { push } = useToasts();
|
|
const { confirm, settle: dismissConfirm } = useConfirm();
|
|
const route = useRoute();
|
|
const router = useRouter();
|
|
|
|
/**
|
|
* The console view mirrors the URL path so navigation is deep-linkable:
|
|
* /admin (overview) · /admin/groups · /admin/groups/{groupId} (a group's
|
|
* routes) · /admin/logs · /admin/audit · /admin/metrics. The page validates
|
|
* the path, so unknown slugs 404 before the console renders.
|
|
*/
|
|
type View = AdminView;
|
|
const adminPath = computed(() => parseAdminPath(route.params.slug));
|
|
const view = computed<View | null>(() => adminPath.value?.view ?? null);
|
|
/** Group whose routes page the URL opens (/admin/groups/{groupId}). */
|
|
const routeGroupId = computed(() => adminPath.value?.groupId ?? null);
|
|
const groupPath = adminGroupPath;
|
|
|
|
const nav = computed(() => [
|
|
{ id: "overview" as View, label: t("tab.overview"), path: "/admin" },
|
|
{ id: "groups" as View, label: t("tab.groups"), path: "/admin/groups" },
|
|
{ id: "logs" as View, label: t("tab.logs"), path: "/admin/logs" },
|
|
{ id: "audit" as View, label: t("tab.audit"), path: "/admin/audit" },
|
|
{ id: "metrics" as View, label: t("tab.metrics"), path: "/admin/metrics" },
|
|
]);
|
|
|
|
const mobileNav = computed(() =>
|
|
nav.value.map(({ id, label }) => ({ value: id, label, icon: navIcon(id) })),
|
|
);
|
|
|
|
function navIcon(id: View) {
|
|
const icons = {
|
|
overview: Gauge,
|
|
groups: Layers3,
|
|
logs: Activity,
|
|
audit: ClipboardList,
|
|
metrics: ShieldCheck,
|
|
} satisfies Record<View, typeof Gauge>;
|
|
return icons[id];
|
|
}
|
|
|
|
const activeNav = computed<View>(() => view.value ?? "overview");
|
|
|
|
const pageTitle = computed(() => {
|
|
if (selectedGroup.value) return t("group.routesIn", { name: selectedGroup.value.name });
|
|
if (routeGroupId.value) return t("tab.groups");
|
|
switch (view.value) {
|
|
case "overview":
|
|
return t("tab.overview");
|
|
case "groups":
|
|
return t("tab.groups");
|
|
case "logs":
|
|
return t("tab.logs");
|
|
case "audit":
|
|
return t("tab.audit");
|
|
case "metrics":
|
|
return t("tab.metrics");
|
|
default:
|
|
return "";
|
|
}
|
|
});
|
|
|
|
const loadingAny = computed(
|
|
() =>
|
|
groupsLoading.value ||
|
|
logsLoading.value ||
|
|
metricsLoading.value ||
|
|
overviewLogsLoading.value ||
|
|
overviewMetricsLoading.value ||
|
|
groupRoutesLoading.value ||
|
|
auditLoading.value,
|
|
);
|
|
|
|
const { logs, loading: logsLoading, error: logsError, load: loadLogs } = useSendLogs();
|
|
// Overview shows every group's latest sends and totals, apart from the Send
|
|
// Logs and Stats pages and their group filters (the console stays mounted, so
|
|
// shared state would carry one page's filter into the other).
|
|
const { logs: overviewLogs, loading: overviewLogsLoading, load: loadOverviewLogs } = useSendLogs();
|
|
const {
|
|
metrics: overviewMetrics,
|
|
loading: overviewMetricsLoading,
|
|
load: loadOverviewMetrics,
|
|
} = useMetrics();
|
|
const {
|
|
entries: auditEntries,
|
|
loading: auditLoading,
|
|
error: auditError,
|
|
load: loadAudit,
|
|
} = useAuditApi();
|
|
const { metrics, loading: metricsLoading, error: metricsError, load: loadMetrics } = useMetrics();
|
|
const {
|
|
groups,
|
|
isSuper,
|
|
roles,
|
|
roleOf,
|
|
canEditGroup,
|
|
canEditRoutes,
|
|
loading: groupsLoading,
|
|
loaded: groupsLoaded,
|
|
needLogin,
|
|
error: groupsError,
|
|
load: loadGroups,
|
|
save: saveGroups,
|
|
rename: groupsRename,
|
|
} = useGroupsApi();
|
|
const {
|
|
routes: groupRoutes,
|
|
loading: groupRoutesLoading,
|
|
error: groupRoutesError,
|
|
load: loadGroupRoutes,
|
|
clear: clearGroupRoutes,
|
|
ready: groupRoutesReady,
|
|
save: saveGroupRoutes,
|
|
} = useGroupRoutesApi();
|
|
|
|
const editorOpen = ref(false);
|
|
const editing = ref<Route | null>(null);
|
|
const saving = ref(false);
|
|
const forbidden = ref(false);
|
|
/** The group the URL opens, once the group list knows it. */
|
|
const selectedGroup = computed<Group | null>(() =>
|
|
routeGroupId.value ? (groups.value.find((g) => g.id === routeGroupId.value) ?? null) : null,
|
|
);
|
|
/** The URL names a group the signed-in user cannot see (or that does not exist). */
|
|
const groupMissing = computed(
|
|
() => !!routeGroupId.value && groupsLoaded.value && !groupsError.value && !selectedGroup.value,
|
|
);
|
|
|
|
const groupEditorOpen = ref(false);
|
|
const editingGroup = ref<Group | null>(null);
|
|
const savingGroup = ref(false);
|
|
|
|
/** Reorder mode: the draft order the user drags until it is saved or cancelled. */
|
|
const reordering = ref(false);
|
|
const orderDraft = ref<Route[]>([]);
|
|
const savingOrder = ref(false);
|
|
/** Route saves (toggle/delete) still in flight; reordering waits for them. */
|
|
const routeMutations = ref(0);
|
|
const routesBusy = computed(
|
|
() => groupRoutesLoading.value || saving.value || routeMutations.value > 0,
|
|
);
|
|
/** Route controls wait while the routes load or a write is in flight. */
|
|
const routesLocked = computed(() => routesBusy.value || savingOrder.value);
|
|
/**
|
|
* A route write may start: the group's routes are loaded (a save replaces the
|
|
* whole list, so writing from a still-empty or failed list would wipe it)
|
|
* and no other load or write is running.
|
|
*/
|
|
const routesWritable = computed(() => groupRoutesReady.value && !routesLocked.value);
|
|
|
|
/** Refuse a route write the page is not ready for; true when it may go ahead. */
|
|
function canWriteRoutes(): boolean {
|
|
if (routesWritable.value) return true;
|
|
push(t("toast.routesNotReady"), "bad");
|
|
return false;
|
|
}
|
|
|
|
// Bumped whenever an editor opens: a save may only close the editor it was
|
|
// made from, never one opened since (on another page, for another route).
|
|
let routeEditorSession = 0;
|
|
let groupEditorSession = 0;
|
|
/** A dropped card is still settling; its new position is not in the draft yet. */
|
|
const reorderBusy = ref(false);
|
|
const orderChanged = computed(
|
|
() =>
|
|
orderDraft.value.length !== groupRoutes.value.length ||
|
|
orderDraft.value.some((r, i) => r.id !== groupRoutes.value[i]?.id),
|
|
);
|
|
|
|
const canCreateRoute = computed(
|
|
() =>
|
|
!needLogin.value &&
|
|
!!selectedGroup.value &&
|
|
canEditRoutes(selectedGroup.value.id) &&
|
|
!reordering.value,
|
|
);
|
|
const canReorder = computed(
|
|
() =>
|
|
!!selectedGroup.value && canEditRoutes(selectedGroup.value.id) && groupRoutes.value.length > 1,
|
|
);
|
|
/**
|
|
* Labels of the group bar's buttons, given up so the group name stays whole:
|
|
* first Reorder turns into an icon, then New route; only with both on icons
|
|
* may a long name be cut short.
|
|
*/
|
|
const barLabels = ref<"all" | "new" | "none">("all");
|
|
const groupBarEl = ref<HTMLElement | null>(null);
|
|
const groupNameEl = ref<HTMLElement | null>(null);
|
|
const barSizerEl = ref<HTMLElement | null>(null);
|
|
|
|
function fitBarLabels(): void {
|
|
const bar = groupBarEl.value;
|
|
const name = groupNameEl.value;
|
|
const sizer = barSizerEl.value;
|
|
if (!bar || !name || !sizer) return;
|
|
// Fractional widths throughout: a rounded pixel decides whether a name fits.
|
|
const px = (value: string): number => parseFloat(value) || 0;
|
|
const gap = (el: Element | null): number => (el ? px(getComputedStyle(el).columnGap) : 0);
|
|
const width = (el: Element | Range | null | undefined): number =>
|
|
el?.getBoundingClientRect().width ?? 0;
|
|
const barStyle = getComputedStyle(bar);
|
|
const room =
|
|
width(bar) -
|
|
px(barStyle.paddingLeft) -
|
|
px(barStyle.paddingRight) -
|
|
px(barStyle.borderLeftWidth) -
|
|
px(barStyle.borderRightWidth) -
|
|
1;
|
|
// The whole name (its text, not the ellipsis box) plus the count after it.
|
|
const text = document.createRange();
|
|
text.selectNodeContents(name);
|
|
const count = name.nextElementSibling;
|
|
const heading = width(text) + (count ? gap(name.parentElement) + width(count) : 0);
|
|
const full = (key: string): number => width(sizer.querySelector(`[data-size="${key}"]`));
|
|
// An icon-only button is a 2rem square (see `.labels-*` below).
|
|
const icon = 2 * px(getComputedStyle(document.documentElement).fontSize);
|
|
const reorder = full("reorder");
|
|
const create = full("new");
|
|
const actionsGap = gap(bar.querySelector(".console-context-actions"));
|
|
const fits = (widths: number[]): boolean => {
|
|
const shown = widths.filter((w) => w > 0);
|
|
const actions = shown.reduce((sum, w) => sum + w, 0) + (shown.length - 1) * actionsGap;
|
|
return heading + px(barStyle.columnGap) + actions <= room;
|
|
};
|
|
if (fits([reorder, create])) barLabels.value = "all";
|
|
else if (fits([reorder && icon, create])) barLabels.value = "new";
|
|
else barLabels.value = "none";
|
|
}
|
|
|
|
let barObserver: ResizeObserver | undefined;
|
|
watch(groupBarEl, (bar) => {
|
|
barObserver?.disconnect();
|
|
if (!bar || typeof ResizeObserver === "undefined") return;
|
|
barObserver = new ResizeObserver(() => fitBarLabels());
|
|
barObserver.observe(bar);
|
|
});
|
|
watch(
|
|
() => [
|
|
selectedGroup.value?.name,
|
|
groupRoutes.value.length,
|
|
locale.value,
|
|
canReorder.value,
|
|
canCreateRoute.value,
|
|
reordering.value,
|
|
],
|
|
() => nextTick(fitBarLabels),
|
|
);
|
|
onMounted(() => document.fonts?.ready.then(fitBarLabels));
|
|
onBeforeUnmount(() => barObserver?.disconnect());
|
|
|
|
const canCreateGroup = computed(
|
|
() => !needLogin.value && !routeGroupId.value && view.value === "groups" && isSuper.value,
|
|
);
|
|
|
|
const logFilterGroup = ref("");
|
|
const auditFilterGroup = ref("");
|
|
const metricsFilterGroup = ref("");
|
|
const refreshKey = ref(0);
|
|
|
|
onMounted(() => {
|
|
if (typeof window !== "undefined") {
|
|
const params = new URLSearchParams(window.location.search);
|
|
forbidden.value = params.get("error") === "forbidden";
|
|
const invite = params.get("invite");
|
|
if (invite === "ok") push(t("members.inviteOk"));
|
|
else if (invite != null && invite !== "ok") push(t("members.inviteBad"), "bad");
|
|
if (params.get("install") === "ok") push(t("install.ok"));
|
|
}
|
|
loadGroups();
|
|
});
|
|
|
|
// The console stays mounted across its pages (the admin page has a fixed
|
|
// key), so a page refreshes what it shows whenever it becomes active —
|
|
// direct deep links included.
|
|
watch(
|
|
view,
|
|
(v, previous) => {
|
|
if (v === "overview") {
|
|
loadOverviewLogs(50);
|
|
loadOverviewMetrics();
|
|
}
|
|
if (v === "logs") loadLogs(50, logFilterGroup.value || undefined);
|
|
if (v === "audit") loadAudit(50, auditFilterGroup.value || undefined);
|
|
if (v === "metrics") loadMetrics(metricsFilterGroup.value || undefined);
|
|
// The first load runs on mount; later visits pick up changes made since.
|
|
if (previous && (v === "overview" || v === "groups")) loadGroups();
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
|
|
// Every page is a history entry: the browser's (or device's) back button
|
|
// returns from a group's routes to the group list.
|
|
function switchView(next: View): void {
|
|
const path = next === "overview" ? "/admin" : `/admin/${next}`;
|
|
if (route.path !== path) router.push(path);
|
|
}
|
|
|
|
/**
|
|
* The active mobile tab emits no change, so a tap on "Groups" while a group's
|
|
* routes are open leads back to the list here (the sidebar link does so itself).
|
|
*/
|
|
function onMobileNavClick(event: MouseEvent): void {
|
|
const tab = event.target instanceof Element ? event.target.closest('[role="tab"]') : null;
|
|
if (tab?.getAttribute("aria-selected") === "true" && routeGroupId.value) switchView("groups");
|
|
}
|
|
|
|
/** Work on the current page that leaving it would throw away. */
|
|
function hasUnsavedWork(): boolean {
|
|
return editorOpen.value || groupEditorOpen.value || (reordering.value && orderChanged.value);
|
|
}
|
|
|
|
/** Counts navigations reaching the guards; a newer one supersedes the question. */
|
|
let navigationAttempt = 0;
|
|
|
|
/** Ask before a navigation throws work away; the page resets once it happened. */
|
|
async function confirmLeave(): Promise<boolean> {
|
|
if (!hasUnsavedWork()) return true;
|
|
const attempt = navigationAttempt;
|
|
const leave = await confirm({
|
|
title: t("confirm.leaveUnsaved"),
|
|
description: t("confirm.leaveUnsavedDesc"),
|
|
confirmText: t("confirm.leave"),
|
|
kind: "leave",
|
|
});
|
|
// Superseded while asking: let the router cancel this navigation itself.
|
|
// Refusing it would read as "stay" and step the browser history back again,
|
|
// on top of the newer navigation that already moved it.
|
|
if (attempt !== navigationAttempt) return true;
|
|
// Staying after Back/Forward: the browser has already moved. The router
|
|
// steps back its own move; earlier, superseded moves are undone after it.
|
|
if (!leave && historyPosition() !== shownPosition) {
|
|
window.addEventListener("popstate", restoreShownEntry, { once: true });
|
|
}
|
|
return leave;
|
|
}
|
|
|
|
/** vue-router's position (in `history.state`) of the current history entry. */
|
|
function historyPosition(): number | null {
|
|
const position = (window.history.state as { position?: unknown } | null)?.position;
|
|
return typeof position === "number" ? position : null;
|
|
}
|
|
|
|
/** History position of the page on screen, as of the last completed navigation. */
|
|
let shownPosition = typeof window === "undefined" ? null : historyPosition();
|
|
const stopTrackingPosition = router.afterEach((_to, _from, failure) => {
|
|
if (!failure) shownPosition = historyPosition();
|
|
});
|
|
onBeforeUnmount(stopTrackingPosition);
|
|
|
|
/** Move the browser back to the entry on screen without starting a navigation. */
|
|
function restoreShownEntry(): void {
|
|
const position = historyPosition();
|
|
if (position !== null && shownPosition !== null && position !== shownPosition) {
|
|
router.options.history.go(shownPosition - position, false);
|
|
}
|
|
}
|
|
|
|
async function signOut(): Promise<void> {
|
|
const confirmed = await confirm({
|
|
title: t("confirm.signOut"),
|
|
confirmText: t("app.signOut"),
|
|
kind: "signOut",
|
|
});
|
|
// A full page load: the server clears the session and redirects.
|
|
if (confirmed) window.location.assign("/admin/logout");
|
|
}
|
|
|
|
// A newer navigation supersedes one still waiting for an answer: that
|
|
// question (like any other confirmation of this page) is cancelled first.
|
|
function supersedePending(): void {
|
|
navigationAttempt++;
|
|
dismissConfirm(false);
|
|
}
|
|
|
|
onBeforeRouteUpdate((to, from) => {
|
|
supersedePending();
|
|
return to.path === from.path || confirmLeave();
|
|
});
|
|
onBeforeRouteLeave(() => {
|
|
supersedePending();
|
|
return confirmLeave();
|
|
});
|
|
|
|
/** Bumped by every page change: work begun on one page must not act on the next. */
|
|
let pageVisit = 0;
|
|
|
|
// Only a navigation that actually happened resets the page it left: its
|
|
// editors, a reorder draft and any confirmation still open.
|
|
watch(
|
|
() => route.path,
|
|
() => {
|
|
pageVisit++;
|
|
dismissConfirm(false);
|
|
editorOpen.value = false;
|
|
groupEditorOpen.value = false;
|
|
cancelReorder();
|
|
},
|
|
);
|
|
|
|
async function refreshOverview(): Promise<void> {
|
|
refreshKey.value++;
|
|
await Promise.all([loadGroups(), loadOverviewLogs(50), loadOverviewMetrics()]);
|
|
push(t("overview.refreshed"));
|
|
}
|
|
|
|
function enterGroup(group: Group): void {
|
|
router.push(groupPath(group.id));
|
|
}
|
|
|
|
// The URL decides which group's routes are shown — on a deep link, a click
|
|
// on a group, or the browser's back/forward buttons alike.
|
|
watch(
|
|
routeGroupId,
|
|
(id, previous) => {
|
|
cancelReorder();
|
|
if (id) loadGroupRoutes(id);
|
|
else clearGroupRoutes();
|
|
// Back on the list: members or sources may have changed meanwhile.
|
|
if (!id && previous && view.value === "groups") loadGroups();
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
|
|
function startReorder(): void {
|
|
if (!routesWritable.value) return;
|
|
orderDraft.value = [...groupRoutes.value];
|
|
reorderBusy.value = false;
|
|
reordering.value = true;
|
|
}
|
|
|
|
function cancelReorder(): void {
|
|
reordering.value = false;
|
|
reorderBusy.value = false;
|
|
orderDraft.value = [];
|
|
}
|
|
|
|
async function saveOrder(): Promise<void> {
|
|
const group = selectedGroup.value;
|
|
if (!group || !orderChanged.value || reorderBusy.value || savingOrder.value) return;
|
|
if (!groupRoutesReady.value || routesBusy.value) {
|
|
push(t("toast.routesNotReady"), "bad");
|
|
return;
|
|
}
|
|
savingOrder.value = true;
|
|
try {
|
|
// Persist the latest copy of each route in the draft order, so the save
|
|
// can never resurrect or roll back a route changed since reordering began.
|
|
const latest = new Map(groupRoutes.value.map((r) => [r.id, r]));
|
|
const ordered = orderDraft.value.flatMap((r) => latest.get(r.id) ?? []);
|
|
const added = groupRoutes.value.filter((r) => !orderDraft.value.some((d) => d.id === r.id));
|
|
await saveGroupRoutes(group.id, [...ordered, ...added]);
|
|
cancelReorder();
|
|
push(t("toast.orderSaved"));
|
|
} catch (err) {
|
|
push(t("toast.saveFailed", { msg: err instanceof Error ? err.message : String(err) }), "bad");
|
|
} finally {
|
|
savingOrder.value = false;
|
|
}
|
|
}
|
|
|
|
function onReorderKey(event: KeyboardEvent): void {
|
|
if (event.key !== "Escape" || savingOrder.value || event.defaultPrevented) return;
|
|
// Escape closes an open dialog or list first (e.g. a member-removal
|
|
// confirmation); it must not also throw away the unsaved order.
|
|
const target = event.target instanceof Element ? event.target : null;
|
|
if (
|
|
target?.closest('[role="dialog"], [role="alertdialog"], [role="listbox"], [role="menu"]') ||
|
|
document.querySelector('[role="dialog"], [role="alertdialog"]')
|
|
)
|
|
return;
|
|
cancelReorder();
|
|
}
|
|
|
|
watch(reordering, (on) => {
|
|
if (on) window.addEventListener("keydown", onReorderKey);
|
|
else window.removeEventListener("keydown", onReorderKey);
|
|
});
|
|
|
|
onBeforeUnmount(() => window.removeEventListener("keydown", onReorderKey));
|
|
|
|
function openNew(): void {
|
|
routeEditorSession++;
|
|
editing.value = null;
|
|
editorOpen.value = true;
|
|
}
|
|
|
|
function openEdit(route: Route): void {
|
|
routeEditorSession++;
|
|
editing.value = route;
|
|
editorOpen.value = true;
|
|
}
|
|
|
|
async function onSave(route: Route): Promise<void> {
|
|
const group = selectedGroup.value;
|
|
if (!group || !canWriteRoutes()) return;
|
|
const session = routeEditorSession;
|
|
saving.value = true;
|
|
try {
|
|
let next: Route[];
|
|
if (editing.value) {
|
|
next = groupRoutes.value.map((r) => (r.id === editing.value!.id ? route : r));
|
|
} else {
|
|
if (groupRoutes.value.some((r) => r.id === route.id)) {
|
|
push(t("toast.routeIdExists"), "bad");
|
|
return;
|
|
}
|
|
next = [...groupRoutes.value, route];
|
|
}
|
|
await saveGroupRoutes(group.id, next);
|
|
if (session === routeEditorSession) editorOpen.value = false;
|
|
push(t("toast.routesSaved"));
|
|
} catch (err) {
|
|
push(t("toast.saveFailed", { msg: err instanceof Error ? err.message : String(err) }), "bad");
|
|
} finally {
|
|
saving.value = false;
|
|
}
|
|
}
|
|
|
|
async function onToggle(route: Route): Promise<void> {
|
|
const group = selectedGroup.value;
|
|
if (!group || !canWriteRoutes()) return;
|
|
routeMutations.value++;
|
|
try {
|
|
await saveGroupRoutes(
|
|
group.id,
|
|
groupRoutes.value.map((r) => (r.id === route.id ? route : r)),
|
|
);
|
|
} catch (err) {
|
|
push(t("toast.saveFailed", { msg: err instanceof Error ? err.message : String(err) }), "bad");
|
|
// Restore the switch from the server, unless another group is open by now.
|
|
if (routeGroupId.value === group.id) loadGroupRoutes(group.id);
|
|
} finally {
|
|
routeMutations.value--;
|
|
}
|
|
}
|
|
|
|
async function onDelete(route: Route): Promise<void> {
|
|
const group = selectedGroup.value;
|
|
if (!group || !canWriteRoutes()) return;
|
|
if (!(await confirm({ title: t("confirm.deleteRoute", { name: route.name || route.id }) })))
|
|
return;
|
|
// The page may have changed while the question was open.
|
|
if (selectedGroup.value?.id !== group.id || !canWriteRoutes()) return;
|
|
routeMutations.value++;
|
|
try {
|
|
await saveGroupRoutes(
|
|
group.id,
|
|
groupRoutes.value.filter((r) => r.id !== route.id),
|
|
);
|
|
push(t("toast.routeDeleted"));
|
|
} catch (err) {
|
|
push(t("toast.deleteFailed", { msg: err instanceof Error ? err.message : String(err) }), "bad");
|
|
} finally {
|
|
routeMutations.value--;
|
|
}
|
|
}
|
|
|
|
function openNewGroup(): void {
|
|
groupEditorSession++;
|
|
editingGroup.value = null;
|
|
groupEditorOpen.value = true;
|
|
}
|
|
|
|
function openEditGroup(group: Group): void {
|
|
groupEditorSession++;
|
|
editingGroup.value = group;
|
|
groupEditorOpen.value = true;
|
|
}
|
|
|
|
/**
|
|
* Group writes replace the whole group list, so they run one at a time, each
|
|
* built from the list the previous one saved; true when one may start.
|
|
*/
|
|
function canWriteGroups(): boolean {
|
|
if (!savingGroup.value) return true;
|
|
push(t("toast.groupsBusy"), "bad");
|
|
return false;
|
|
}
|
|
|
|
async function onSaveGroupFromPanel(group: Group): Promise<void> {
|
|
if (!canWriteGroups()) return;
|
|
savingGroup.value = true;
|
|
try {
|
|
const next = groups.value.map((g) => (g.id === group.id ? group : g));
|
|
await saveGroups(next);
|
|
push(t("toast.groupSaved"));
|
|
} catch (err) {
|
|
push(t("toast.saveFailed", { msg: err instanceof Error ? err.message : String(err) }), "bad");
|
|
loadGroups();
|
|
} finally {
|
|
savingGroup.value = false;
|
|
}
|
|
}
|
|
|
|
async function onSaveGroup(group: Group): Promise<void> {
|
|
if (!canWriteGroups()) return;
|
|
const session = groupEditorSession;
|
|
savingGroup.value = true;
|
|
try {
|
|
const editing = editingGroup.value;
|
|
let next: Group[];
|
|
if (editing) {
|
|
if (group.id !== editing.id) {
|
|
// Id changed: rename first so routes/webhook secret/invites follow,
|
|
// then persist the remaining edits under the new id.
|
|
await groupsRename(editing.id, group.id);
|
|
// A list loaded meanwhile may already hold the new id as well.
|
|
next = [...groups.value.filter((g) => g.id !== editing.id && g.id !== group.id), group];
|
|
} else {
|
|
next = groups.value.map((g) => (g.id === editing.id ? group : g));
|
|
}
|
|
} else {
|
|
if (groups.value.some((g) => g.id === group.id)) {
|
|
push(t("toast.groupIdExists"), "bad");
|
|
return;
|
|
}
|
|
next = [...groups.value, group];
|
|
}
|
|
await saveGroups(next);
|
|
if (session === groupEditorSession) groupEditorOpen.value = false;
|
|
push(t("toast.groupSaved"));
|
|
await loadGroups();
|
|
} catch (err) {
|
|
push(t("toast.saveFailed", { msg: err instanceof Error ? err.message : String(err) }), "bad");
|
|
} finally {
|
|
savingGroup.value = false;
|
|
}
|
|
}
|
|
|
|
async function onDeleteGroup(group: Group): Promise<void> {
|
|
if (!canWriteGroups()) return;
|
|
const visit = pageVisit;
|
|
// Fetch the real route count for this group instead of relying on the
|
|
// routes of whichever group happens to be open in the detail view.
|
|
let used = 0;
|
|
try {
|
|
const data = await apiFetch<{ routes?: Route[] }>(
|
|
`/admin/api/groups/${encodeURIComponent(group.id)}/routes`,
|
|
);
|
|
used = (data.routes ?? []).length;
|
|
} catch {
|
|
// Count is best-effort; proceed without the warning.
|
|
}
|
|
// The list was left while the count loaded: never ask on another page.
|
|
if (visit !== pageVisit) return;
|
|
const confirmed = await confirm({
|
|
title: t("confirm.deleteGroup", { name: group.name || group.id }),
|
|
description: used ? t("confirm.deleteGroupWarn", { n: used }).trim() : undefined,
|
|
});
|
|
if (!confirmed || visit !== pageVisit || !canWriteGroups()) return;
|
|
savingGroup.value = true;
|
|
try {
|
|
await saveGroups(groups.value.filter((g) => g.id !== group.id));
|
|
push(t("toast.groupDeleted"));
|
|
} catch (err) {
|
|
push(t("toast.deleteFailed", { msg: err instanceof Error ? err.message : String(err) }), "bad");
|
|
} finally {
|
|
savingGroup.value = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.console-shell {
|
|
display: grid;
|
|
/* The sidebar narrows with the window (264px from ~1260px down to 208px),
|
|
wide enough for every label in either language. */
|
|
grid-template-columns: clamp(208px, 21vw, 264px) minmax(0, 1fr);
|
|
min-height: 100vh;
|
|
background: rgb(var(--wh-bg));
|
|
color: rgb(var(--wh-text));
|
|
}
|
|
.console-sidebar {
|
|
position: sticky;
|
|
top: 0;
|
|
display: flex;
|
|
height: 100vh;
|
|
flex-direction: column;
|
|
border-right: 1px solid rgb(var(--wh-border));
|
|
background: linear-gradient(165deg, rgb(var(--wh-surface)), rgb(var(--wh-surface-2)));
|
|
padding: 1.25rem 0.85rem;
|
|
}
|
|
.console-brand {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.7rem;
|
|
padding: 0.45rem 0.55rem 1.75rem;
|
|
color: rgb(var(--wh-text));
|
|
text-decoration: none;
|
|
}
|
|
.console-brand :deep(svg) {
|
|
color: rgb(var(--wh-accent));
|
|
}
|
|
.console-brand span {
|
|
display: grid;
|
|
gap: 0.1rem;
|
|
}
|
|
.console-brand strong {
|
|
font-size: 1rem;
|
|
letter-spacing: -0.04em;
|
|
}
|
|
.console-brand small,
|
|
.console-nav-label,
|
|
.console-kicker {
|
|
color: rgb(var(--wh-faint));
|
|
font-size: 0.62rem;
|
|
font-weight: 800;
|
|
letter-spacing: 0.13em;
|
|
text-transform: uppercase;
|
|
}
|
|
.console-nav-label {
|
|
margin: 0 0.65rem 0.45rem;
|
|
}
|
|
.console-nav {
|
|
display: grid;
|
|
gap: 0.2rem;
|
|
}
|
|
.console-nav-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.7rem;
|
|
width: 100%;
|
|
border: 0;
|
|
border-radius: 0.65rem;
|
|
background: transparent;
|
|
padding: 0.7rem;
|
|
color: rgb(var(--wh-muted));
|
|
font: inherit;
|
|
font-size: 0.82rem;
|
|
font-weight: 700;
|
|
text-align: left;
|
|
transition:
|
|
background-color 150ms ease,
|
|
color 150ms ease;
|
|
cursor: pointer;
|
|
}
|
|
.console-nav-item:hover {
|
|
background: rgb(var(--wh-surface-2));
|
|
color: rgb(var(--wh-text));
|
|
}
|
|
.console-nav-item.active {
|
|
background: rgb(var(--wh-accent));
|
|
color: white;
|
|
box-shadow: 0 8px 18px rgb(var(--wh-accent) / 0.2);
|
|
}
|
|
.console-sidebar-footer {
|
|
display: grid;
|
|
gap: 0.9rem;
|
|
margin-top: auto;
|
|
padding: 0.9rem 0.55rem 0.25rem;
|
|
border-top: 1px solid rgb(var(--wh-border));
|
|
}
|
|
.console-sidebar-footer button {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.55rem;
|
|
border: 0;
|
|
background: transparent;
|
|
padding: 0;
|
|
color: rgb(var(--wh-muted));
|
|
font: inherit;
|
|
font-size: 0.8rem;
|
|
font-weight: 700;
|
|
cursor: pointer;
|
|
}
|
|
.console-sidebar-footer button:hover {
|
|
color: rgb(var(--wh-bad));
|
|
}
|
|
.console-main {
|
|
min-width: 0;
|
|
}
|
|
.console-topbar {
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 20;
|
|
display: flex;
|
|
min-height: 76px;
|
|
align-items: center;
|
|
gap: 0.45rem;
|
|
border-bottom: 1px solid rgb(var(--wh-border));
|
|
background: color-mix(in srgb, rgb(var(--wh-bg)) 87%, transparent);
|
|
padding: 0.8rem clamp(1rem, 3vw, 2.5rem);
|
|
backdrop-filter: blur(18px);
|
|
}
|
|
.console-heading {
|
|
flex: 1 1 auto;
|
|
min-width: 0;
|
|
padding-right: 0.55rem;
|
|
}
|
|
.console-topbar h1 {
|
|
display: -webkit-box;
|
|
overflow: hidden;
|
|
-webkit-box-orient: vertical;
|
|
-webkit-line-clamp: 2;
|
|
margin: 0.1rem 0 0;
|
|
font-size: 1.15rem;
|
|
letter-spacing: -0.035em;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
.console-kicker {
|
|
margin: 0;
|
|
}
|
|
.console-heading .console-kicker {
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
.console-utilities,
|
|
.console-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: flex-end;
|
|
gap: 0.45rem;
|
|
}
|
|
.console-status {
|
|
white-space: nowrap;
|
|
}
|
|
.console-topbar-signout {
|
|
display: none;
|
|
}
|
|
.console-mobile-nav {
|
|
display: none;
|
|
}
|
|
.console-content {
|
|
width: min(100% - 2rem, 1240px);
|
|
margin: 0 auto;
|
|
padding: clamp(1.25rem, 3vw, 2.5rem) 0 5rem;
|
|
}
|
|
.console-login {
|
|
display: grid;
|
|
min-height: 62vh;
|
|
place-items: center;
|
|
}
|
|
.console-login-card {
|
|
width: min(100%, 430px);
|
|
text-align: center;
|
|
}
|
|
.console-login-card :deep(.rc-card-header) {
|
|
justify-content: center;
|
|
color: rgb(var(--wh-accent));
|
|
}
|
|
.console-login-card h2 {
|
|
margin: 0.35rem 0 0.65rem;
|
|
font-size: 1.35rem;
|
|
letter-spacing: -0.035em;
|
|
}
|
|
.console-login-card p {
|
|
margin: 0 0 1.4rem;
|
|
color: rgb(var(--wh-muted));
|
|
}
|
|
.console-context-bar {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 0.75rem 1rem;
|
|
margin-bottom: 1rem;
|
|
padding: 0.8rem 1rem;
|
|
border: 1px solid rgb(var(--wh-border));
|
|
border-radius: 0.85rem;
|
|
background: rgb(var(--wh-surface) / 0.6);
|
|
}
|
|
.console-context-bar > div {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.8rem;
|
|
}
|
|
.console-context-bar p {
|
|
margin: 0;
|
|
color: rgb(var(--wh-muted));
|
|
font-size: 0.8rem;
|
|
font-weight: 700;
|
|
}
|
|
.console-context-bar strong {
|
|
font-size: 1.25rem;
|
|
letter-spacing: -0.04em;
|
|
}
|
|
/* A heading with its count: one size, aligned on the text baseline. */
|
|
.console-context-bar > .console-count {
|
|
align-items: baseline;
|
|
gap: 0.5rem;
|
|
}
|
|
.console-count p {
|
|
color: rgb(var(--wh-text));
|
|
font-size: 1rem;
|
|
font-weight: 600;
|
|
}
|
|
.console-count strong {
|
|
color: rgb(var(--wh-muted));
|
|
font-size: 1rem;
|
|
font-variant-numeric: tabular-nums;
|
|
letter-spacing: 0;
|
|
}
|
|
.console-context-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
margin-left: auto;
|
|
}
|
|
/* A group's routes: its name with the route count right after it. The name
|
|
gives way (ellipsis) so the count and the actions keep their line. */
|
|
.console-group-bar {
|
|
position: relative;
|
|
}
|
|
.console-context-bar > .console-group-heading {
|
|
flex: 1 1 0;
|
|
min-width: 0;
|
|
gap: 0.5rem;
|
|
}
|
|
.console-group-heading h2 {
|
|
min-width: 0;
|
|
overflow: hidden;
|
|
margin: 0;
|
|
font-size: 1rem;
|
|
font-weight: 600;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
.console-group-bar .console-context-actions {
|
|
flex: none;
|
|
}
|
|
/* Labels given up for the name (see fitBarLabels): an icon-only button
|
|
turns into a 2rem square. */
|
|
.labels-new .console-reorder-label,
|
|
.labels-none .console-reorder-label,
|
|
.labels-none .console-new-route-label {
|
|
display: none;
|
|
}
|
|
.labels-new .console-reorder-btn,
|
|
.labels-none .console-reorder-btn,
|
|
.labels-none .console-new-route-btn {
|
|
width: 2rem;
|
|
padding-inline: 0;
|
|
}
|
|
/* Measures the buttons with their labels without showing or overflowing. */
|
|
.console-bar-sizer {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
display: flex;
|
|
width: 100%;
|
|
overflow: hidden;
|
|
visibility: hidden;
|
|
pointer-events: none;
|
|
}
|
|
.console-bar-sizer > * {
|
|
flex: none;
|
|
}
|
|
.console-context-bar .console-reorder-hint {
|
|
flex-basis: 100%;
|
|
font-size: 0.78rem;
|
|
font-weight: 500;
|
|
}
|
|
.console-empty {
|
|
padding: 4rem 1rem;
|
|
}
|
|
.console-group-card {
|
|
cursor: pointer;
|
|
}
|
|
/* Cards stretch to their grid row; the footer sits at the bottom so the
|
|
dividers of one row line up whatever each card lists above them. */
|
|
.console-group-card,
|
|
.console-group-card > :deep(div) {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.console-group-card > :deep(div) {
|
|
flex: 1 1 auto;
|
|
}
|
|
.console-open {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.35rem;
|
|
color: rgb(var(--wh-accent));
|
|
font-size: 0.75rem;
|
|
font-weight: 800;
|
|
}
|
|
@media (max-width: 900px) {
|
|
.console-shell {
|
|
display: block;
|
|
}
|
|
.console-sidebar {
|
|
display: none;
|
|
}
|
|
.console-topbar-signout {
|
|
display: inline-flex;
|
|
}
|
|
.console-mobile-nav {
|
|
display: block;
|
|
border-bottom: 1px solid rgb(var(--wh-border));
|
|
padding: 0.5rem 1rem;
|
|
overflow-x: auto;
|
|
/* Still swipeable, without a scrollbar under the tabs. */
|
|
scrollbar-width: none;
|
|
}
|
|
.console-mobile-nav::-webkit-scrollbar {
|
|
display: none;
|
|
}
|
|
.console-mobile-nav :deep(.rc-tabs) {
|
|
min-width: max-content;
|
|
}
|
|
}
|
|
@media (max-width: 620px) {
|
|
/* Title left with theme/language pinned top-right; page actions below, right-aligned. */
|
|
.console-topbar {
|
|
display: grid;
|
|
grid-template-columns: minmax(0, 1fr) auto;
|
|
align-items: start;
|
|
gap: 0.75rem 0.25rem;
|
|
}
|
|
.console-heading {
|
|
padding-right: 0;
|
|
}
|
|
.console-utilities {
|
|
gap: 0.25rem;
|
|
}
|
|
.console-actions {
|
|
grid-column: 1 / -1;
|
|
justify-self: end;
|
|
max-width: 100%;
|
|
overflow-x: auto;
|
|
padding-bottom: 0.05rem;
|
|
}
|
|
/* Keep the top-right tools compact so the title column stays readable. */
|
|
.console-status,
|
|
.console-signout-label,
|
|
.console-lang-icon {
|
|
display: none;
|
|
}
|
|
.console-topbar-signout {
|
|
width: 2rem;
|
|
padding-inline: 0;
|
|
}
|
|
.console-content {
|
|
width: min(100% - 1.25rem, 1240px);
|
|
}
|
|
}
|
|
@media (max-width: 360px) {
|
|
/* Too narrow to share a row with the tools: the breadcrumb sits beside
|
|
them and the title takes the full width below. */
|
|
.console-topbar {
|
|
row-gap: 0.3rem;
|
|
}
|
|
.console-heading {
|
|
display: contents;
|
|
}
|
|
.console-kicker {
|
|
grid-column: 1;
|
|
grid-row: 1;
|
|
align-self: center;
|
|
}
|
|
.console-topbar h1 {
|
|
grid-column: 1 / -1;
|
|
grid-row: 2;
|
|
margin: 0;
|
|
}
|
|
.console-utilities {
|
|
grid-column: 2;
|
|
grid-row: 1;
|
|
}
|
|
.console-actions {
|
|
grid-row: 3;
|
|
margin-top: 0.45rem;
|
|
}
|
|
}
|
|
</style>
|