Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions ui/src/components/CatalogDetailCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<script setup lang="ts">
import { type PuppetCatalog } from 'src/puppet/models/puppet-catalog';
import { useI18n } from 'vue-i18n';

const { t } = useI18n();
const catalog = defineModel<PuppetCatalog>('catalog', { required: true });
const title = defineModel('title', { type: String, required: true });
</script>

<template>
<q-card>
<q-card-section class="bg-primary text-white">
{{ title }}
</q-card-section>
<q-card-section class="q-pa-none">
<q-list>
<q-item>
<q-item-section>
<q-item-label caption>{{ t('LABEL_CERTNAME') }}</q-item-label>
<q-item-label>{{ catalog.certname }}</q-item-label>
</q-item-section>
</q-item>
<q-item>
<q-item-section>
<q-item-label caption>{{
t('LABEL_CATALOG_VERSION')
}}</q-item-label>
<q-item-label>{{ catalog.version }}</q-item-label>
</q-item-section>
</q-item>
<q-item>
<q-item-section>
<q-item-label caption>{{
t('LABEL_PRODUCER_TIMESTAMP')
}}</q-item-label>
<q-item-label>{{ catalog.producer_timestamp }}</q-item-label>
</q-item-section>
</q-item>
</q-list>
</q-card-section>
</q-card>
</template>

<style scoped></style>
51 changes: 51 additions & 0 deletions ui/src/components/CatalogDiffViewTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script setup lang="ts">
import type { DiffItem, DiffStyle } from 'src/helper/diff';

const rows = defineModel<DiffItem<unknown>[]>('rows')

function getDiffChar(style: DiffStyle) {
switch (style) {
case 'empty':
return '';
case 'normal':
return '';
case 'removed':
return '-';
case 'added':
return '+';
}
}

function getDiffColor(style: DiffStyle) {
const textColor = 'black';

switch (style) {
case 'empty':
return `bg-red-3 text-${textColor}`;
case 'normal':
return '';
case 'removed':
return `bg-red-3 text-${textColor}`;
case 'added':
return `bg-green-3 text-${textColor}`;
}
}

</script>

<template>
<q-markup-table>
<tbody>
<tr
v-for="(row, index) in rows"
:key="index"
:class="getDiffColor(row.style)"
>
<td>{{ getDiffChar(row.style) }}</td>
<slot name="columns" :row="row"></slot>
</tr>
</tbody>
</q-markup-table>
</template>

<style scoped></style>
75 changes: 75 additions & 0 deletions ui/src/helper/diff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
export type DiffType = 'same' | 'add' | 'del';
export type DiffStyle = 'empty' | 'normal' | 'removed' | 'added';

export type DiffRow<T> = {
type: DiffType;
oldLine: number | null;
newLine: number | null;
oldItem: T | null;
newItem: T | null;
};

export type DiffItem<T> = {
style: DiffStyle;
item: T | null;
};


export function diffObjectsWithoutContext<T>(
a: T[],
b: T[],
keyOf: (item: T) => string
): DiffRow<T>[] {
const bPositions = new Map<string, number[]>();
b.forEach((item, idx) => {
const k = keyOf(item);
const arr = bPositions.get(k) ?? [];
arr.push(idx + 1);
bPositions.set(k, arr);
});

const rows: DiffRow<T>[] = [];
const usedB = new Set<number>();

// 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;
}
14 changes: 13 additions & 1 deletion ui/src/i18n/langs/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
14 changes: 13 additions & 1 deletion ui/src/i18n/langs/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
11 changes: 10 additions & 1 deletion ui/src/layouts/MainLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@
<q-item-label>{{ $t('MENU_REPORTS') }}</q-item-label>
</q-item-section>
</q-item>
<q-item clickable :to="{ name: 'CatalogOverview' }">
<q-item-section avatar>
<q-icon name="library_books" />
</q-item-section>

<q-item-section>
<q-item-label>{{ $t('MENU_CATALOGS') }}</q-item-label>
</q-item-section>
</q-item>
<q-expansion-item
icon="view_list"
:label="$t('MENU_VIEWS')"
Expand Down Expand Up @@ -111,7 +120,7 @@
</q-drawer>

<q-page-container>
<router-view :key="route.path"/>
<router-view :key="route.path" />
</q-page-container>

<q-page-sticky
Expand Down
111 changes: 111 additions & 0 deletions ui/src/pages/catalog/CatalogDetailPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<script setup lang="ts">
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<PuppetCatalog>();

function loadCatalog() {
const query = new PqlQuery(PqlEntity.Catalogs);
query.filter().and().equal('certname', certname);
void Backend.getQueryResult<ApiPuppetCatalog[]>(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();
});
</script>

<template>
<q-page padding>
<div v-if="!isLoading" class="row">
<div class="col q-pr-md">
<q-card v-if="catalog">
<q-card-section class="bg-primary text-white text-h6">
{{ $t('LABEL_DETAIL', 2) }}
</q-card-section>
<q-card-section class="q-pa-none">
<q-markup-table v-if="certname" flat>
<tbody>
<tr>
<td class="text-left text-bold">Certname</td>
<td class="text-left text-bold">
<NodeLink :certname="certname" />
</td>
</tr>
<tr>
<td class="text-left text-bold">Version</td>
<td class="text-left">
{{ catalog.version }}
</td>
</tr>
<tr>
<td class="text-left text-bold">Transaction UUID</td>
<td class="text-left">
{{ catalog.transaction_uuid }}
</td>
</tr>
<tr v-if="catalog.code_id">
<td class="text-left text-bold">Code ID</td>
<td class="text-left">
{{ catalog.code_id }}
</td>
</tr>
</tbody>
</q-markup-table>
</q-card-section>
</q-card>
<q-card class="q-mt-md">
<q-card-section class="q-pa-none">
<q-tab-panels v-model="tab" v-if="catalog">
<q-tab-panel name="resources" class="q-pa-none">
<q-markup-table v-if="certname" flat>
<thead>
<tr>
<th>{{ $t('LABEL_RESOURCE') }}</th>
<th>{{ $t('LABEL_LOCATION') }}</th>
</tr>
</thead>
<tbody>
<tr
v-for="resource in catalog.resources.data"
:key="resource.title"
>
<td class="text-left">
{{ resource.type }}[{{ resource.title }}]
</td>
<td class="text-left">
{{ resource.file }}:{{ resource.line }}
</td>
</tr>
</tbody>
</q-markup-table>
</q-tab-panel>
</q-tab-panels>
</q-card-section>
</q-card>
</div>
</div>
</q-page>
</template>

<style scoped></style>
Loading
Loading