diff --git a/ui/index.html b/ui/index.html index eb5776e..2a37e81 100644 --- a/ui/index.html +++ b/ui/index.html @@ -3,6 +3,7 @@ + Gnexus Book diff --git a/ui/package-lock.json b/ui/package-lock.json index 85ce2a1..bb51093 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -7,7 +7,9 @@ "name": "gnexus-book-ui", "dependencies": { "@vitejs/plugin-vue": "^5.2.0", + "dompurify": "^3.4.18", "gnexus-ui-kit": "file:../../gnexus-ui-kit", + "marked": "^18.2.1", "vite": "^6.0.0", "vue": "^3.4.0" }, @@ -877,6 +879,13 @@ "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", "license": "MIT" }, + "node_modules/@types/trusted-types": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", + "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==", + "license": "MIT", + "optional": true + }, "node_modules/@vitejs/plugin-vue": { "version": "5.2.4", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-5.2.4.tgz", @@ -996,6 +1005,15 @@ "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", "license": "MIT" }, + "node_modules/dompurify": { + "version": "3.4.18", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.18.tgz", + "integrity": "sha512-ofe3wI/uNm68HInABYFJYqQxRw1EaKAjNdrFVKqjUY+UZurvNd2L/HuQe097s/4RivWiZyP6tT7aoT8atjfhwg==", + "license": "(MPL-2.0 OR Apache-2.0)", + "optionalDependencies": { + "@types/trusted-types": "^2.0.7" + } + }, "node_modules/entities": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz", @@ -1099,6 +1117,18 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/marked": { + "version": "18.2.1", + "resolved": "https://registry.npmjs.org/marked/-/marked-18.2.1.tgz", + "integrity": "sha512-ii4bxCTCqqwpT86XZWgJNs+ZnAIZksmLGYMViWA7PDIXYIeNo1x6cDdX3JOip9NM/cI6p8z57FxliACboTruMA==", + "license": "MIT", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 20" + } + }, "node_modules/nanoid": { "version": "3.3.12", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.12.tgz", diff --git a/ui/package.json b/ui/package.json index 3ef2a3f..2408a7d 100644 --- a/ui/package.json +++ b/ui/package.json @@ -9,9 +9,10 @@ }, "dependencies": { "@vitejs/plugin-vue": "^5.2.0", + "dompurify": "^3.4.18", + "gnexus-ui-kit": "file:../../gnexus-ui-kit", + "marked": "^18.2.1", "vite": "^6.0.0", - "vue": "^3.4.0", - "gnexus-ui-kit": "file:../../gnexus-ui-kit" - }, - "devDependencies": {} + "vue": "^3.4.0" + } } diff --git a/ui/src/i18n/messages/en.js b/ui/src/i18n/messages/en.js index 4f53500..2c5036d 100644 --- a/ui/src/i18n/messages/en.js +++ b/ui/src/i18n/messages/en.js @@ -78,9 +78,15 @@ "common.role": "Role", "common.scopes": "Scopes", "common.preview": "Preview", + "common.fields": "Fields", + "common.back": "Back", "docs.title": "Documents", "docs.subtitle": "Browse, search and version the knowledge base.", + "docs.index": "Document index", + "docs.document": "Document", + "docs.metadata": "Metadata", + "docs.newDraft": "New draft", "docs.searchPlaceholder": "Search documents", "docs.noDocs": "No documents loaded", "docs.noResults": "Nothing matched this search.", @@ -108,7 +114,9 @@ "inventory.title": "Inventory", "inventory.subtitle": "Structured facts about hosts, services and networks.", "inventory.selectType": "Select an inventory type.", - "inventory.selectRecord": "Select a record to inspect its JSON.", + "inventory.selectRecord": "Select a record to inspect it.", + "inventory.recordId": "ID", + "inventory.host": "Host", "inventory.rawView": "Raw", "inventory.jsonView": "JSON", "inventory.noRecords": "This inventory type is empty.", diff --git a/ui/src/i18n/messages/ru.js b/ui/src/i18n/messages/ru.js index 3cfbae9..4613761 100644 --- a/ui/src/i18n/messages/ru.js +++ b/ui/src/i18n/messages/ru.js @@ -78,8 +78,14 @@ "common.role": "Роль", "common.scopes": "Права", "common.preview": "Предпросмотр", + "common.fields": "Поля", + "common.back": "Назад", "docs.title": "Документы", + "docs.index": "Индекс документов", + "docs.document": "Документ", + "docs.metadata": "Метаданные", + "docs.newDraft": "Новый черновик", "docs.subtitle": "Просмотр, поиск и версии базы знаний.", "docs.searchPlaceholder": "Поиск документов", "docs.noDocs": "Документы не загружены", @@ -108,7 +114,9 @@ "inventory.title": "Инвентарь", "inventory.subtitle": "Структурированные факты о хостах, сервисах и сетях.", "inventory.selectType": "Выберите тип инвентаря.", - "inventory.selectRecord": "Выберите запись, чтобы посмотреть её JSON.", + "inventory.selectRecord": "Выберите запись, чтобы посмотреть её.", + "inventory.recordId": "ID", + "inventory.host": "Хост", "inventory.rawView": "Исходный", "inventory.jsonView": "JSON", "inventory.noRecords": "Этот тип инвентаря пуст.", diff --git a/ui/src/i18n/messages/uk.js b/ui/src/i18n/messages/uk.js index ff1ad9b..0d2516d 100644 --- a/ui/src/i18n/messages/uk.js +++ b/ui/src/i18n/messages/uk.js @@ -78,8 +78,14 @@ "common.role": "Роль", "common.scopes": "Дозволи", "common.preview": "Попередній перегляд", + "common.fields": "Поля", + "common.back": "Назад", "docs.title": "Документи", + "docs.index": "Індекс документів", + "docs.document": "Документ", + "docs.metadata": "Метадані", + "docs.newDraft": "Нова чернетка", "docs.subtitle": "Перегляд, пошук і версії бази знань.", "docs.searchPlaceholder": "Пошук документів", "docs.noDocs": "Документи не завантажено", @@ -108,7 +114,9 @@ "inventory.title": "Інвентар", "inventory.subtitle": "Структуровані факти про хости, сервіси та мережі.", "inventory.selectType": "Виберіть тип інвентарю.", - "inventory.selectRecord": "Виберіть запис, щоб переглянути його JSON.", + "inventory.selectRecord": "Виберіть запис, щоб переглянути його.", + "inventory.recordId": "ID", + "inventory.host": "Хост", "inventory.rawView": "Сирий", "inventory.jsonView": "JSON", "inventory.noRecords": "Цей тип інвентарю порожній.", diff --git a/ui/src/main.js b/ui/src/main.js index bf5696f..f86a79f 100644 --- a/ui/src/main.js +++ b/ui/src/main.js @@ -1,4 +1,6 @@ import { computed, createApp, onMounted, reactive, ref, watch } from "vue"; +import { marked } from "marked"; +import DOMPurify from "dompurify"; import "gnexus-ui-kit/dist/css/kit.css"; import "gnexus-ui-kit/dist/assets/fonts/phosphor-icons/src/css/icons.css"; import { @@ -6,13 +8,19 @@ GnBadge, GnButton, GnCard, + GnChip, GnConfirmDialog, GnDescriptionList, + GnDrawer, GnEmptyState, GnInput, GnMetricCard, + GnModal, GnPageHeader, GnSearchField, + GnTable, + GnTabs, + GnTextarea, GnToastProvider, GnToolbar, GnUserCard, @@ -41,6 +49,24 @@ return `---\nowner: gmikcon\nstatus: draft\nlast_reviewed: ${today}\nreview_interval: 30d\nconfidence: medium\nsource_of_truth: manual\n---\n\n# New document\n\n`; }; +marked.setOptions({ gfm: true, breaks: false }); + +const renderMarkdown = value => + DOMPurify.sanitize(marked.parse(String(value || ""))); + +const readableKey = key => + String(key) + .replace(/[_-]+/g, " ") + .replace(/\b\w/g, char => char.toUpperCase()); + +const displayValue = value => { + if (value === null || value === undefined || value === "") return "—"; + if (Array.isArray(value)) return value.map(displayValue).join(", "); + if (typeof value === "object") return JSON.stringify(value, null, 2); + if (typeof value === "boolean") return value ? "true" : "false"; + return String(value); +}; + const IssueList = { components: { GnBadge }, props: { @@ -53,12 +79,14 @@

{{ t('status.noIssues') }}

-
- {{ issue.severity }} - {{ issue.code }} - {{ issue.path }} + {{ issue.severity || 'warning' }} +
+
+ {{ issue.path }} + {{ issue.code }} +
+

{{ issue.message }}

-

{{ issue.message }}

` @@ -70,13 +98,19 @@ GnBadge, GnButton, GnCard, + GnChip, GnConfirmDialog, GnDescriptionList, + GnDrawer, GnEmptyState, GnInput, GnMetricCard, + GnModal, GnPageHeader, GnSearchField, + GnTable, + GnTabs, + GnTextarea, GnToolbar, GnUserCard, IssueList @@ -113,6 +147,9 @@ content: defaultDocTemplate() }); const proposalRunning = ref(false); + const proposalOpen = ref(false); + const historyOpen = ref(false); + const mobileDocView = ref("list"); const inventoryTypes = ref([]); const inventoryType = ref(""); @@ -120,6 +157,7 @@ const inventoryFilter = ref(""); const selectedInventoryId = ref(""); const inventoryRaw = ref(false); + const inventoryTab = ref("fields"); const inventoryRawText = ref(""); const inventoryLoading = ref(false); const inventoryError = ref(""); @@ -186,8 +224,7 @@ { id: "status", label: t("nav.status"), icon: "ph-heartbeat" }, ...(authEnabled.value && user.value ? [{ id: "keys", label: t("nav.keys"), icon: "ph-key" }] - : []), - { id: "settings", label: t("nav.settings"), icon: "ph-sliders" } + : []) ]); const pageMeta = computed( @@ -250,6 +287,35 @@ } ]); + const docFrontmatterItems = computed(() => { + const frontmatter = selectedDoc.value?.frontmatter || {}; + const priority = [ + "owner", + "status", + "last_reviewed", + "review_interval", + "confidence", + "source_of_truth" + ]; + const keys = Object.keys(frontmatter).sort((a, b) => { + const ai = priority.indexOf(a); + const bi = priority.indexOf(b); + if (ai === -1 && bi === -1) return a.localeCompare(b); + if (ai === -1) return 1; + if (bi === -1) return -1; + return ai - bi; + }); + return keys.map(key => ({ + key, + term: readableKey(key), + value: displayValue(frontmatter[key]) + })); + }); + + const renderedDocBody = computed(() => + renderMarkdown(selectedDoc.value?.body || "") + ); + const filteredInventory = computed(() => { const query = inventoryFilter.value.trim().toLowerCase(); if (!query) return inventoryRecords.value; @@ -265,6 +331,22 @@ item => item.id === selectedInventoryId.value ) || null ); + const inventoryFieldItems = computed(() => + Object.entries(selectedInventoryRecord.value || {}).map(([key, value]) => ({ + key, + term: readableKey(key), + value: displayValue(value) + })) + ); + const inventoryColumns = computed(() => [ + { key: "name", label: t("common.name") }, + { key: "id", label: t("inventory.recordId") }, + { key: "host", label: t("inventory.host") } + ]); + const inventoryTabs = computed(() => [ + { id: "fields", label: t("common.fields"), icon: "ph-list-dashes" }, + { id: "json", label: t("common.raw"), icon: "ph-code" } + ]); const inventoryDisplay = computed(() => { if (inventoryRaw.value) return inventoryRawText.value; return selectedInventoryRecord.value @@ -300,6 +382,24 @@ return versionNo === latest; }; + const changeDetailItems = computed(() => { + const change = selectedChange.value; + if (!change) return []; + return [ + { key: "summary", term: t("common.summary"), value: change.summary }, + { key: "status", term: t("common.status"), value: statusLabel(change.status) }, + { key: "kind", term: t("common.type"), value: change.kind }, + { key: "target", term: t("common.target"), value: change.target }, + { key: "reason", term: t("common.reason"), value: change.reason || "—" }, + { key: "created", term: t("common.created"), value: formatDate(change.created_at) }, + { + key: "actor", + term: t("auth.account"), + value: [change.actor_name, change.actor_kind, change.via].filter(Boolean).join(" · ") || "—" + } + ]; + }); + async function request(path, options = {}) { const response = await fetch(`/api${path}`, { credentials: "same-origin", @@ -399,7 +499,7 @@ ) { await loadDoc(selectedDocPath.value); } else if (docs.value.length) { - await loadDoc(docs.value[0].path); + await loadDoc(docs.value[0].path, false); } } if (inventoryResult.status === "fulfilled") { @@ -444,10 +544,11 @@ } } - async function loadDoc(path) { + async function loadDoc(path, openDetail = true) { if (!path) return; if (docQuery.value) docQuery.value = ""; selectedDocPath.value = path; + if (openDetail) mobileDocView.value = "detail"; selectedDoc.value = null; docLoading.value = true; docError.value = ""; @@ -509,6 +610,34 @@ await requestDiff(Math.max(1, latest - 1), latest); } + function openProposal() { + if (!selectedDoc.value) return; + proposal.target = selectedDocPath.value; + proposal.content = + selectedDoc.value.raw || selectedDoc.value.body || defaultDocTemplate(); + proposal.summary = ""; + proposal.reason = ""; + proposalOpen.value = true; + } + + function openHistory() { + historyOpen.value = true; + if (selectedDocPath.value && !docHistory.value.length) { + loadDoc(selectedDocPath.value); + } + } + + function backToDocList() { + mobileDocView.value = "list"; + } + + function switchInventoryTab(tab) { + inventoryTab.value = tab; + if (tab === "json" && !inventoryRawText.value) { + refreshInventoryRaw(); + } + } + function restoreVersion(versionNo) { askConfirm({ title: t("docs.restoreConfirm"), @@ -563,6 +692,7 @@ }); proposal.summary = ""; proposal.reason = ""; + proposalOpen.value = false; activePage.value = "changes"; drawerOpen.value = false; await refreshChanges(); @@ -659,9 +789,10 @@ inventoryLoading.value = true; inventoryError.value = ""; try { + inventoryRawText.value = ""; inventoryRecords.value = (await apiGet(`/inventory/${encodeURIComponent(type)}`)) || []; selectedInventoryId.value = inventoryRecords.value[0]?.id || ""; - if (inventoryRaw.value) await refreshInventoryRaw(); + if (inventoryTab.value === "json") await refreshInventoryRaw(); } catch (error) { inventoryRecords.value = []; inventoryError.value = @@ -880,6 +1011,7 @@ function go(page) { activePage.value = page; + if (page === "docs") mobileDocView.value = "list"; drawerOpen.value = false; if (page === "keys") loadKeys(); if (page === "status") refreshStatus(); @@ -922,9 +1054,11 @@ applyingChange, applyChange, authEnabled, + backToDocList, booting, canWrite, changeError, + changeDetailItems, changeLoading, changes, changeStatusVariant, @@ -936,6 +1070,7 @@ dismissIssued, docDiff, docError, + docFrontmatterItems, docHistory, docLoading, docQuery, @@ -947,12 +1082,17 @@ go, healthStatus, historyError, + historyOpen, + inventoryColumns, inventoryDisplay, inventoryError, + inventoryFieldItems, inventoryFilter, inventoryLoading, inventoryRaw, inventoryRecords, + inventoryTab, + inventoryTabs, inventoryType, inventoryTypes, isAdmin, @@ -974,14 +1114,19 @@ localeOverride, login, logout, + mobileDocView, navItems, + openHistory, + openProposal, pageError, pageSubtitle, pageTitle, pretty, proposal, + proposalOpen, proposalRunning, refreshAll, + renderedDocBody, restoreVersion, revokeKey, rotateKey, @@ -1000,6 +1145,7 @@ storage, storageIsDb, submitProposal, + switchInventoryTab, t, toast, toggleAllKeys, @@ -1063,7 +1209,7 @@ :avatar="{ initials: userInitials }" compact /> - - {{ t('docs.restore') }} -
- -
- - - -
{{ docDiff }}
-
- {{ diffError }} - - - -
- - - - -
- {{ t('docs.submit') }} -
-
-
+ {{ diffError }} + + +
+

{{ historyError }}

+ +
+
+ + {{ t('docs.restore') }} +
+
+
+
+ {{ t('docs.diffTitle') }} + {{ t('common.close') }} +
+
{{ docDiff }}
+
+ {{ diffError }} +
+
+ + +

{{ t('docs.proposalMeta') }}

+
+ + + + +
+ {{ t('docs.submit') }} + {{ t('common.cancel') }} +
+
+
-
-
+ + {{ inventoryError }} + +
+ -
- -