From 19e479a08d983adeeb79566b9de06b81e69c856d Mon Sep 17 00:00:00 2001 From: Marco Wende Date: Mon, 19 Oct 2026 13:31:25 +0200 Subject: [PATCH] =?UTF-8?q?Policies:=20Vergleich=20als=20zweispaltige=20Ge?= =?UTF-8?q?gen=C3=BCberstellung=20(A=20|=20B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Statt gestapelter JSON-Blöcke jetzt eine Tabelle: pro settingDefinitionId eine Zeile mit Wert A neben Wert B. Kompakter, lesbarer Kurzwert (Get-SettingDisplayValue: Choice/Simple/Collections) im Vordergrund, volles kanonisches JSON als Tooltip. Status-Einfärbung (unterschiedlich/nur A/nur B/gleich) + Filter "nur Unterschiede". Endpoint liefert dafür vereinheitlichte rows (Union der Keys) mit short/full je Seite. Co-Authored-By: Claude Opus 4.8 --- src/PolicyIO.ps1 | 87 +++++++++++++++++++++++++++++++++++------------- www/app.js | 62 ++++++++++++++++++---------------- www/styles.css | 31 +++++++++-------- 3 files changed, 116 insertions(+), 64 deletions(-) diff --git a/src/PolicyIO.ps1 b/src/PolicyIO.ps1 index efa2746..d947b61 100644 --- a/src/PolicyIO.ps1 +++ b/src/PolicyIO.ps1 @@ -1121,9 +1121,42 @@ function Invoke-PolicyConsolidateEndpoint { # ============================================================ # Zwei Settings-Catalog-Policies vergleichen (Diff nach settingDefinitionId) # ============================================================ -# Body: { ids:[idA, idB] }. Liefert: nur in A / nur in B / gleich / unterschiedlich. -# Nutzt dieselbe Extraktion wie die Konsolidierung (Get-SettingDefinitionId + -# Get-SettingCanonicalJson -> kanonischer Wert-Vergleich). +# Kompakter, lesbarer Wert einer settingInstance (fuer die Gegenueberstellung). +# Best-effort: Choice -> letzte Wert-Komponente, Simple -> Wert, Collections -> Liste/Anzahl. +# Das volle (kanonische) JSON bleibt separat erhalten. +function Get-SettingDisplayValue { + param($SettingElement) + $si = Get-PolicyProp $SettingElement 'settingInstance' + if (-not $si) { $si = $SettingElement } + + $cv = Get-PolicyProp $si 'choiceSettingValue' + if ($cv) { + $v = [string](Get-PolicyProp $cv 'value') + $tail = ($v -split '_')[-1] + $kids = @(Get-PolicyProp $cv 'children') | Where-Object { $_ } + if (@($kids).Count -gt 0) { return "$tail (+$(@($kids).Count) Unter)" } + return $tail + } + $sv = Get-PolicyProp $si 'simpleSettingValue' + if ($sv) { return [string](Get-PolicyProp $sv 'value') } + $scv = @(Get-PolicyProp $si 'simpleSettingCollectionValue') | Where-Object { $_ } + if (@($scv).Count -gt 0) { + $joined = (@($scv | ForEach-Object { [string](Get-PolicyProp $_ 'value') }) -join ', ') + if ($joined.Length -gt 140) { $joined = $joined.Substring(0, 137) + '...' } + return $joined + } + $ccv = @(Get-PolicyProp $si 'choiceSettingCollectionValue') | Where-Object { $_ } + if (@($ccv).Count -gt 0) { + return (@($ccv | ForEach-Object { ([string](Get-PolicyProp $_ 'value') -split '_')[-1] }) -join ', ') + } + $gcv = @(Get-PolicyProp $si 'groupSettingCollectionValue') | Where-Object { $_ } + if (@($gcv).Count -gt 0) { return "$(@($gcv).Count) Gruppe(n)" } + return '' +} + +# Body: { ids:[idA, idB] }. Liefert A/B-Metadaten + vereinheitlichte Zeilen (Union +# der settingDefinitionId), jede mit Status (same|different|onlyA|onlyB) sowie +# Kurzwert und vollem (kanonischem) Wert je Seite - fuer die Gegenueberstellung. function Invoke-PolicyCompareEndpoint { param($Body) try { Assert-GraphConnected } catch { return @{ __status = 401; error = 'Nicht mit Microsoft Graph verbunden' } } @@ -1141,7 +1174,7 @@ function Invoke-PolicyCompareEndpoint { if (-not $el) { continue } $defId = Get-SettingDefinitionId $el if (-not $defId) { continue } - $map[$defId] = Get-SettingCanonicalJson $el + $map[$defId] = @{ canon = Get-SettingCanonicalJson $el; short = Get-SettingDisplayValue $el } } $pols += @{ id = [string]$id @@ -1153,28 +1186,36 @@ function Invoke-PolicyCompareEndpoint { } $a = $pols[0]; $b = $pols[1] - $onlyA = @(); $onlyB = @(); $same = @(); $different = @() - foreach ($k in @($a.map.Keys)) { - if ($b.map.Contains($k)) { - if ($a.map[$k] -eq $b.map[$k]) { $same += @{ settingDefinitionId = $k; value = $a.map[$k] } } - else { $different += @{ settingDefinitionId = $k; valueA = $a.map[$k]; valueB = $b.map[$k] } } - } else { - $onlyA += @{ settingDefinitionId = $k; value = $a.map[$k] } - } - } - foreach ($k in @($b.map.Keys)) { - if (-not $a.map.Contains($k)) { $onlyB += @{ settingDefinitionId = $k; value = $b.map[$k] } } + # Union der Keys: A-Reihenfolge, dann die nur in B vorhandenen anhaengen. + $keys = [System.Collections.Generic.List[string]]::new() + foreach ($k in @($a.map.Keys)) { [void]$keys.Add([string]$k) } + foreach ($k in @($b.map.Keys)) { if (-not $a.map.Contains($k)) { [void]$keys.Add([string]$k) } } + + $rows = @() + $cDiff = 0; $cOnlyA = 0; $cOnlyB = 0; $cSame = 0 + foreach ($k in $keys) { + $inA = $a.map.Contains($k); $inB = $b.map.Contains($k) + $ea = $null; $eb = $null + if ($inA) { $ea = $a.map[$k] } + if ($inB) { $eb = $b.map[$k] } + + $status = '' + if ($inA -and $inB) { + if ($ea.canon -eq $eb.canon) { $status = 'same'; $cSame++ } else { $status = 'different'; $cDiff++ } + } elseif ($inA) { $status = 'onlyA'; $cOnlyA++ } else { $status = 'onlyB'; $cOnlyB++ } + + $row = [ordered]@{ id = $k; status = $status } + if ($inA) { $row['shortA'] = $ea.short; $row['fullA'] = $ea.canon } + if ($inB) { $row['shortB'] = $eb.short; $row['fullB'] = $eb.canon } + $rows += $row } return @{ - ok = $true - a = @{ id = $a.id; name = $a.name; platform = $a.platform; count = $a.count } - b = @{ id = $b.id; name = $b.name; platform = $b.platform; count = $b.count } - onlyA = @($onlyA) - onlyB = @($onlyB) - same = @($same) - different = @($different) - counts = @{ onlyA = @($onlyA).Count; onlyB = @($onlyB).Count; same = @($same).Count; different = @($different).Count } + ok = $true + a = @{ id = $a.id; name = $a.name; platform = $a.platform; count = $a.count } + b = @{ id = $b.id; name = $b.name; platform = $b.platform; count = $b.count } + rows = @($rows) + counts = @{ different = $cDiff; onlyA = $cOnlyA; onlyB = $cOnlyB; same = $cSame } } } diff --git a/www/app.js b/www/app.js index fc68c8b..cc5c80f 100644 --- a/www/app.js +++ b/www/app.js @@ -6619,6 +6619,7 @@ document.getElementById('polConsConfirm')?.addEventListener('click', polDoConsol // Policies vergleichen (zwei Settings-Catalog-Policies -> Diff) // ============================================================= let _polCmpResult = null; +let _polCmpOnlyDiff = false; async function openPolCompare() { const keys = [...PolState.selected].filter(k => k.startsWith('settingscatalog::')); @@ -6645,48 +6646,53 @@ function polCmpShortId(id) { return `${escapeHtml(tail)} ${escapeHtml(s)}`; } -function polCmpVal(v) { - return `${escapeHtml(String(v ?? ''))}`; +// Eine Wert-Zelle (Kurzwert sichtbar, volles JSON als Tooltip). Leer = „—". +function polCmpCell(short, full, extraCls) { + if (short == null && full == null) return '
—
'; + const s = (short === '' || short == null) ? '∅' : short; + return `
${escapeHtml(s)}
`; } function renderPolCompare(res) { + _polCmpResult = res; const c = res.counts || {}; + const aName = res.a?.name || 'A', bName = res.b?.name || 'B'; + document.getElementById('polCmpSummary').innerHTML = - `
` - + `
A: ${escapeHtml(res.a?.name || '—')} (${res.a?.count ?? 0} Settings · ${escapeHtml(res.a?.platform || '')})
` - + `
B: ${escapeHtml(res.b?.name || '—')} (${res.b?.count ?? 0} Settings · ${escapeHtml(res.b?.platform || '')})
` - + `
` - + `
` + `
` + `${c.different || 0} unterschiedlich` + `${c.onlyA || 0} nur in A` + `${c.onlyB || 0} nur in B` + `${c.same || 0} gleich` + + `` + + `
`; + const cb = document.getElementById('polCmpOnlyDiff'); + if (cb) cb.onchange = () => { _polCmpOnlyDiff = cb.checked; renderPolCompare(_polCmpResult); }; + + const rows = (res.rows || []).filter(r => _polCmpOnlyDiff ? r.status !== 'same' : true); + + const header = + `
` + + `
Einstellung (${(res.rows || []).length})
` + + `
A · ${escapeHtml(aName)}
` + + `
B · ${escapeHtml(bName)}
` + `
`; - const sect = (title, cls, rows) => rows.length - ? `
${title} (${rows.length})
${rows.join('')}
` - : ''; + const bodyRows = rows.map(r => { + const diffCls = r.status === 'different' ? 'diff' : ''; + return `
` + + `
${polCmpShortId(r.id)}
` + + polCmpCell(r.shortA, r.fullA, diffCls) + + polCmpCell(r.shortB, r.fullB, diffCls) + + `
`; + }).join(''); - const diffRows = (res.different || []).map(r => - `
${polCmpShortId(r.settingDefinitionId)}` - + `
A ${polCmpVal(r.valueA)}` - + `B ${polCmpVal(r.valueB)}
`); - const onlyARows = (res.onlyA || []).map(r => - `
${polCmpShortId(r.settingDefinitionId)} ${polCmpVal(r.value)}
`); - const onlyBRows = (res.onlyB || []).map(r => - `
${polCmpShortId(r.settingDefinitionId)} ${polCmpVal(r.value)}
`); - const sameRows = (res.same || []).map(r => - `
${polCmpShortId(r.settingDefinitionId)} ${polCmpVal(r.value)}
`); - - document.getElementById('polCmpBody').innerHTML = - sect('Unterschiedlich', 'diff', diffRows) - + sect('Nur in A', 'a', onlyARows) - + sect('Nur in B', 'b', onlyBRows) - + sect('Gleich', 'same', sameRows) - || '
Keine Einstellungen zum Vergleichen.
'; + document.getElementById('polCmpBody').innerHTML = rows.length + ? `
${header}${bodyRows}
` + : '
Keine Einstellungen (mit aktivem Filter).
'; document.getElementById('polCmpInfo').textContent = - `${(res.a?.count ?? 0)} ↔ ${(res.b?.count ?? 0)} Settings`; + `A: ${res.a?.count ?? 0} · B: ${res.b?.count ?? 0} Settings`; } document.getElementById('btnPolCompare')?.addEventListener('click', openPolCompare); diff --git a/www/styles.css b/www/styles.css index 8b03401..58b3c59 100644 --- a/www/styles.css +++ b/www/styles.css @@ -5499,20 +5499,25 @@ body.read-only .app-row { .pol-cmp-badge.a { background: rgba(96,165,250,.15); color: #60a5fa; } .pol-cmp-badge.b { background: rgba(167,139,250,.15); color: #a78bfa; } .pol-cmp-badge.same { background: rgba(74,222,128,.15); color: #4ade80; } -.pol-cmp-sect { margin-top: 12px; } -.pol-cmp-sect-h { font-weight: 600; font-size: 12.5px; padding: 4px 8px; border-radius: 6px; margin-bottom: 4px; background: var(--hairline-soft); } -.pol-cmp-sect-h.diff { background: rgba(251,191,36,.12); color: #fbbf24; } -.pol-cmp-sect-h.a { background: rgba(96,165,250,.12); color: #60a5fa; } -.pol-cmp-sect-h.b { background: rgba(167,139,250,.12); color: #a78bfa; } -.pol-cmp-sect-h.same { background: rgba(74,222,128,.12); color: #4ade80; } -.pol-cmp-row { padding: 5px 8px; border-bottom: 1px solid var(--hairline-soft, rgba(255,255,255,.06)); font-size: 12.5px; } -.pol-cmp-row:last-child { border-bottom: 0; } +.pol-cmp-filter { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; } .pol-cmp-id { display: inline-block; } -.pol-cmp-id .muted { font-size: 11px; word-break: break-all; } -.pol-cmp-val { display: inline-block; font-size: 11.5px; background: var(--bg3, var(--hover)); padding: 1px 6px; border-radius: 4px; word-break: break-all; } -.pol-cmp-ab { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 3px; } -.pol-cmp-side { flex: 1 1 240px; } -.pol-cmp-side b { color: var(--text-dim, #888); margin-right: 4px; } +.pol-cmp-id .muted { font-size: 10.5px; word-break: break-all; } +/* Zweispaltige Gegenueberstellung A | B */ +.pol-cmp-table { display: grid; grid-template-columns: minmax(200px, 1.5fr) 1fr 1fr; border: 1px solid var(--hairline, #333); border-radius: 8px; overflow: hidden; font-size: 12px; } +.pol-cmp-trow { display: contents; } +.pol-cmp-trow > div { padding: 6px 8px; border-bottom: 1px solid var(--hairline-soft, rgba(255,255,255,.06)); min-width: 0; } +.pol-cmp-trow.head > div { position: sticky; top: 0; background: var(--bg3, var(--hover)); font-weight: 600; z-index: 1; } +.pol-cmp-trow.head .col-a { color: #60a5fa; } +.pol-cmp-trow.head .col-b { color: #a78bfa; } +.pol-cmp-setting { background: var(--canvas); } +.pol-cmp-c { word-break: break-all; } +.pol-cmp-c.empty { color: var(--muted, #777); text-align: center; } +.pol-cmp-c.diff { background: rgba(251,191,36,.12); color: #fbbf24; font-weight: 600; } +/* Zeilen-Einfaerbung nach Status (dezent) */ +.pol-cmp-trow.onlyA .pol-cmp-setting { box-shadow: inset 3px 0 0 #60a5fa; } +.pol-cmp-trow.onlyB .pol-cmp-setting { box-shadow: inset 3px 0 0 #a78bfa; } +.pol-cmp-trow.different .pol-cmp-setting { box-shadow: inset 3px 0 0 #fbbf24; } +.pol-cmp-trow.same .pol-cmp-c { color: var(--text-dim, #999); } .pol-cons-src { margin: 6px 0 0; padding-left: 18px; font-size: 12px; } .pol-cons-src li { margin: 1px 0; } .pol-cons-conf-head { margin: 14px 0 6px; font-weight: 600; font-size: 13px; }