controls/job-active-script-grid.ps1

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

    New-UDGrid -Id ("JobGrid"+$($Script.Id)+"Active") -Title "Jobs" -Headers @("Id","Script","", "Started", "Duration", "Executed By", "Actions") -Properties @("JobId","Script", "Status", "StartTime", "Duration", "ExecutedBy", "Actions") -Endpoint {

        $OrderDirection = 'Descending'
        if ($SortAscending)
        {
            $OrderDirection = 'Ascending'
        }

        if ($null -ne $Script)
        {
            $Jobs = Get-UAJob -Script $Script -Status "Active" -OrderBy $SortColumn -OrderDirection $OrderDirection -Skip $Skip -First $Take -IncludeTotalCount
        }
        else 
        {
            $Jobs = Get-UAJob -Status "Active" -OrderBy $SortColumn -OrderDirection $OrderDirection -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 = $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"}
            }
           
            if(($JobStatus -eq "Running") -or ($JobStatus -eq "WaitingOnFeedback") -or ($JobStatus -eq "Queued"))
            {
                $Duration = Format-UASecondsToReadableString -Seconds(((Get-Date) - $_.StartTime).TotalSeconds)
            }
            else {
                $Duration = Format-UASecondsToReadableString -Seconds(($_.EndTime - $_.StartTime).TotalSeconds)
            }
            
            [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 #todo don't show jan 0 0 0 0 when not started
                Duration = $Duration
                ExecutedBy = $Identity.Name
                Actions = $ActionControls
            }
        } | Out-UDGridData -TotalItems $Total
    } -AutoRefresh -DefaultSortColumn "Id" -ServerSideProcessing
}