controls/schedule-grid.ps1

function New-ScheduleGrid 
{
    param($Script)

    New-UDGrid -Id 'schedule-grid' -Title "Schedules" -Headers @("Id","Schedule", "Next Execution Time", "Script", "Actions") -Properties @("Id","Cron", "NextExecution", "Script","Actions") -Endpoint {
        if ($null -ne $Script)
        {
            Get-UASchedule -Script $Script |  ForEach-Object {

                $Schedule = $_

                $CancelButton = New-UDButton -Text "" -Icon ban -OnClick {
                    New-ScheduleRemoveModal -Schedule $Schedule
                }
    
                if ($null -eq $Session:AuthorizationPolicies -or ($Session:UserRole -eq 'Administrator' -or $Session:UserRole -eq 'Operator'))
                {
                    $ActionButtons =  New-UDElement -Tag div -Content{
                        New-UDTooltip -Content{$CancelButton} -TooltipContent {"Remove Schedule"}
                    }
                }
                else {
                    $ActionButtons = "N/A"
                }

                $NextExecution = $_.NextExecution
                if ($_.NextExecution -eq [DateTime]::MinValue.ToString())
                {
                    $NextExecution = "As soon as possible"
                }

                [PSCustomObject]@{
                    Id = $_.Id
                    Cron = $_.Description
                    NextExecution = $NextExecution
                    Script = (New-UDLink -Text $Script.Name -Url "/script/$($Script.Id)")
                    Actions = $ActionButtons
                }
            } |  Out-UDGridData
        }
        else
        {
            Get-UASchedule | ForEach-Object {
                $Script = Get-UAScript -Id ($_.Script.Id)
                $NextExecution = $_.NextExecution
                if ($_.NextExecution -eq [DateTime]::MinValue.ToString())
                {
                    $NextExecution = "As soon as possible"
                }

                [PSCustomObject]@{
                    Id = $_.Id
                    Cron = $_.Description
                    NextExecution = $NextExecution
                    Script = New-UDLink -Text $Script.Name -Url "/script/$($Script.Id)"
                    Actions = ""
                }
            } |  Out-UDGridData
        }
    } -AutoRefresh -RefreshInterval 10
}