switch record preview to list for better readability

This commit is contained in:
2026-08-24 12:56:20 +02:00
parent 2b14bbce85
commit 94a84545f4
@@ -395,27 +395,44 @@ function Show-SearchResults {
[Parameter(Mandatory)] [Parameter(Mandatory)]
[AllowEmptyCollection()] [AllowEmptyCollection()]
[object[]] $Rows [object[]] $Rows,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $Title = 'Matching rows'
) )
if ($Rows.Count -eq 0) { if ($Rows.Count -eq 0) {
Write-Host 'No matching rows.' Write-Host ('{0}: none.' -f $Title)
return return
} }
$displayRows = for ($rowIndex = 0; $rowIndex -lt $Rows.Count; $rowIndex++) { $labelPadding = Get-MaxPadding -Items $Columns
$properties = [ordered]@{ '#' = $rowIndex + 1 }
for ($columnIndex = 0; $columnIndex -lt $Columns.Count; $columnIndex++) {
$column = $Columns[$columnIndex]
$label = '{0} [{1}]' -f $column.value, $column.key
$properties[$label] = ConvertTo-PreviewText -Value $Rows[$rowIndex][$columnIndex]
}
[pscustomobject] $properties
}
Write-Host '' Write-Host ''
Write-Host ('Matching rows: {0} (long values are truncated only in this preview)' -f $Rows.Count) Write-Host ('{0}: {1} (long values are truncated only in this display)' -f $Title, $Rows.Count)
$displayRows | Format-Table -AutoSize | Out-Host for ($rowIndex = 0; $rowIndex -lt $Rows.Count; $rowIndex++) {
Write-Host ('* Row: {0}' -f ($rowIndex + 1))
for ($columnIndex = 0; $columnIndex -lt $Columns.Count; $columnIndex++) {
$column = $Columns[$columnIndex]
$label = '{0} [{1}]{2}' -f $column.value, $column.key, "".PadRight($labelPadding - ($column.value.Length + $column.key.Length + 3), ' ')
$value = ConvertTo-PreviewText -Value $Rows[$rowIndex][$columnIndex] -MaximumLength 90
Write-Host (' {0} : {1}' -f $label, $value)
}
Write-Host '--------------------------------------------------------------------------------'
}
}
function Get-MaxPadding {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[object[]] $Items
)
($Items | ForEach-Object { ('{0} [{1}]' -f $_.value, $_.key).Length }) |
Measure-Object -Maximum |
Select-Object -ExpandProperty Maximum
} }
function Save-SearchBackup { function Save-SearchBackup {
@@ -595,7 +612,7 @@ function Invoke-ElixFormsMetadataBulkUpdate {
throw 'Search reported {0} records but {1} rows were fetched; refusing a partial bulk update.' -f $search.TotalRecords, $search.Rows.Count throw 'Search reported {0} records but {1} rows were fetched; refusing a partial bulk update.' -f $search.TotalRecords, $search.Rows.Count
} }
Show-SearchResults -Columns $search.Columns -Rows $search.Rows Show-SearchResults -Columns $search.Columns -Rows $search.Rows -Title 'Rows to be modified'
if ($search.Rows.Count -eq 0) { if ($search.Rows.Count -eq 0) {
Write-Host 'Nothing to update.' Write-Host 'Nothing to update.'
return return
@@ -634,7 +651,10 @@ function Invoke-ElixFormsMetadataBulkUpdate {
Write-Host ('Backup written before the first save: {0}' -f $backupPath) Write-Host ('Backup written before the first save: {0}' -f $backupPath)
$completed = [Collections.Generic.List[object]]::new() $completed = [Collections.Generic.List[object]]::new()
$completedRows = [Collections.Generic.List[object]]::new()
$failed = [Collections.Generic.List[object]]::new() $failed = [Collections.Generic.List[object]]::new()
$updatedFieldColumnKey = 'S_{0}_{1}' -f $schemaId, $field.Key
$updatedFieldColumnIndex = Get-ColumnIndex -Columns $search.Columns -Key $updatedFieldColumnKey
for ($rowIndex = 0; $rowIndex -lt $search.Rows.Count; $rowIndex++) { for ($rowIndex = 0; $rowIndex -lt $search.Rows.Count; $rowIndex++) {
$row = $search.Rows[$rowIndex] $row = $search.Rows[$rowIndex]
$objectId = [string] $row[$objectIdIndex] $objectId = [string] $row[$objectIdIndex]
@@ -670,6 +690,12 @@ function Invoke-ElixFormsMetadataBulkUpdate {
DataId = $dataId DataId = $dataId
ReturnedValue = $returnedValue ReturnedValue = $returnedValue
}) })
$updatedRow = [object[]]::new(@($row).Count)
[Array]::Copy($row, $updatedRow, $updatedRow.Length)
if ($updatedFieldColumnIndex -ge 0) {
$updatedRow[$updatedFieldColumnIndex] = $newValue
}
$completedRows.Add($updatedRow)
Write-Host (' Saved. Returned value: "{0}"' -f (ConvertTo-PreviewText -Value $returnedValue -MaximumLength 120)) Write-Host (' Saved. Returned value: "{0}"' -f (ConvertTo-PreviewText -Value $returnedValue -MaximumLength 120))
} }
catch { catch {
@@ -685,6 +711,9 @@ function Invoke-ElixFormsMetadataBulkUpdate {
Write-Host '' Write-Host ''
Write-Host ('Update summary: {0} succeeded, {1} failed, {2} not attempted.' -f $completed.Count, $failed.Count, ($search.Rows.Count - $completed.Count - $failed.Count)) Write-Host ('Update summary: {0} succeeded, {1} failed, {2} not attempted.' -f $completed.Count, $failed.Count, ($search.Rows.Count - $completed.Count - $failed.Count))
if ($completedRows.Count -gt 0) {
Show-SearchResults -Columns $search.Columns -Rows $completedRows.ToArray() -Title 'Modified rows'
}
if ($failed.Count -gt 0) { if ($failed.Count -gt 0) {
$failed | Format-Table -AutoSize | Out-Host $failed | Format-Table -AutoSize | Out-Host
Write-Warning ('A partial update may have occurred. Use the backup at {0} to review original values.' -f $backupPath) Write-Warning ('A partial update may have occurred. Use the backup at {0} to review original values.' -f $backupPath)
@@ -693,7 +722,7 @@ function Invoke-ElixFormsMetadataBulkUpdate {
if (Read-YesNo -Prompt 'Re-run the same search to verify the current results?') { if (Read-YesNo -Prompt 'Re-run the same search to verify the current results?') {
$verification = Get-ElixFormsSearchResult -Client $client -BaseUri $BaseUri -Cookie $cookie -SchemaId $schemaId -Filters $filters -PageSize $PageSize $verification = Get-ElixFormsSearchResult -Client $client -BaseUri $BaseUri -Cookie $cookie -SchemaId $schemaId -Filters $filters -PageSize $PageSize
Show-SearchResults -Columns $verification.Columns -Rows $verification.Rows Show-SearchResults -Columns $verification.Columns -Rows $verification.Rows -Title 'Rows returned by verification'
if ($filters.Contains($field.Key)) { if ($filters.Contains($field.Key)) {
Write-Host 'Note: the updated field was a search filter, so changed rows may no longer match.' Write-Host 'Note: the updated field was a search filter, so changed rows may no longer match.'
} }