switch record preview to list for better readability
This commit is contained in:
+44
-15
@@ -395,27 +395,44 @@ function Show-SearchResults {
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[AllowEmptyCollection()]
|
||||
[object[]] $Rows
|
||||
[object[]] $Rows,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string] $Title = 'Matching rows'
|
||||
)
|
||||
|
||||
if ($Rows.Count -eq 0) {
|
||||
Write-Host 'No matching rows.'
|
||||
Write-Host ('{0}: none.' -f $Title)
|
||||
return
|
||||
}
|
||||
|
||||
$displayRows = for ($rowIndex = 0; $rowIndex -lt $Rows.Count; $rowIndex++) {
|
||||
$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
|
||||
}
|
||||
$labelPadding = Get-MaxPadding -Items $Columns
|
||||
|
||||
Write-Host ''
|
||||
Write-Host ('Matching rows: {0} (long values are truncated only in this preview)' -f $Rows.Count)
|
||||
$displayRows | Format-Table -AutoSize | Out-Host
|
||||
Write-Host ('{0}: {1} (long values are truncated only in this display)' -f $Title, $Rows.Count)
|
||||
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 {
|
||||
@@ -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
|
||||
}
|
||||
|
||||
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) {
|
||||
Write-Host 'Nothing to update.'
|
||||
return
|
||||
@@ -634,7 +651,10 @@ function Invoke-ElixFormsMetadataBulkUpdate {
|
||||
Write-Host ('Backup written before the first save: {0}' -f $backupPath)
|
||||
|
||||
$completed = [Collections.Generic.List[object]]::new()
|
||||
$completedRows = [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++) {
|
||||
$row = $search.Rows[$rowIndex]
|
||||
$objectId = [string] $row[$objectIdIndex]
|
||||
@@ -670,6 +690,12 @@ function Invoke-ElixFormsMetadataBulkUpdate {
|
||||
DataId = $dataId
|
||||
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))
|
||||
}
|
||||
catch {
|
||||
@@ -685,6 +711,9 @@ function Invoke-ElixFormsMetadataBulkUpdate {
|
||||
|
||||
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))
|
||||
if ($completedRows.Count -gt 0) {
|
||||
Show-SearchResults -Columns $search.Columns -Rows $completedRows.ToArray() -Title 'Modified rows'
|
||||
}
|
||||
if ($failed.Count -gt 0) {
|
||||
$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)
|
||||
@@ -693,7 +722,7 @@ function Invoke-ElixFormsMetadataBulkUpdate {
|
||||
|
||||
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
|
||||
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)) {
|
||||
Write-Host 'Note: the updated field was a search filter, so changed rows may no longer match.'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user