Policies: Vergleich zweier Settings-Catalog-Policies (Diff)
Neuer Button "Vergleichen" (aktiv bei genau 2 Settings-Catalog-Policies) + Endpoint POST /api/policies/compare. Diff nach settingDefinitionId über die vorhandene Extraktion (Get-SettingDefinitionId/Get-SettingCanonicalJson): nur in A / nur in B / gleich / unterschiedlich (Werte gegenübergestellt). Modal mit Zählern + Abschnitten, Diff als JSON exportierbar. Read-only. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
40e26b9f32
commit
e35005e489
5 files changed
+202
-3
No files matched your search
+95
-3
@@ -6426,14 +6426,24 @@ function polUpdateSelCount() {
|
||||
if (c) c.textContent = n;
|
||||
}
|
||||
// Konsolidieren nur bei >=2 Policies UND alle vom Typ Settings Catalog.
|
||||
const allSc = keys.every(k => k.startsWith('settingscatalog::'));
|
||||
const btnC = document.getElementById('btnPolConsolidate');
|
||||
if (btnC) {
|
||||
const allSc = n >= 2 && keys.every(k => k.startsWith('settingscatalog::'));
|
||||
btnC.disabled = !allSc;
|
||||
btnC.title = allSc
|
||||
const ok = n >= 2 && allSc;
|
||||
btnC.disabled = !ok;
|
||||
btnC.title = ok
|
||||
? 'Ausgewählte Settings-Catalog-Policies zu einer neuen Policy zusammenführen'
|
||||
: 'Mindestens zwei Policies vom Typ „Settings Catalog" auswählen';
|
||||
}
|
||||
// Vergleichen: genau 2 Settings-Catalog-Policies.
|
||||
const btnCmp = document.getElementById('btnPolCompare');
|
||||
if (btnCmp) {
|
||||
const ok = n === 2 && allSc;
|
||||
btnCmp.disabled = !ok;
|
||||
btnCmp.title = ok
|
||||
? 'Die zwei ausgewählten Settings-Catalog-Policies vergleichen'
|
||||
: 'Genau zwei Policies vom Typ „Settings Catalog" auswählen';
|
||||
}
|
||||
}
|
||||
|
||||
function polSyncCheckAll() {
|
||||
@@ -6605,6 +6615,88 @@ async function polDoConsolidate() {
|
||||
document.getElementById('btnPolConsolidate')?.addEventListener('click', openPolConsolidate);
|
||||
document.getElementById('polConsConfirm')?.addEventListener('click', polDoConsolidate);
|
||||
|
||||
// =============================================================
|
||||
// Policies vergleichen (zwei Settings-Catalog-Policies -> Diff)
|
||||
// =============================================================
|
||||
let _polCmpResult = null;
|
||||
|
||||
async function openPolCompare() {
|
||||
const keys = [...PolState.selected].filter(k => k.startsWith('settingscatalog::'));
|
||||
if (keys.length !== 2) { toast('Genau zwei Settings-Catalog-Policies auswählen.', 'warn'); return; }
|
||||
const ids = keys.map(k => k.slice('settingscatalog::'.length));
|
||||
_polCmpResult = null;
|
||||
document.getElementById('polCmpSummary').innerHTML = '<span class="spinner" style="width:14px;height:14px;border-width:2px;"></span> Vergleiche…';
|
||||
document.getElementById('polCmpBody').innerHTML = '';
|
||||
document.getElementById('polCmpInfo').textContent = '';
|
||||
openModal('modalPolCompare');
|
||||
try {
|
||||
const res = await api('/api/policies/compare', { method: 'POST', body: { ids }, timeoutMs: 120000 });
|
||||
_polCmpResult = res;
|
||||
renderPolCompare(res);
|
||||
} catch (e) {
|
||||
document.getElementById('polCmpSummary').innerHTML = `<span class="pol-cons-err">Vergleich fehlgeschlagen: ${escapeHtml(e.message)}</span>`;
|
||||
}
|
||||
}
|
||||
|
||||
// settingDefinitionId lesbarer machen: letztes Segment hervorheben.
|
||||
function polCmpShortId(id) {
|
||||
const s = String(id || '');
|
||||
const tail = s.split(/[_~\.]/).filter(Boolean).pop() || s;
|
||||
return `<span class="pol-cmp-id" title="${escapeHtml(s)}"><b>${escapeHtml(tail)}</b> <span class="muted">${escapeHtml(s)}</span></span>`;
|
||||
}
|
||||
|
||||
function polCmpVal(v) {
|
||||
return `<code class="pol-cmp-val">${escapeHtml(String(v ?? ''))}</code>`;
|
||||
}
|
||||
|
||||
function renderPolCompare(res) {
|
||||
const c = res.counts || {};
|
||||
document.getElementById('polCmpSummary').innerHTML =
|
||||
`<div class="pol-cmp-head">`
|
||||
+ `<div><b>A:</b> ${escapeHtml(res.a?.name || '—')} <span class="muted">(${res.a?.count ?? 0} Settings · ${escapeHtml(res.a?.platform || '')})</span></div>`
|
||||
+ `<div><b>B:</b> ${escapeHtml(res.b?.name || '—')} <span class="muted">(${res.b?.count ?? 0} Settings · ${escapeHtml(res.b?.platform || '')})</span></div>`
|
||||
+ `</div>`
|
||||
+ `<div class="pol-cmp-counts">`
|
||||
+ `<span class="pol-cmp-badge diff">${c.different || 0} unterschiedlich</span>`
|
||||
+ `<span class="pol-cmp-badge a">${c.onlyA || 0} nur in A</span>`
|
||||
+ `<span class="pol-cmp-badge b">${c.onlyB || 0} nur in B</span>`
|
||||
+ `<span class="pol-cmp-badge same">${c.same || 0} gleich</span>`
|
||||
+ `</div>`;
|
||||
|
||||
const sect = (title, cls, rows) => rows.length
|
||||
? `<div class="pol-cmp-sect"><div class="pol-cmp-sect-h ${cls}">${title} (${rows.length})</div>${rows.join('')}</div>`
|
||||
: '';
|
||||
|
||||
const diffRows = (res.different || []).map(r =>
|
||||
`<div class="pol-cmp-row diff">${polCmpShortId(r.settingDefinitionId)}`
|
||||
+ `<div class="pol-cmp-ab"><span class="pol-cmp-side"><b>A</b> ${polCmpVal(r.valueA)}</span>`
|
||||
+ `<span class="pol-cmp-side"><b>B</b> ${polCmpVal(r.valueB)}</span></div></div>`);
|
||||
const onlyARows = (res.onlyA || []).map(r =>
|
||||
`<div class="pol-cmp-row">${polCmpShortId(r.settingDefinitionId)} ${polCmpVal(r.value)}</div>`);
|
||||
const onlyBRows = (res.onlyB || []).map(r =>
|
||||
`<div class="pol-cmp-row">${polCmpShortId(r.settingDefinitionId)} ${polCmpVal(r.value)}</div>`);
|
||||
const sameRows = (res.same || []).map(r =>
|
||||
`<div class="pol-cmp-row">${polCmpShortId(r.settingDefinitionId)} ${polCmpVal(r.value)}</div>`);
|
||||
|
||||
document.getElementById('polCmpBody').innerHTML =
|
||||
sect('Unterschiedlich', 'diff', diffRows)
|
||||
+ sect('Nur in A', 'a', onlyARows)
|
||||
+ sect('Nur in B', 'b', onlyBRows)
|
||||
+ sect('Gleich', 'same', sameRows)
|
||||
|| '<div class="muted">Keine Einstellungen zum Vergleichen.</div>';
|
||||
|
||||
document.getElementById('polCmpInfo').textContent =
|
||||
`${(res.a?.count ?? 0)} ↔ ${(res.b?.count ?? 0)} Settings`;
|
||||
}
|
||||
|
||||
document.getElementById('btnPolCompare')?.addEventListener('click', openPolCompare);
|
||||
document.getElementById('polCmpExport')?.addEventListener('click', () => {
|
||||
if (!_polCmpResult) return;
|
||||
const a = (_polCmpResult.a?.name || 'A').replace(/[^a-zA-Z0-9_-]/g, '_');
|
||||
const b = (_polCmpResult.b?.name || 'B').replace(/[^a-zA-Z0-9_-]/g, '_');
|
||||
polDownloadJson(_polCmpResult, `policy-compare-${a}-vs-${b}.json`);
|
||||
});
|
||||
|
||||
// Datei-Inhalt -> Liste von Envelopes { exportType, policy, ... }
|
||||
function polExtractEnvelopes(parsed, fileName) {
|
||||
if (parsed && Array.isArray(parsed.policies)) return parsed.policies;
|
||||
|
||||
Reference in new issue
Block a user