controls/job-running-grid.ps1

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

    New-UDGrid -Id "JobRunningGrid" -Title "Running Jobs" -Headers @("Id","Script","", "Started", "Duration", "Executed By", "Actions") -Properties @("Id","Script", "Status", "StartTime", "Duration", "ExecutedBy", "Actions") -Endpoint {
        
        $OrderDirection = 'Descending'
        if ($SortAscending)
        {
            $OrderDirection = 'Ascending'
        }


        $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 {
            $Identity = Get-UAIdentity -Id $_.Identity.Id
            $Script = Get-UAScript -Id $_.Script.Id
            $Job = $_
            $JobStatus = $_.Status
            

            if(($JobStatus -eq "Running") -or ($JobStatus -eq "WaitingOnFeedback") -or ($JobStatus -eq "Queued"))
            {
                $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
                } 
                

                $ActionControls =  New-UDElement -Tag div -Content{
                    New-UDTooltip -Content{$ViewJobButton} -TooltipContent {"Open Job Page"}
                    " "
                    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{$OutputButton} -TooltipContent {"View Job Output"}

                [PSCustomObject]@{
                    Id = New-UDLink -Text $Job.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(((Get-Date) - $_.StartTime).TotalSeconds)
                    ExecutedBy = $Identity.Name
                    Actions = $ActionControls
                } 
            } 
            
        } | Out-UDGridData -TotalItems $Total
    } -AutoRefresh -DefaultSortColumn "Id" -DefaultSortDescending -RefreshInterval 10 -ServerSideProcessing
}