Add Markdown editor, server statistics and content navigation

This commit is contained in:
SantaSpeen committed 2026-12-02 15:32:14 +03:00
1 parent 03c590e172
commit 1819f35f91
52 files changed
+7190 -28

No files matched your search

+15
View File
@@ -12,6 +12,11 @@
"id": "projects",
"label": "Проекты",
"icon": "applications"
},
{
"id": "documents",
"label": "Документы",
"icon": "document"
}
]
},
@@ -37,8 +42,18 @@
"id": "logs",
"label": "Логи",
"icon": "document"
},
{
"id": "statistics",
"label": "Статистика сервера",
"icon": "server"
}
]
},
{
"id": "documents",
"label": "Документы",
"icon": "document"
}
]
}
+3 -1
View File
@@ -83,6 +83,8 @@ body.dock-open .nav-empty {
flex-wrap: wrap;
}
.breadcrumb {
display: none;
display: block;
min-width: 0;
flex: 1 1 200px;
}
}
+103 -3
View File
@@ -1,5 +1,7 @@
import {
applyTheme,
breadcrumbsMarkup,
mountBreadcrumbs,
iconSvg,
createNotifier,
mountCopyField,
@@ -12,6 +14,14 @@ import {
searchSelectMarkup,
mountSearchSelect,
} from "./anidev/runtime/index.js";
import {
contentDemoPages,
contentDemoMarkup,
mountContentDemo,
contentBreadcrumbs,
contentHref,
createDemoDocuments,
} from "./anidev/components/content-demo.js";
const $ = (selector) => document.querySelector(selector),
t = (ru) => ru;
@@ -21,7 +31,10 @@ const abort = new AbortController(),
const notify = createNotifier($("#project-toast"), { t });
const cleanups = [];
let syncAccountTheme = () => {};
const pageIds = new Set(["overview", "projects", "logs"]);
const pageIds = new Set(["overview", "projects", "logs", ...contentDemoPages]);
const documentFiles = createDemoDocuments();
let contentCleanup = () => {},
breadcrumbCleanup = () => {};
let allowedIds = new Set(),
serviceHome = null;
let mobilePages = new Map();
@@ -93,6 +106,13 @@ function urlFor(id, push = false) {
}
let sessionCleanup = () => {};
function showSession(error = { status: 401 }) {
contentCleanup();
contentCleanup = () => {};
breadcrumbCleanup();
breadcrumbCleanup = () => {};
documentFiles.clear();
for (const [path, file] of createDemoDocuments())
documentFiles.set(path, file);
pageRequest?.abort();
pageRequest = undefined;
menuRequest?.abort();
@@ -238,6 +258,8 @@ async function showPage(id) {
return;
}
pageRequest?.abort();
contentCleanup();
contentCleanup = () => {};
errorCleanup();
errorCleanup = () => {};
const request = (pageRequest = new AbortController()),
@@ -247,6 +269,7 @@ async function showPage(id) {
$(".page-heading").hidden = false;
$(".integration-form").hidden = true;
accountMenu.setActive(id);
renderBreadcrumbs(id);
mobileDock.update(id, `${identity.panel}:${identity.id || "account"}`);
if (["account", "account-settings"].includes(id)) {
renderAccount(id);
@@ -321,10 +344,51 @@ async function showPage(id) {
displayError(404);
return;
}
if (!allowedIds.has(id)) {
if (
!allowedIds.has(id) &&
!(["server", "servers"].includes(id) && allowedIds.has("statistics"))
) {
displayError(403);
return;
}
if (contentDemoPages.includes(id)) {
$(".page-heading").hidden = true;
const url = new URL(location.href),
server = url.searchParams.get("server") || "edge-01",
path = url.searchParams.get("path") || "/";
container.innerHTML = contentDemoMarkup(id, {
server,
path,
t,
heading: (title, description) =>
`<div class="page-heading"><div><h1></h1><p></p></div></div>`,
});
const heading = container.querySelector(".page-heading");
if (heading) {
const names = {
documents: "Документы и код",
servers: "Серверы",
server,
statistics: `Статистика · ${server}`,
};
heading.querySelector("h1").textContent = names[id];
heading.querySelector("p").textContent =
"Демонстрационные данные · API пока не подключено.";
}
contentCleanup = mountContentDemo(
container.querySelector("[data-content-demo]"),
{
page: id,
server,
path,
files: documentFiles,
onNavigate: visitContentURL,
notify,
t,
},
);
return;
}
container.setAttribute("aria-busy", "true");
try {
const data = await get(`pages/${id}.json`, request.signal);
@@ -425,7 +489,12 @@ const mobileDock = mountMobileDock($(".navigation"), {
if (personal[id])
return { id, label: personal[id][0], icon: personal[id][1] };
if (preview(id)) return { id, label: "Состояние", icon: "warning" };
return mobilePages.get(id) || null;
return (
mobilePages.get(id) ||
(["servers", "server"].includes(id) && mobilePages.has("statistics")
? { id, label: id === "servers" ? "Серверы" : "Сервер", icon: "server" }
: null)
);
},
});
const navigation = mountNavigation($(".nav-links"), {
@@ -456,6 +525,35 @@ function go(id, push = true) {
urlFor(id, push);
showPage(id);
}
function renderBreadcrumbs(id) {
breadcrumbCleanup();
const url = new URL(location.href);
const personalNames = {
account: "Управление",
"account-security": "Безопасность",
"account-sessions": "Устройства и сеансы",
"account-settings": "Настройки",
};
const items = contentDemoPages.includes(id)
? contentBreadcrumbs(id, {
server: url.searchParams.get("server") || "edge-01",
path: url.searchParams.get("path") || "/",
rootPage: "overview",
t,
})
: [
{ label: "anidev", href: contentHref({ page: "overview" }) },
{ label: personalNames[id] || mobilePages.get(id)?.label || "Панель" },
];
$(".breadcrumb").innerHTML = breadcrumbsMarkup({ items, t });
breadcrumbCleanup = mountBreadcrumbs($(".breadcrumbs"), {
onNavigate: visitContentURL,
});
}
function visitContentURL(url) {
history.pushState({}, "", url);
go(url.searchParams.get("page") || "overview", false);
}
async function loadAccount() {
accountRequest?.abort();
const request = (accountRequest = new AbortController());
@@ -658,6 +756,8 @@ function dispose() {
accountRequest?.abort();
errorCleanup();
sessionCleanup();
contentCleanup();
breadcrumbCleanup();
abort.abort();
cleanups.forEach((cleanup) => cleanup());
navigation.dispose();