controls/job-grid.ps1

function New-JobGrid {
    param($Identity, $Script)

    New-UDGrid -Id "JobGrid" -Title "Jobs" -Headers @("Id","Script","", "Started", "Duration", "Executed By", "Actions") -Properties @("JobId","Script", "Status", "StartTime", "Duration", "ExecutedBy", "Actions") -Endpoint {
        if ($null -ne $Identity)
        {
            $Jobs = Get-UAJob -ComputerName $ComputerName -Identity $Identity
        }
        elseif ($null -ne $Script)
        {
            $Jobs = Get-UAJob -ComputerName $ComputerName -Script $Script
        }
        else 
        {
            $Jobs = Get-UAJob -ComputerName $ComputerName
        }
        
        $Jobs | ForEach-Object {
            $Job = $_
            $Identity = Get-UAIdentity -Id $_.Identity.Id
            $Script = Get-UAScript -Id $_.Script.Id
            $JobStatus = $Job.Status

            $Feedback = (Get-UAJobFeedback -JobId $Job.id)
                   
            $CancelJobButton = New-UDButton -Text "" -Icon ban -OnClick {
                 New-JobCancelModal -Job $Job
            }

            $ViewJobButton = New-UDButton -Text "" -Icon folder -OnClick {
                Invoke-UDRedirect -Url "/job/$($Job.Id)"
            }

            $ViewFeedBackButton = New-UDButton -Text "" -Icon question -OnClick {
                New-JobFeedbackModal -Job $Job
            } 

            $ScriptHelpButton = New-UDButton -Text "" -Icon code -OnClick {
                New-PowerShellHelpModal -Object $Job
            }

            $ActionControls =  New-UDElement -Tag div -Content{
                New-UDTooltip -Content{$ViewJobButton} -TooltipContent {"Open Job Page"}
                " "
                if(($JobStatus -eq "Running") -or ($JobStatus -eq "WaitingOnFeedback") -or ($JobStatus -eq "Queued"))
                {
                    New-UDTooltip -Content{$CancelJobButton} -TooltipContent {"Cancel the running Job"}
                    " "
                }
                if ($null -ne $Feedback)
                {
                     New-UDTooltip -Content{$ViewFeedBackButton} -TooltipContent {"View Pending Job Feedback"}
                     " "
                }
                New-UDTooltip -Content{$ScriptHelpButton} -TooltipContent {"Open PowerShell Job Help"}
            }
           
    
            [PSCustomObject]@{
                JobId = New-UDLink -Text $Job.Id -Url "/job/$($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 = $ActionControls
            }
        } | Out-UDGridData
    } -AutoRefresh 5
}