controls/job-historical-grid.ps1
function New-JobHistoricalGrid { param($Identity, $Script) New-UDGrid -Id "JobHistoricalGrid" -Title "Historical Jobs" -Headers @("Id", "Script", "Status", "Started", "Duration", "Executed By","Actions") -Properties @("Id", "Script", "Status", "StartTime", "Duration", "ExecutedBy","Actions") -Endpoint { $OrderDirection = 'Descending' if ($SortAscending) { $OrderDirection = 'Ascending' } $Jobs = Get-UAJob -Status "Historical" -OrderBy $SortColumn -OrderDirection "Descending" -Skip $Skip -First $Take -IncludeTotalCount $Total = $Jobs | Select-Object -First 1 $Jobs = $Jobs | Select-Object -Skip 1 $Jobs | ForEach-Object { $Job = $_ $Identity = Get-UAIdentity -Id $_.Identity.Id $Script = Get-UAScript -Id $_.Script.Id $JobStatus = $_.Status $JobOutput = Get-UAJobOutput -JobId $_.Id if(($JobStatus -ne "Running") -and ($JobStatus -ne "WaitingOnFeedback") -and ($JobStatus -ne "Queued")) { $OutputButton = if($null -ne $JobOutput) { New-UDButton -Text "" -Icon envelope_open -OnClick { New-UDJobOutputModal -Job $Job } } else { "N/A" } $ViewJobButton = New-UDButton -Text "" -Icon folder -OnClick { Invoke-UDRedirect -Url "/job/$($Job.Id)" } $ActionButtons = New-UDElement -Tag div -Content{ New-UDTooltip -Content{$ViewJobButton} -TooltipContent {"Open Job Page"} " " New-UDTooltip -Content{$OutputButton} -TooltipContent {"View Job Output"} } [PSCustomObject]@{ Id = New-UDLink -Text $_.Id -Url "/job/$($_.Id)" Script = New-UDLink -Text $Script.Name -Url "/script/$($Script.Id)" Status = New-UDJobIcon -Job $_ -NoSpan StartTime = $_.StartTime Duration = Format-UASecondsToReadableString -Seconds(($_.EndTime - $_.StartTime).TotalSeconds) ExecutedBy = $Identity.Name Actions = $ActionButtons } } } | Out-UDGridData -TotalItems $Total } -AutoRefresh -DefaultSortColumn "Id" -DefaultSortDescending -ServerSideProcessing } |