Separate guest and panel navigation and add account flyout

This commit is contained in:
SantaSpeen committed 2026-12-01 16:04:40 +03:00
1 parent 60b584b7c1
commit 5852bf1897
42 files changed
+1024 -55

No files matched your search

+1
View File
@@ -3,5 +3,6 @@
"name": "Anna Volkova",
"email": "anna@example.test",
"status": "active",
"panel": "admin",
"banReason": null
}
@@ -0,0 +1,9 @@
{
"title": "Безопасность",
"description": "Способы входа в аккаунт. Тестовые данные; изменение факторов входа в примере не выполняется.",
"rows": [
{ "label": "Пароль", "value": "Установлен" },
{ "label": "TOTP", "value": "Подключён" },
{ "label": "Passkey", "value": "Windows Hello" }
]
}
@@ -0,0 +1,11 @@
{
"title": "Устройства и сеансы",
"description": "Пример активных сеансов аккаунта.",
"rows": [
{ "label": "Windows · Edge", "value": "Текущий сеанс" },
{
"label": "Android · Chrome",
"value": "Последняя активность: сегодня, 09:30"
}
]
}
+43 -10
View File
@@ -1,13 +1,46 @@
{
"defaultPage": "overview",
"items": [
{ "id": "overview", "label": "Обзор", "icon": "dashboard" },
{ "id": "projects", "label": "Проекты", "icon": "applications" },
{
"id": "administration",
"label": "Администрирование",
"icon": "server",
"children": [{ "id": "logs", "label": "Логи", "icon": "document" }]
"panels": {
"user": {
"defaultPage": "overview",
"items": [
{
"id": "overview",
"label": "Обзор",
"icon": "dashboard"
},
{
"id": "projects",
"label": "Проекты",
"icon": "applications"
}
]
},
"admin": {
"defaultPage": "overview",
"items": [
{
"id": "overview",
"label": "Обзор",
"icon": "dashboard"
},
{
"id": "projects",
"label": "Проекты",
"icon": "applications"
},
{
"id": "administration",
"label": "Администрирование",
"icon": "server",
"children": [
{
"id": "logs",
"label": "Логи",
"icon": "document"
}
]
}
]
}
]
}
}
+141 -9
View File
@@ -22,7 +22,12 @@ const cleanups = [];
const pageIds = new Set(["overview", "projects", "logs"]);
let allowedIds = new Set(),
serviceHome = null;
const fixedIds = new Set(["account", "account-settings"]);
const fixedIds = new Set([
"account",
"account-security",
"account-sessions",
"account-settings",
]);
let theme = "light",
disposed = false,
menuRequest,
@@ -82,6 +87,71 @@ function urlFor(id, push = false) {
else url.searchParams.delete("page");
history[push ? "pushState" : "replaceState"]({}, "", url);
}
let sessionCleanup = () => {};
function showSession(error = { status: 401 }) {
pageRequest?.abort();
pageRequest = undefined;
menuRequest?.abort();
menuRequest = undefined;
accountRequest?.abort();
accountRequest = undefined;
errorCleanup();
errorCleanup = () => {};
sessionCleanup();
sessionCleanup = () => {};
dock.close();
accountMenu.close();
notify.dismiss();
document.querySelectorAll("[popover]:popover-open").forEach((popup) => {
if (popup.matches(":popover-open")) popup.hidePopover();
});
document.querySelectorAll("dialog[open]").forEach((dialog) => dialog.close());
identity = null;
accountError = error;
changingMenu = true;
navigation.setItems([]);
changingMenu = false;
allowedIds.clear();
serviceHome = null;
accountMenu.update({});
$("#page-data").replaceChildren();
$(".integration-form").hidden = true;
document.body.dataset.session =
error.status === 401 ? "guest" : "unavailable";
$(".shell").inert = true;
$(".skip").href = "#session-screen";
const screen = $("#session-screen");
screen.innerHTML = errorPageMarkup({
status: error.status || (error instanceof TypeError ? "offline" : 500),
t,
});
sessionCleanup = mountErrorPage(screen, {
onAccount: () =>
notify("Это пример состояния входа. SSO пока не подключён.", {
type: "info",
title: "Вход в аккаунт",
}),
onRetry: async () => {
await loadAccount();
if (identity) refreshNavigation();
},
});
const login = screen.querySelector('[data-error-action="account"]');
if (login) login.textContent = "Войти";
}
function showShell() {
sessionCleanup();
sessionCleanup = () => {};
$("#session-screen").replaceChildren();
$(".shell").inert = false;
document.body.dataset.session = "authenticated";
$(".skip").href = "#content";
document.body.dataset.panel = identity.panel;
$(".breadcrumb").textContent =
identity.panel === "admin"
? "Anidev / Панель администратора"
: "Anidev / Панель пользователя";
}
function displayError(status, { reason, requestId, retry } = {}) {
errorCleanup();
errorCleanup = () => {};
@@ -157,6 +227,10 @@ function renderAccount(id) {
}
}
async function showPage(id) {
if (!identity) {
if (accountError) showSession(accountError);
return;
}
pageRequest?.abort();
errorCleanup();
errorCleanup = () => {};
@@ -167,10 +241,53 @@ async function showPage(id) {
$(".page-heading").hidden = false;
$(".integration-form").hidden = true;
accountMenu.setActive(id);
if (fixedIds.has(id)) {
if (["account", "account-settings"].includes(id)) {
renderAccount(id);
return;
}
if (["account-security", "account-sessions"].includes(id)) {
$("#page-title").textContent = "Загрузка…";
$("#page-description").textContent = "Получаем данные аккаунта.";
container.setAttribute("aria-busy", "true");
try {
const data = await get(
`account/${id === "account-security" ? "security" : "sessions"}.json`,
request.signal,
);
if (disposed || request !== pageRequest) return;
if (
typeof data.title !== "string" ||
typeof data.description !== "string" ||
!Array.isArray(data.rows)
)
throw Error("Invalid account section");
$("#page-title").textContent = data.title;
$("#page-description").textContent = data.description;
const list = document.createElement("dl");
list.className = "account-details";
for (const row of data.rows.slice(0, 100)) {
if (typeof row.label !== "string" || typeof row.value !== "string")
throw Error("Invalid account row");
const item = document.createElement("div"),
term = document.createElement("dt"),
value = document.createElement("dd");
term.textContent = row.label;
value.textContent = row.value;
item.append(term, value);
list.append(item);
}
container.append(list);
} catch (error) {
if (error.name !== "AbortError" && request === pageRequest && !disposed) {
if (error.status === 401) showSession(error);
else
displayError(error.status || 500, { retry: () => showPage(current) });
}
} finally {
if (request === pageRequest) container.setAttribute("aria-busy", "false");
}
return;
}
if (identity?.status === "banned") {
displayError("banned", { reason: identity.banReason });
return;
@@ -234,6 +351,10 @@ async function showPage(id) {
} catch (error) {
if (error.name === "AbortError" || disposed || request !== pageRequest)
return;
if (error.status === 401) {
showSession(error);
return;
}
if (error.status === 403 && error.code === "ACCOUNT_BANNED") {
accountError = null;
identity = {
@@ -302,18 +423,24 @@ async function loadAccount() {
try {
const data = await get("account.json", request.signal);
if (disposed || request !== accountRequest) return;
if (data?.status === "guest") {
showSession({ status: 401 });
return;
}
if (
!data ||
typeof data.id !== "string" ||
typeof data.name !== "string" ||
typeof data.email !== "string" ||
!["active", "banned"].includes(data.status) ||
(data.panel !== undefined && !["user", "admin"].includes(data.panel)) ||
(data.banReason != null && typeof data.banReason !== "string")
)
throw Error("Invalid account response");
identity = data;
identity = { ...data, panel: data.panel || "user" };
accountError = null;
accountMenu.update(data);
showShell();
} catch (error) {
if (
error.name !== "AbortError" &&
@@ -325,20 +452,25 @@ async function loadAccount() {
identity = {
...identity,
status: "banned",
panel: "user",
banReason: typeof error.reason === "string" ? error.reason : null,
};
accountError = null;
}
showShell();
} else showSession(error);
}
}
}
async function refreshNavigation() {
if (!identity) return;
menuRequest?.abort();
const request = (menuRequest = new AbortController());
$("#connection-status").textContent = "Обновляем доступные разделы…";
try {
const data = await get("navigation.json", request.signal);
const response = await get("navigation.json", request.signal);
if (disposed || request !== menuRequest) return;
const data = response.panels ? response.panels[identity.panel] : response;
if (!data) throw Error("Panel navigation not configured");
const reserved = (items) =>
Array.isArray(items) &&
items.some(
@@ -391,9 +523,8 @@ async function refreshNavigation() {
pageRequest?.abort();
accountError = null;
if (error.status === 401) {
identity = null;
accountError = error;
accountMenu.update({});
showSession(error);
return;
} else
identity = {
...identity,
@@ -464,7 +595,7 @@ $("#check-settings").addEventListener(
{ signal },
);
await loadAccount();
refreshNavigation();
if (identity) refreshNavigation();
function dispose() {
if (disposed) return;
disposed = true;
@@ -472,6 +603,7 @@ function dispose() {
pageRequest?.abort();
accountRequest?.abort();
errorCleanup();
sessionCleanup();
abort.abort();
cleanups.forEach((cleanup) => cleanup());
navigation.dispose();
+8 -2
View File
@@ -8,8 +8,14 @@
<link rel="stylesheet" href="./anidev/components/system.css" />
<link rel="stylesheet" href="./app.css" />
</head>
<body data-concept="dock" data-theme="light">
<a class="skip" href="#content">Перейти к содержимому</a>
<body data-concept="dock" data-theme="light" data-session="loading">
<main id="session-screen" tabindex="-1" aria-live="polite">
<section class="identity-gate">
<h1>Проверяем вход…</h1>
<p>Получаем состояние аккаунта.</p>
</section>
</main>
<a class="skip" href="#session-screen">Перейти к содержимому</a>
<div class="shell">
<aside
class="navigation"