pages/script.ps1

New-UDPage -Url "script/:scriptid" -Id "scriptdetails-page" -Endpoint {
    param($ScriptId)

    Try{
        $Session:AuthorizationPolicies = Get-UDAuthorizationPolicy -ErrorAction Continue
        $Session:UserRole = (Get-UAIdentity -Name ($User)).Role.Name
    }
    Catch{
        $Session:AuthorizationPolicies = $null
    }
    

    $Script = Get-UAScript -Id $ScriptId
    $ScriptTags = Get-UAScriptTag -Script $Script
    $PowerShellVersions = Get-UAPowerShellVersion
    $Parameters = Get-UAScriptParameter -ScriptId $ScriptId
    $AllowManualInvocation = if ($Script.DisableManualInvocation -eq $true) {$false} else {$true}

    New-UDHelmet -Content {
        New-UDHtmlTag -Tag 'title' -Content { "Universal Automation / Scripts / $($Script.Name)" }
    }
    
    New-UDRow -Columns {
        New-UDColumn -Size 6 -Content {
            #New-UDIcon -Icon file
            New-UDPageHeader -Text $Script.Name -Id "ScriptPageHeader"

                #New-UDElement -Tag div -Content { "Script ID: $($Script.Id)"}
                New-UDHtml -Markup ("<b>Script ID</b>: $($Script.Id)")
                if($null -ne $Script.Description)
                {
                    New-UDElement -Tag div -Content { "Description: $($Script.Description)"}
                }
    
                New-UDTooltip -Content {
                    New-UDElement -Tag div -Content { "Commit ID: $($Script.CommitId.Substring(0, 7))"}
                } -TooltipContent {
                    $Script.CommitId
                }
                #New-UDElement -Tag div -Content { "Created: $($Script.CreatedTime)"}
                New-UDHtml -Markup ("<b>Created</b>: $($Script.CreatedTime)")

                if($null -ne $Script.ManualTime -and $Script.ManualTime -ne 0)
                {
                    New-UDElement -Tag div -Content { 
                        $ManualTime = Format-UASecondsToReadableString -Seconds $($Script.ManualTime)
                        New-UDHtml -Markup ("<b>Manual Time</b>: $ManualTime") 
                    }
                }

                New-UDElement -Tag div -Id "ScriptPageTagDiv" -Attributes @{
                    float = "left"
                    paddingLeft = "10px"
                } -Content {
                    New-UDElement -Tag b  -Content {
                        "Tags: "
                        New-ScriptTagHTML -Script $Script -UseToolTip $True
                        if($null -eq $Session:AuthorizationPolicies -or ($Session:UserRole -eq "Administrator" -or $Session:UserRole -eq "Operator"))
                        {
                            New-UDIconButton -Icon (New-UDIcon -Icon "Plus" -Color "#4452B8") -OnClick{
                                New-UDAddTagModal -Script $Script
                            }
                        }
                    }
                }
        }
        New-UDColumn -Size 6 -Content {
            New-UDElement -Tag div -Attributes @{
                textAlign = 'right'
                width = '100cw'
            } -Content {

                if($null -eq $Session:AuthorizationPolicies -or ($Session:UserRole -eq "Administrator" -or $Session:UserRole -eq "Operator"))
                {

                    if($AllowManualInvocation -eq $true)
                    {
                        New-UDPadding -Padding '5px' -Content {
                            New-UDButton -Text " Run" -Width 150 -OnClick {
                                New-UDScriptRunModal -Script $Script
                                Sync-UDElement -Id "JobGrid" -Broadcast
                            } -Icon play 
                        }
                    }
                    New-UDPadding -Padding '5px' -Content {
                        New-UDButton -Text "Schedule" -Width 150 -OnClick {
                            New-UDScriptScheduleModal -Script $Script
                        } -Icon calendar
                    }
                    New-UDPadding -Padding '5px' -Content {
                        New-UDButton -Text " Edit" -Width 150 -OnClick {
                            Edit-UDScriptModal -Script $Script
                        } -Icon edit
                    }
                    New-UDPadding -Padding '5px' -Content {
                        New-UDButton -Text " Delete" -Width 150 -OnClick {
                            New-UDDeleteScriptModal -Script $Script
                        } -Icon ban
                    }
                }
            
            }
        }
    }

    New-UDTabContainer -Tabs {
        New-UDTab -id "RunningScriptJobTab" -Text "Running Jobs" -Content {
            New-JobActiveScriptGrid -Script $Script
        }

        New-UDTab -id "PastScriptJobTab" -Text "Past Jobs" -Content {
            New-JobHistoricalScriptGrid -Script $Script
        }

        New-UDTab -Text "Script" -Content {

            $Session:ScriptEditMode = $false

            New-UDCard -id "ScriptEditTabCard" -Title "Edit Script Block" -Endpoint {
                New-UDElement -Id 'ScriptPageEditDiv'-Tag 'div' -Attributes @{
                    style = @{
                        height = "700px"
                   }
               } -Endpoint {
                    
                    $ScriptHistory = Get-UAScriptHistory -Script $Script | Sort-Object -Property 'Timestamp' -Descending | Select-Object -First 1
                    New-UDElement -id "scripteditinformation" -Tag 'div' -Content {
                        New-UDHtml -Markup ("<b>Last Updated By</b>: " + ($ScriptHistory.Author.ToString()))
                        New-UDHtml -Markup ("<b>Last Updated On</b>: " + ($ScriptHistory.Timestamp.ToString()))
                        New-UDHtml -Markup ("<b>Last Updated Message</b>: " + ($ScriptHistory.Message.ToString()))
                        New-UDHtml -Markup ("<br>")
                    }                     
                    
                    
                    
                    if($null -eq $Session:AuthorizationPolicies -or ($Session:UserRole -eq "Administrator" -or $Session:UserRole -eq "Operator"))
                    {
                        if($Session:ScriptEditMode -eq $True)
                        {   
                            
                            
                            New-UDButton -Id "ScriptPageScriptBlockCancelButton" -Text "Cancel" -Icon "ban" -OnClick {
                                $Session:ScriptEditMode = $False
                                Sync-UDElement -Id "ScriptPageEditDiv"
                                Sync-UDElement -Id "ScriptPageScriptBlockEditor"
                            }
                            " "
                            New-UDButton -Id "ScriptPageScriptBlockSaveButton" -Text "Save Changes" -Icon "save" -OnClick {
                                $ScriptContent = ((Get-UDElement -Id 'ScriptPageScriptBlockEditor').Attributes["code"])
                                New-SaveScriptContentModal -Script $Script -ScriptContent $ScriptContent
                            }
                            New-UDCodeEditor -Id "ScriptPageScriptBlockEditor" -Language 'powershell' -Code $Script.Content -Theme 'vs-dark' -AutoSize
                        }
                        else {
                            New-UDButton -Id "ScriptPageScriptBlockEditButton" -Text "Edit" -Icon "edit" -OnClick {
                                $Session:ScriptEditMode = $True
                                Sync-UDElement -Id "ScriptPageEditDiv"
                            }
                            New-UDCodeEditor -Id "ScriptPageScriptBlockEditor" -Language 'powershell' -Code $Script.Content -Theme 'vs-dark' -ReadOnly -AutoSize
                        }
                    }                    
                }
            }
        }
        
        if ($Parameters.Length -ne 0)
        {
            New-UDTab -Text "Parameters" -Content {
                New-UDTable -Id "ScriptPageParametersTable" -Title "Parameters" -Header @("Name", "Type") -Endpoint {
                    $Parameters = Get-UAScriptParameter -ScriptId $ScriptId
                    $Parameters | ForEach-Object {
                        $ScriptParameter = [PSCustomObject]@{
                            Name = $_.Name
                            Type = $_.Type
                        }
                        $ScriptParameter | Out-UDTableData -Property @("Name", "Type")
                    }
                } 
            }
        }
        
        $Schedules = Get-UASchedule -Script $Script
        if ($null -ne $Schedules)
        {
            New-UDTab -Text "Schedule" -Content {
                New-ScheduleGrid -Script $Script
            }
        }

        New-UDTab -Text "Commit History" -Content {
            New-ScriptHistoryGrid -Script $Script
        }

        if ($ScriptTags) {
            New-UDTab -Text "Tags" -Content {
                New-TagGrid -Script $Script
            }
        }

        New-UDTab -Text "Execution Options" -Content {
            New-UDCard -Title "Script Execution Options" -Content {
                
                $RequiredPowerShellVersion = if (!$Script.RequiredPowerShellVersion -or $Script.RequiredPowerShellVersion -eq "") {"None Specified"} else { $Script.RequiredPowerShellVersion }
                
                New-UDElement -Tag 'div' -Content {
                    if($AllowManualInvocation -eq $true){
                        New-UDHtml -Markup ("<b>Manual Invocation: </b> Enabled")
                    }
                    else {
                        New-UDHtml -Markup ("<b>Manual Invocation: </b> Disabled")
                    }
                    New-UDHtml -Markup ("<b>Required PowerShell Version: </b>" + ($RequiredPowerShellVersion.ToString()))
                }
                
            }
            
        }

    }

}