From d67a9f0258f174765f9d6ec9caddf8ac80a3e9e4 Mon Sep 17 00:00:00 2001 From: Sebastian Rakel Date: Wed, 28 Oct 2026 22:24:12 +0100 Subject: [PATCH] Implement Catalog View and Diff fixes #190 --- ui/src/components/CatalogDetailCard.vue | 44 ++++ ui/src/components/CatalogDiffViewTable.vue | 51 ++++ ui/src/helper/diff.ts | 75 ++++++ ui/src/i18n/langs/de-DE.json | 14 +- ui/src/i18n/langs/en-US.json | 14 +- ui/src/layouts/MainLayout.vue | 11 +- ui/src/pages/catalog/CatalogDetailPage.vue | 111 +++++++++ ui/src/pages/catalog/CatalogDiffViewPage.vue | 249 +++++++++++++++++++ ui/src/pages/catalog/CatalogOverviewPage.vue | 214 ++++++++++++++++ ui/src/puppet/models/puppet-catalog.ts | 50 ++++ ui/src/router/routes.ts | 15 ++ 11 files changed, 845 insertions(+), 3 deletions(-) create mode 100644 ui/src/components/CatalogDetailCard.vue create mode 100644 ui/src/components/CatalogDiffViewTable.vue create mode 100644 ui/src/helper/diff.ts create mode 100644 ui/src/pages/catalog/CatalogDetailPage.vue create mode 100644 ui/src/pages/catalog/CatalogDiffViewPage.vue create mode 100644 ui/src/pages/catalog/CatalogOverviewPage.vue create mode 100644 ui/src/puppet/models/puppet-catalog.ts diff --git a/ui/src/components/CatalogDetailCard.vue b/ui/src/components/CatalogDetailCard.vue new file mode 100644 index 0000000..2d79793 --- /dev/null +++ b/ui/src/components/CatalogDetailCard.vue @@ -0,0 +1,44 @@ + + + + + diff --git a/ui/src/components/CatalogDiffViewTable.vue b/ui/src/components/CatalogDiffViewTable.vue new file mode 100644 index 0000000..e747975 --- /dev/null +++ b/ui/src/components/CatalogDiffViewTable.vue @@ -0,0 +1,51 @@ + + + + + diff --git a/ui/src/helper/diff.ts b/ui/src/helper/diff.ts new file mode 100644 index 0000000..98be87e --- /dev/null +++ b/ui/src/helper/diff.ts @@ -0,0 +1,75 @@ +export type DiffType = 'same' | 'add' | 'del'; +export type DiffStyle = 'empty' | 'normal' | 'removed' | 'added'; + +export type DiffRow = { + type: DiffType; + oldLine: number | null; + newLine: number | null; + oldItem: T | null; + newItem: T | null; +}; + +export type DiffItem = { + style: DiffStyle; + item: T | null; +}; + + +export function diffObjectsWithoutContext( + a: T[], + b: T[], + keyOf: (item: T) => string +): DiffRow[] { + const bPositions = new Map(); + b.forEach((item, idx) => { + const k = keyOf(item); + const arr = bPositions.get(k) ?? []; + arr.push(idx + 1); + bPositions.set(k, arr); + }); + + const rows: DiffRow[] = []; + const usedB = new Set(); + + // walk a => same or del + a.forEach((item, idx) => { + const k = keyOf(item); + const queue = bPositions.get(k); + + if (queue && queue.length > 0) { + const newLine = queue.shift()!; + usedB.add(newLine); + rows.push({ + type: 'same', + oldLine: idx + 1, + newLine, + oldItem: item, + newItem: b[newLine - 1] ?? null, + }); + } else { + rows.push({ + type: 'del', + oldLine: idx + 1, + newLine: null, + oldItem: item, + newItem: null, + }); + } + }); + + // remaining b => add + b.forEach((item, idx) => { + const newLine = idx + 1; + if (!usedB.has(newLine)) { + rows.push({ + type: 'add', + oldLine: null, + newLine, + oldItem: null, + newItem: item, + }); + } + }); + + return rows; +} diff --git a/ui/src/i18n/langs/de-DE.json b/ui/src/i18n/langs/de-DE.json index 11ac415..25c6218 100644 --- a/ui/src/i18n/langs/de-DE.json +++ b/ui/src/i18n/langs/de-DE.json @@ -90,5 +90,17 @@ "LABEL_AUTO_REFRESH_OFF": "Automatische Aktualisierung aus", "LABEL_REFRESH": "Aktualisieren", "EXPORT_AS_CSV": "Als CSV exportieren", - "ERROR_CSV_EXPORT": "Fehler beim Export als CSV" + "ERROR_CSV_EXPORT": "Fehler beim Export als CSV", + "LABEL_CATALOG_VERSION": "Katalog Version", + "LABEL_PRODUCER_TIMESTAMP": "Erstellungszeitstempel", + "LABEL_CATEGORY": "Kategorie", + "MENU_CATALOGS": "Kataloge", + "LABEL_LOCATION": "Ort", + "LABEL_SOURCE": "Quelle", + "LABEL_AGAINST": "gegen", + "LABEL_EDGE": "Edge", + "LABEL_VERSION": "Version", + "LABEL_ENVIRONMENT": "Umgebung", + "LABEL_COMPARE": "vergleiche", + "LABEL_COMPARE_WITH": "vergleichen mit {certname}" } diff --git a/ui/src/i18n/langs/en-US.json b/ui/src/i18n/langs/en-US.json index 3d16d20..fec7fa6 100644 --- a/ui/src/i18n/langs/en-US.json +++ b/ui/src/i18n/langs/en-US.json @@ -90,5 +90,17 @@ "LABEL_AUTO_REFRESH_OFF": "Auto refresh off", "LABEL_REFRESH": "Refresh", "EXPORT_AS_CSV": "Export as CSV", - "ERROR_CSV_EXPORT": "Error while exporting as CSV" + "ERROR_CSV_EXPORT": "Error while exporting as CSV", + "LABEL_CATALOG_VERSION": "catalog version", + "LABEL_PRODUCER_TIMESTAMP": "producer timestamp", + "LABEL_CATEGORY": "category", + "MENU_CATALOGS": "Catalogs", + "LABEL_LOCATION": "location", + "LABEL_SOURCE": "source", + "LABEL_AGAINST": "against", + "LABEL_EDGE": "edge", + "LABEL_VERSION": "version", + "LABEL_ENVIRONMENT": "environment", + "LABEL_COMPARE": "compare", + "LABEL_COMPARE_WITH": "compare with {certname}" } diff --git a/ui/src/layouts/MainLayout.vue b/ui/src/layouts/MainLayout.vue index 4c91715..47d3ab1 100644 --- a/ui/src/layouts/MainLayout.vue +++ b/ui/src/layouts/MainLayout.vue @@ -66,6 +66,15 @@ {{ $t('MENU_REPORTS') }} + + + + + + + {{ $t('MENU_CATALOGS') }} + + - + +import { useRoute } from 'vue-router'; +import { onMounted, ref } from 'vue'; +import { + type ApiPuppetCatalog, + PuppetCatalog, +} from 'src/puppet/models/puppet-catalog'; +import Backend from 'src/client/backend'; +import PqlQuery, { PqlEntity } from 'src/puppet/query-builder'; +import NodeLink from 'components/NodeLink.vue'; + +const route = useRoute(); +const certname = route.params.certname!.toString(); +const isLoading = ref(true); +const tab = ref('resources'); +const catalog = ref(); + +function loadCatalog() { + const query = new PqlQuery(PqlEntity.Catalogs); + query.filter().and().equal('certname', certname); + void Backend.getQueryResult(query) + .then((result) => { + if (result.status === 200) { + console.log(result.data.Data.Data); + catalog.value = PuppetCatalog.fromApi(result.data.Data.Data[0]!); + } + }) + .finally(() => { + isLoading.value = false; + }); +} + +onMounted(() => { + loadCatalog(); +}); + + + + + diff --git a/ui/src/pages/catalog/CatalogDiffViewPage.vue b/ui/src/pages/catalog/CatalogDiffViewPage.vue new file mode 100644 index 0000000..ca078f4 --- /dev/null +++ b/ui/src/pages/catalog/CatalogDiffViewPage.vue @@ -0,0 +1,249 @@ + + + + + diff --git a/ui/src/pages/catalog/CatalogOverviewPage.vue b/ui/src/pages/catalog/CatalogOverviewPage.vue new file mode 100644 index 0000000..09eb453 --- /dev/null +++ b/ui/src/pages/catalog/CatalogOverviewPage.vue @@ -0,0 +1,214 @@ + + + + + diff --git a/ui/src/puppet/models/puppet-catalog.ts b/ui/src/puppet/models/puppet-catalog.ts new file mode 100644 index 0000000..536635f --- /dev/null +++ b/ui/src/puppet/models/puppet-catalog.ts @@ -0,0 +1,50 @@ +import { autoImplement } from 'src/helper/functions'; + +export interface ApiPuppetCatalog { + certname: string; + version: string; + environment: string; + hash: string; + transaction_uuid: string; + code_id: string; + producer_timestamp: string; // time.Time -> string (ISO timestamp) + producer: string; + resources: CatalogResource; + edges: CatalogEdge; +} + +export interface CatalogResource { + href: string; + data: CatalogResourceData[]; +} + +export interface CatalogResourceData { + certname: string; + resource: string; + type: string; + title: string; + exported: boolean; + tags: string[]; + file: string; + line: number; + parameters: unknown; +} + +export interface CatalogEdge { + href: string; + data: CatalogEdgeData[]; +} + +export interface CatalogEdgeData { + relationship: string; + source_title: string; + source_type: string; + target_title: string; + target_type: string; +} + +export class PuppetCatalog extends autoImplement() { + static fromApi(apiItem: ApiPuppetCatalog): PuppetCatalog { + return new PuppetCatalog(apiItem); + } +} diff --git a/ui/src/router/routes.ts b/ui/src/router/routes.ts index e10ade1..4ccd963 100644 --- a/ui/src/router/routes.ts +++ b/ui/src/router/routes.ts @@ -46,6 +46,21 @@ const routes: RouteRecordRaw[] = [ path: 'report/:certname/:report_hash', component: () => import('pages/report/ReportDetailPage.vue'), }, + { + name: 'CatalogOverview', + path: 'catalogs', + component: () => import('pages/catalog/CatalogOverviewPage.vue'), + }, + { + name: 'CatalogDetail', + path: 'catalog/:certname', + component: () => import('pages/catalog/CatalogDetailPage.vue'), + }, + { + name: 'CatalogDiffView', + path: 'catalog/diff/:source/with/:against', + component: () => import('pages/catalog/CatalogDiffViewPage.vue'), + }, { name: 'PredefinedViewResult', path: 'view/:viewName',