controls/script-grid.ps1

function New-ScriptGrid 
{
    param($Identity)

    New-UDStyle -Style "
    margin-top: 10px;
    .card {
        height: 95%;
        margin: 0;
    }
    "
 -Content {
        New-UDSplitPane -MinimumSize 200 -Content {
            New-UDCard -Title "Folders" -Content {
                $RootNode = New-UDTreeNode -Id '1' -Name '/' -Icon folder 
                New-UDTreeView -Node $RootNode -OnNodeClicked {
                    param($Body)
                    $Obj = $Body | ConvertFrom-Json
                    
                    $Session:ScriptTreeNode = $Obj.NodeId
                    Sync-UDElement -Id "ScriptsGrid"
    
                    $Parent = Get-UAFolder -Id $Obj.NodeId
                    Get-UAFolder -Parent $Parent| ForEach-Object {
                        New-UDTreeNode -Id $_.Id -Name $_.Name -Icon folder
                    }
                }
            } 
    
            New-UDGrid -Id "ScriptsGrid" -Title "Scripts" -Headers @("Id", "Name", "Tags", "Created", "Manual Time", "Created By", "Has Schedule", "Actions") -Properties @("Id", "Name", "Tags", "CreatedTime", "ManualTime", "CreatedBy", "IsScheduled", "Actions") -Endpoint {
    
                if ($null -ne $Identity)
                {
                    $Scripts = Get-UAScript -Identity $Identity
                }
                elseif ($null -ne $Session:ScriptTreeNode)
                {
                    $Scripts = Get-UAScript -FolderId $Session:ScriptTreeNode
                }
                else
                {
                    $Scripts = Get-UAScript
                }
                
                $Scripts | ForEach-Object {
                    $Script = $_
                    $CreatedBy = Get-UAIdentity -Id $_.Identity.Id
        
                    $OpenScriptButton = New-UDButton -Icon folder -OnClick {
                        Invoke-UDRedirect -Url "/script/$($Script.Id)"
                    }
                    
                    $RunButton = New-UDButton -Icon play -OnClick {
                            New-UDScriptRunModal -Script $Script
                    }

                    $ScriptHelpButton = New-UDButton -Icon code -OnClick {
                        New-PowerShellHelpModal -Object $Script
                    }

                    if ($null -eq $Session:AuthorizationPolicies -or ($Session:UserRole -eq 'Administrator' -or $Session:UserRole -eq 'Operator'))
                    {
                        $ActionButtons =  New-UDElement -Tag div -Content{
                            New-UDTooltip -Content{$OpenScriptButton} -TooltipContent {"Open Script Page"}
                            " "
                            if ($Script.DisableManualInvocation -ne $true)
                            {
                                New-UDTooltip -Content{$RunButton} -TooltipContent {"Run the Script"}
                                " "
                            }
                            New-UDTooltip -Content{$ScriptHelpButton} -TooltipContent {"View PowerShell Help for Script"}
                        }
                    }
                    else {
                        $ActionButtons = "N/A"
                    }

                    $Schedule = Get-UASchedule -Script $Script

                    if ($null -ne $Schedule)
                    {
                        $IsScheduled = New-UDIcon -Icon check_circle -Color green
                    }
                    else 
                    {
                        $IsScheduled = New-UDIcon -Icon times_circle -Color red
                    }

                    $TagLabelData = New-UDElement -Tag div -Id "TagDiv" -Content {
                        New-ScriptTagHTML -Script $Script
                    }


                    [PSCustomObject]@{
                        Id = $_.Id
                        Name = New-UDLink -Text $_.Name -Url "/script/$($_.Id)"
                        Tags = $TagLabelData
                        CreatedTime = $_.CreatedTime
                        ManualTime = Format-UASecondsToReadableString -Seconds($_.ManualTime)
                        CreatedBy = $CreatedBy.Name
                        IsScheduled = $IsScheduled
                        Actions = $ActionButtons
                        
            
                    }
                } | Out-UDGridData
            }
        }
    }
}